Without using standalone
, I used to transform my .pdf
output in a .png
file by an online converter (I don't give the link because I don't know if it is reliable, however, you can easily find it googling around) but since I installed arara
package I've done this conversion more quickly.
I have Windows 10 but I think this works with every operating system, you only need to have ImageMagick (it's free) and arara
package installed.
Modifying the animate
rule provided by cmhughes, which creates a .gif
file, I have created a convert.yaml
rule and put in ...\MiKTeX 2.9\scripts\arara\rules
(the path varies according to which operating system and TeX distribution you are using, I have MiKTeX):
!config
# Convert .pdf to any format file allowed by ImageMagick convert command (the default is png)
# author: CarLaTeX
# last edited by: CarLaTeX, Dicember 26th 2016
# requires arara 3.0+
#
# Sample usage:
# - these both create a .png file
# % arara: convert
# % arara: convert: {format: png}
#
# - this creates a .gif file with red background
# % arara: convert: {format: gif, background: red}
#
# - this creates a .png file with a trimmed image
# (use the parameter "otheroptions" to add any option not already explicitly considered by the rule,
# that is any option different from -background, -alpha, -density and -quality}
# % arara: convert: {otheroptions: -trim +repage}
#
#
# This rule is really just a shortcut for commands like the following:
#
# convert -density 300 myfile.pdf myfile.png
#
# which will output myfile.png
#
identifier: convert
name: convert
commands:
- <arara> @{ isWindows( "cmd /c convert", "convert" ) } -background @{background} -alpha @{alpha} -density @{density} @{otheroptions} "@{ getBasename(file) }.pdf" -quality @{quality} "@{ getBasename(file) }.@{format}"
arguments:
- identifier: density
flag: <arara> @{parameters.density}
default: 150
- identifier: otheroptions
flag: <arara> @{parameters.otheroptions}
- identifier: quality
flag: <arara> @{parameters.quality}
default: 100
- identifier: background
flag: <arara> @{parameters.background}
default: white
- identifier: alpha
flag: <arara> @{parameters.alpha}
default: remove
- identifier: format
flag: <arara> @{parameters.format}
default: png
(Take into account that I'm not an expert, maybe this could be done better).
Of course, you have to do this once for all, then it is sufficient to put:
% arara: pdflatex (or any other command you are using to compile)
% arara: ... (possible other commands)
% arara: convert
at the beginning of your document and compile it with arara
.
For example, if you have this myfile.tex
:
% arara: pdflatex
% arara: convert
\documentclass{article}
\begin{document}
Quack!
\end{document}
and you run arara myfile.tex
, you will get a myfile.pdf
and a myfile.png
.
For an analogous solution using Ghostscript, see this answer of mine.