PDF To Image

February 26, 2007 on 8:34 pm | In Uncategorized |

I wanted to view a PDF on my PSP, but unfortunately the PDF was full of images so the usual viewer bookr didn’t want to load it. Luckily I managed to figure out how to convert the PDF into JPEGs so I could view them. Since I hadn’t found a guide in my searches, here is a rough guide of how I did it.
The Tool of choice for this exercise is ghostscript, in particular the command line component ‘gs’. Ghostscript is a PDF/PS interpreter, available on linux and windows (SF.net Download). The magical command line I used was:

gs -sDEVICE=jpeg -dJPEGQ=95 -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -dDOINTERPOLATE -sOutputFile=m_%d.jpg -dSAFER -dBATCH -dNOPAUSE -r57×58 M.pdf
What does this all do?

  • sDEVICE=jpeg -dJPEGQ=95
    • Defines the image output format, there are alot of image types that can be saved, I chose JPEG as the PSP cannot view PNG images in the built in image viewer.
    • The list of available outputs can be found by running gs with no command line arguments, or by visiting http://www.cs.wisc.edu/~ghost/doc/cvs/Devices.htm
  • -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -dDOINTERPOLATE
    • Antialiasing settings, these make your output look the best. Use them.
  • -sOutputFile=m_%d.png
    • The output file name, %d implies you want to split images by page, the %d will be replaced with the page number.
  • -dSAFER -dBATCH -dNOPAUSE
    • Batch processing options, makes gs output all of the images without stopping and confirming.
  • -r57×58
    • Resolution of output images, I had to play with this a bit to get the exact numbers, depends on your input file too.
  • M.pdf
    • The name of the input file.

Anyway, so you run that and suprise suprise you get alot of images, ripe for viewing :) Enjoy.

9 Comments »

RSS feed for comments on this post.

  1. Wow! That is what i needed! Thak you VERY much!

    Comment by LongMan — November 19, 2007 #

  2. But! -sOutputFile=m_%d.png not too good with -sDEVICE=jpeg

    Comment by LongMan — November 19, 2007 #

  3. Haha true, I’ll fix that. Thanks :)

    Comment by Danzel — November 20, 2007 #

  4. Hi.
    Thanks for this article. You solved my Problem in no time!
    (But it took me quite a time to discover this article)

    Comment by Matze — March 13, 2008 #

  5. Just what I was looking. However the quality is very poor, I can’t read the text that was on my original PDF, any suggestions on what to check to improve the output quality?

    Comment by Luis — April 15, 2008 #

  6. Check out the options for anti-aliasing etc here:
    http://pages.cs.wisc.edu/~ghost/doc/cvs/Use.htm#Rendering_parameters

    -dAlignToPixels might help.

    Comment by Danzel — April 15, 2008 #

  7. Hi,
    It might sound basic but I can’t find gs.exe, I will appreciate any pointer to the executable.
    Thanks.

    Comment by Murat — August 30, 2008 #

  8. Grab Ghostscript for windows:
    http://sourceforge.net/project/showfiles.php?group_id=1897&package_id=108733&release_id=617197
    gs863w32.exe
    It should be in there.

    Comment by Danzel — August 30, 2008 #

  9. for windows its gswin32c instead of gs, and you will also need to add it to systemwnviroment variables.

    Comment by Rizwan — May 24, 2010 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^