[Tex/LaTex] How to convert pdf file to image in latex file

pdftextikz-pgf

I use imagemagick to convert pdf file to image when creating tikz code in latex file. The code is as follows:

\documentclass[preview,border=2pt,2pt]{standalone}
\documentclass[convert={density=300,outext=.png}]{standalone}
...

But 2nd line to invoke imagemagick convert does not work. I need help on this. Thanks.

Best Answer

The example in the question has two documentclass commands, which is not allowed in LaTeX. You can use a single command with the convert option added to the options of the first line.

Note that the second 2pt option does not do anything, it generates a warning and it can be removed. Note also that you need to run LaTeX with the shell-escape option to allow calling convert. I don't use TeXstudio myself but according to How to invoke latex with the -shell-escape flag in TeXMakerX? you can do it in various ways, one of which is to add a compile directive at the start of the file as in the example below.

MWE:

% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
\documentclass[preview,border=2pt,convert={density=300,outext=.png}]{standalone}
\begin{document}
\Huge converted pdf
\end{document}

Result (note that the squares indicate transparency, they are shown because they are invisible):

enter image description here

Apart from the .png the .pdf is also generated automatically.

Related Question