How to convert a PDF document to PNG?

123,788

Solution 1

This is overkill for what you need, but in the absence of another answer, GIMP can do this for you. Just install it, open the PDF, and save-as a PNG.

Solution 2

If you have imagemagick installed, you can just type:

convert myfile.pdf myfile.png

Though personally I prefer the results obtained from pdftoppm from Poppler utilities:

pdftoppm -png myfile.pdf > myfile.png

Solution 3

Windows: Install PDFCreator and open your PDF. Print it to the PDFCreator printer (or whatever you called it) and hit save. When you hit save, after choosing a filename, set the filetype to PNG.

Linux: Install ImageMagick (on Ubuntu: sudo apt-get install imagemagick) and then in a terminal type: convert [Input PDF File.pdf] [Output PNG File.png].

Mac OS X: Open the PDF in Preview and in the Save As dialog, set the filetype to png.

Solution 4

You could also use GS:

"c:\Program Files\gs\gs9.10\bin\gswin64.exe" -dBATCH -dNOPAUSE -sDEVICE=pnggray -r300 -dUseCropBox -sOutputFile="path_to_png_files\pdffilename-%03d.png" "path_to_pdf_file\pdffilename.pdf"

The path to GS should be adjusted based on your installation.

The DEVICE parameter here will specify grayscale. You can also output with color instead. These settings will allow you to output to 24-bit color, 300 dpi PNG files using the RGB.icc color profile:

-sDEVICE=png16m -sOutputICCProfile=default_rgb.icc -r300

Compared to convert, GS seems to run much faster, and it is more suitable for big batches of conversion.

Solution 5

Another way is

inkscape -d 300 -e "$filename.png" "$filename.pdf"

(you can omit -d 300 if you only need 96 dpi).

However, inkscape may have problems with the fonts, which is why I prefer convert from ImageMagick (see frabjous' and digitxp's answers).

Share:
123,788
Raymond
Author by

Raymond

Updated on September 17, 2022

Comments

  • Raymond
    Raymond over 1 year

    Is there a free way to convert a PDF document to a PNG image?

  • Raymond
    Raymond over 13 years
    No more overkill than the 5 or so 'free' programs I installed that left a watermark on the image. Worked beautifully, thanks!
  • Andreas
    Andreas about 12 years
    on mac with homebrew I had to install imagemagick and ghostscript for this to work. brew install imagemagick brew install ghostscript
  • Sparhawk
    Sparhawk about 11 years
    Why do you prefer the results of pdftoppm? I notice that the default output resolution is higher than imagemagick (although this can be changed), but apart from that they seem comparable on my test file.
  • chrishiestand
    chrishiestand about 11 years
    Gimp works great for a single page, but I don't see a simple way to export lots of pages automatically. I'm sure if you know gimp well you could use automation tools to get it working. But perhaps pdftoppm is better.
  • Brad
    Brad about 11 years
    @chrishiestand, You should post that as an alternative answer.
  • maxpenguin
    maxpenguin about 11 years
    Poppler does a much better job for me - I've got an input pdf with CYMK colours, with imagemagick the colours come out a crazy bright cyan. Also convert takes ~8 seconds and pdftoppm takes less than 0.5 seconds. Thanks for the pointer!
  • galacticninja
    galacticninja about 11 years
  • HikeMike
    HikeMike almost 11 years
    Paint can open PDFs?
  • Canadian Luke
    Canadian Luke almost 11 years
    @DanielBeck He's saying to open in a PDF viewer, then copy and paste
  • Roman Protsiuk
    Roman Protsiuk almost 11 years
    converting multipage PDF with poppler will look more like this: pdftoppm -png myfile.pdf myfile
  • sandover
    sandover over 10 years
    Informally comparing them head to head, I found pdftoppm about 5x (for PNG) to 16x (for JPG) faster once I adjusted for the same resolution. My test file was a scientific paper 10 pages long.
  • kromuchi
    kromuchi over 10 years
    See blog.alivate.com.au/poppler-windows for windows binaries of poppler and use pdftocairo -png
  • joeA
    joeA over 9 years
    Signed up for super user just to upvote this. Now if I only had any hope of remembering it...
  • Alain Pannetier
    Alain Pannetier over 8 years
    +1 for inkscape. Because you can edit the pages, rework the diagrams and save as svg or even as pdf etc...
  • Rachael
    Rachael over 8 years
    Route is "import" -> export as
  • Ajedi32
    Ajedi32 over 8 years
    Note that if you use imagemagick, you may also need ghostscript: stackoverflow.com/q/32466112/1157054
  • DetlevCM
    DetlevCM about 8 years
    While this is an old post, I think it may be worth pointing out that GIMP is not an ideal solution - at least I remember it not readin a pdf file generated by R correctly. Using pfftoppm with R generated pdf plots produces the correct image. (And Adobe Acrobat 9 Pro works too if you have it - can't speak about other versions.)
  • Noumenon
    Noumenon over 7 years
    Just don't make the mistake of trying to actually edit the PNG with GIMP if you know how to use any other image editor. Convert and export.
  • Mr Purple
    Mr Purple about 7 years
    For multi page pdfs you can File>Open_as_layers then File>Export_Layers using the export layers as png plugin
  • prakash
    prakash over 6 years
    An update may be in order. With the 2.8.16 version of GIMP, I found that "Export as" is used instead of "Save as".
  • goetzc
    goetzc about 5 years
    On macOS you can also use the build-in sips tool: sips -s format png the_pdf_file.pdf --out the_png_file.png
  • Admin
    Admin about 2 years
    attempt to perform an operation not allowed by the security policy PDF' `
  • Admin
    Admin about 2 years
    @Vimos Might be a bug in your version of ghostscript or imagemagick, but see here.