Today, I just wanted to convert a PDF into a PNG image. I knew I already did it but I forgot to remember how (I only need it once every six months). I hope you don't mind if I use my own blog to avoid looking again for it. First, it requires ImageMagick. The following script will do the trick:
from PythonMagick import Image os.environ["MAGICK_HOME"] = r"path_to_ImageMagick" file = "my.pdf" to = file.replace(".pdf",".png") p = PythonMagick.Image() p.density('300') p.read(os.path.abspath(file)) p.write(os.path.abspath(to)) # the ImageMacgick command line to do it # cmd = "convert -density 300 -depth 8 -quality 85 {0} {1}".format(file, to)
I recently faced an issue while converting an equation into an image using the method I developped in this post. I do not know why but the following expression \frac{X_t}{Y_t} did not work. So I had to use miktex and more specifically htlatex through the following command line:
htlatex eq.tex html "" "" "--interaction=nonstopmode"
The last parameter avoids the programm to check the input stream if an error was detected. I wrapped this into a quick and dirty python program you can find below. It will also describe what eq.tex should contain.