TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created various plots using pgfplots package for my thesis. Now I would export them in jpg or png format. Does it exist a way to achieve this porpouse?

share|improve this question
Both formats are bitmaps, and so do not scale. Keeping as PDFs would be much better. – Joseph Wright Jan 12 '13 at 17:38
Look at section 7.1 in the documentation of pgfplots – egreg Jan 12 '13 at 18:02
up vote 8 down vote accepted

First of all, make sure you have installed ImageMagick as the following code uses ImageMagick's convert command.

Once you have had a PDF output, you need to convert it to PNG by using the following batch file named pdf2png.bat. It is convenient to register the batch path to the system variable.

rem pdf2png.bat
echo off
rem %1 PDF filename without extension
rem %2 density
rem %3 alpha, choose one of {on,off,remove}

del "%~1-*.png"

convert -compose copy -bordercolor red -border 3x3 -density %2 -alpha %3 "%~1.pdf" "%~1-%%02d.png" 


  • %1 is the first mandatory argument that specifies the filename (without extension) of your PDF to convert.
  • %2 is the second mandatory argument that specifies the density. The higher density makes the PNG dimension larger.
  • %3 is the third mandatory argument that specifies whether or not you preserve the transparency. Use on if you want to preserve the transparency, otherwise choose remove. I don't use off because it produces a lousy output.
  • I added an additional feature such that the output will be enclosed by a red rectangle. If you don't like this feature, remove -compose copy -bordercolor red -border 3x3 from the code above.


It is just an example. Your scenario in which you get a PDF might be different from mine. My scenario is as follows: compile the following input file with latex->dvips->ps2pdf to get a PDF output.

% myfilename.tex


You can invoke the batch from the editor of your choice, but here I invoke the batch from the DOS prompt:

enter image description here

The output is:

enter image description here

The red rectangle is the border produced by -compose copy -bordercolor red -border 3x3.

share|improve this answer
But in this way I convert all the document or only the image? – Mazzy Jan 12 '13 at 17:33
@Mazzy: Only the image if you put each plot into a separate, compilable TeX input file. Use standalone document class for each plot. – kiss my armpit Jan 12 '13 at 17:35
See tex.stackexchange.com/questions/91188/… for one way to extract all the figure environments. The script there could be modified to produce one file per figure. – Ethan Bolker Jan 12 '13 at 17:48

Acrobat Reader allows for saving a PDF as JPG. Just compile each LaTeX file. Open them in Acrobat and Save As JPG.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.