简体   繁体   中英

ImageMagick/Ghostscript overwrites first page of PDF file

I have a strange behavior starting today after I upgraded to Ghostscript 9.15 and ImageMagick 6.9.0-4. I am trying to convert some multi-page PDF files to multiple JPEG files.

The problem is that the first page of the PDF file (the 0 JPG file) is overwritten by the software with the last page of the PDF file. For example, launching the command:

 convert -verbose -define jpeg0 -thumbnail x400 -flatten \
   -background white /uploads/54b534908aa9b.pdf  \
   /small0115/54b534908aa9b_%d.jpg

Would get me all pages, except the first one, which is the replaced by the last one.

An output for the -verbose option prints as follows for this 52 paged PDF file:

/uploads/54b534908aa9b.pdf[0] PDF 694x1224 694x1224+0+0 16-bit sRGB 944KB 0.000u 0:00.000
.......
/uploads/54b534908aa9b.pdf[50] PDF 694x1224 694x1224+0+0 16-bit sRGB 944KB 0.000u 0:00.000
/uploads/54b534908aa9b.pdf[51] PDF 694x1224 694x1224+0+0 16-bit sRGB 944KB 0.000u 0:00.000
/uploads/54b534908aa9b.pdf=>/small0115/54b534908aa9b_0.jpg PDF

As far as I can see, the software automatically writes the first page again, but uses the last page to do so, instead of leaving it as it is.

A workaround to this problem is to generate the first page of the file again, but then this is just a workaround, and not a viable solution for a programmer :)

Try this command:

convert                        \
  -verbose                     \
   /uploads/54b534908aa9b.pdf  \
  -thumbnail x400              \
   /small0115/54b534908aa9b.jpg

The resulting files will automatically get numbered as 54b534908aa9b-0.jpg , 54b534908aa9b-1.jpg , 54b534908aa9b-2.jpg ... 54b534908aa9b-51.jpg .


Remarks:

  1. I do not understand what your -define jpeg0 parameter is supposed to achieve. Is this a typo?

  2. Also, -flatten does not have any effect (Ghostscript -- used by ImageMagick to process the PDF into a raster file, which IM can then handle -- cannot handle PDF layers anyway.)

  3. Also -background white will not have any effect: if the PDF pages have a colored 'background', the resulting JPEG will have the same color background. If the PDF pages have a transparent background (most common for PDFs), then the JPEG file format cannot handle it, and the background will appear white...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM