PNGs to PDF produces some blank pages

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
teranine
Posts: 3
Joined: 2011-09-25T17:40:36-07:00
Authentication code: 8675308

PNGs to PDF produces some blank pages

Post by teranine »

I'm using this command line to process approximately 500 scanned PNG files (300 DPI) into smaller/cleaner versions:

Code: Select all

convert infile.png -shave 1%x1% -resize 50% -quality 75 -filter Cubic +repage -deskew 40% +repage -unsharp 5.0+0.50+0.0 -white-threshold 88% -fuzz 10% -trim outfile.png
It works very well in producing small/clean/readable PNG files for reading on both a 22" monitor and ipad (using GoodReader to view PNG files).

However, converting all the files into a PDF produces some blank pages within the PDF when using the default PDF reader (Document Viewer 2.32.0) in Ubuntu 10.10.

When I use Adobe Reader 9 (linux), all the pages are viewable and there are no issues. But, I primarily need to view the PDF on my ipad using the GoodReader app, which shows some blank pages like the Document Viewer app in Ubuntu. Only Adobe Reader 9 displays the PDF correctly with no blank pages.

This is how I use convert to create the PDF:

Code: Select all

convert *.png -density 288 out.pdf
Here are some instances where the PDF is displayed correctly for all viewers (Document Viewer, Adobe Reader 9, GoodReader):

(1) If I don't process the scanned PNGs and instead just directly convert the raw PNG files into a PDF (no shaving, resizing, threshold, trim, etc).

(2) If I process the PNGs to produce smaller/cleaner PNGs, convert them all to PPM format, and then produce a PDF (results in larger PDF than if I were to use PNG format images)

(3) If I use gscan2pdf to import the process PNGs and save them as a PDF (my goal is have the processing and PDF generation entirely command line)

So my guess is that something is happening to the processed PNGs that produces blank pages in the final PDF. If I use the unprocessed PNGs to create the final PDF, there are no issues (but the PDF size is in the GB range).

Please help, thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNGs to PDF produces some blank pages

Post by fmw42 »

what version of IM are you using as the PNG code has been under development and improvement for quite some number of releases, so old versions may have had bugs or inability to deal with certain png types. If your version is not current, then you should try upgrading and see if that helps. Also as IM uses Ghostscript for PDFs, you might upgrade GS also.

Also try reordering your arguments as (since your input image may have a virtual canvas and -trim may need it at the end, also set your filter before using -resize)

convert infile.png +repage -shave 1%x1% -filter Cubic -resize 50% -deskew 40% -unsharp 5.0+0.50+0.0 -white-threshold 88% -fuzz 10% -trim +repage -quality 75 outfile.png

Note -quality has different meaning for its values in PNG than it does for JPG. Your value is the default for PNG. See http://www.imagemagick.org/script/comma ... hp#quality
teranine
Posts: 3
Joined: 2011-09-25T17:40:36-07:00
Authentication code: 8675308

Re: PNGs to PDF produces some blank pages

Post by teranine »

My version:

Version: ImageMagick 6.6.2-6 2010-12-02 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP

I also downloaded the current stable source and compiled the convert utliity. Produces same results.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNGs to PDF produces some blank pages

Post by fmw42 »

Try disabling OpenMP. I have heard of some problems with its use on certain platforms? I cannot say whether it will help or not. Also try upgrading your Ghostscript.

Are any of the PNGs black or just the PDF pages? If the latter, also try upgrading your Ghostscript.
teranine
Posts: 3
Joined: 2011-09-25T17:40:36-07:00
Authentication code: 8675308

Re: PNGs to PDF produces some blank pages

Post by teranine »

Reordering my arguments and filters before the resize worked!

convert infile.png +repage -shave 1%x1% -filter Cubic -resize 50% -deskew 40% -unsharp 5.0+0.50+0.0 -white-threshold 88% -fuzz 10% -trim +repage -quality 75 outfile.png

Thanks so much!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNGs to PDF produces some blank pages

Post by fmw42 »

glad it was that simple a solution
Post Reply