Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a multiple-page PDF to a single image

I'm attempting to convert a PDF into a single image using GhostScript.

Only the first page is converted, while my intention is to generate a horrendously tall PNG/JPG image with all the pages concatenated together.

These are the parameters I'm currently passing to the GhostScript DLL (via a .NET application):

pdf2img \
  -dNOPAUSE \
  -dBATCH \
  -dSAFER \
  -sDEVICE=png256 \
  -dGraphicsAlphaBits=4 \
  -dTextAlphaBits=4 \
  -dDOINTERPOLATE \
  -dAlignToPixels=1 \
  -r300x300 \
  -sOutputFile=GLOSS.png \
   GLOSS.pdf

Is it possible to concatenate all the pages together via GhostScript? Or should I resort to an external method?

like image 491
TheFuzzy Avatar asked Mar 25 '09 10:03

TheFuzzy


2 Answers

After converting multi-page PDF to images (PNG, JPEG, TIFF, etc.) using GS, you'll need to take one step further to merge the output images into a multi-page TIFF image.

Take a look at the source code of VietOCR.NET, which has the functionality but does it in two separate steps. You can modify it to call the two functions back to back.

like image 81
nguyenq Avatar answered Oct 02 '22 02:10

nguyenq


Did you have a look at ImageMagick? This free library might have an option to create a single image from a PDF (It actually uses Ghostscript but adds a lot of graphical editing capabilities such as merging images).

like image 40
Dirk Vollmar Avatar answered Oct 02 '22 02:10

Dirk Vollmar