Page 1 of 1

IM generating black screen when converting few PDFs to JPEG

Posted: 2013-11-19T11:34:32-07:00
by papagi11
We have upgraded ImageMagick software to the latest version and now we are having problem while converting few PDFs to JPEGs, the new version of IM is generating weird JPGs. For the same PDF, we are getting good JPEG in old version of ImageMagick (6.5.4-7).

Have a look at the below picture which shows the comparison to see the JPEG generated from new IM (black picture) and old IM (white color with text)

Image

Looks like ImageMagick is using Ghostscript to do conversions for PDFs. Current version of Ghostscript on my machine is:
$ ghostscript -version
GPL Ghostscript 8.70 (2009-07-31)
&
ImageMagick Version: ImageMagick 6.8.7-5 Q16 x86_64

OS details
$ uname -a
Linux 2.6.32-279.9.1.el6.x86_64

PDF file has been placed at - https://www.dropbox.com/s/495nk62vwx0bf ... 13_PDF.pdf

The command that we are trying to convert the PDF to JPEG is
convert -resize 800X600 /IM/input/11152013_PDF.pdf[0] -profile "/ICCProfiles/Recommended/sRGB Color Space Profile.icm" /IM/output/11152013_PDF.jpg

Had tried the command without applying the profile and still we are getting the JPEG as a black screen.

Is it the upgrade of ImageMagick causing the issue or else the newer version of IM is not compatibile with Ghostscript that we have?

Re: IM generating black screen when converting few PDFs to J

Posted: 2013-11-19T11:50:46-07:00
by snibgo
With recent IM v6.8.7-0 and GS v9.07 on Windows 7, with no profile, I get black text on white background.

I suggest you upgrade Ghostscript.

Re: IM generating black screen when converting few PDFs to J

Posted: 2013-11-19T11:51:24-07:00
by fmw42
try upgrading your ghostscript.

Your file does not conform to Adobe PDF standards. When I run


identify -verbose 11152013_PDF.pdf

I get lots of errors.

Code: Select all

  **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)
   **** Warning: File has unbalanced q/Q operators (too many q's)

   **** This file had errors that were repaired or ignored.
   **** The file was produced by: 
   **** >>>> TargetStream StreamA2P <<<<
   **** Please notify the author of the software that produced this
   **** file that it does not conform to Adobe's published PDF
   **** specification.

Nevertheless, a convertsion as follows on my IM 6.8.7.6 Q16 Mac OSX works fine.


convert 11152013_PDF.pdf[0] 11152013_PDF-0.jpg

**** Warning: File has unbalanced q/Q operators (too many q's)

**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> TargetStream StreamA2P <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.

The background is white.

In older versions of GS, you could process either multipage pdfs without alpha channel or one page pdfs with alpha. You needed to change the delegates.xml file to pngalpha to allow for the alpha. In your file, the alpha channel is the negative of the grayscale channel. I suspect your old Ghostscript is having trouble with the alpha.

In the delegates.xml file I have


<delegate decode="ps:alpha" stealth="True" command=""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s""/>

Re: IM generating black screen when converting few PDFs to J

Posted: 2013-11-19T12:22:29-07:00
by papagi11
snibgo wrote:With recent IM v6.8.7-0 and GS v9.07 on Windows 7, with no profile, I get black text on white background.

I suggest you upgrade Ghostscript.
Tried with latest IM and GS and suggested above

Machine Details
Windows Server 2008 R2
64 bit Operating System

We have the latest version of IM and GS on this windows machine
GhostScript - 9.10
ImageMagick - 6.8.7-6

Tried the command

C:\Users\IM\Desktop>convert -resize 800X600 11152013_PDF.pdf[0] 11152013_PDF.jpg

The output JPEG generated is still the black screen.

Re: IM generating black screen when converting few PDFs to J

Posted: 2013-11-19T13:08:33-07:00
by snibgo
I notice your PDF is mostly transparent. When I convert to PNG, the background is transparent. JPG can't do transparency and IM normally converts this to black, for jpg. For me, the jpg has a white background. I don't know why. For you, it is black, as I would expect. Perhaps this is a difference in delegates.xml.

Code: Select all

D:\web\im>%IM%convert -verbose -background pink 11152013_PDF.pdf[0] j.png
[ghostscript library] Files/gs/gs9.07/bin/gswin64c.exe" -q -dQUIET -dSAFER -dBAT
CH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-
sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -dFirstPage=
1 -dLastPage=1 "-sOutputFile=C:/Users/Alan/AppData/Local/Temp/magick-6296pnaR9Qk
8m0zs%d" "-fC:/Users/Alan/AppData/Local/Temp/magick-6296h6vi81Wg_oiv" "-fC:/User
s/Alan/AppData/Local/Temp/magick-6296_ZF-bB-jpF6i"   **** Warning: File has unba
lanced q/Q operators (too many q's)

   **** This file had errors that were repaired or ignored.
   **** The file was produced by:
   **** >>>> TargetStream StreamA2P <<<<
   **** Please notify the author of the software that produced this
   **** file that it does not conform to Adobe's published PDF
   **** specification.
You might find that "-background white" does the trick.

Re: IM generating black screen when converting few PDFs to J

Posted: 2013-11-19T15:07:29-07:00
by fmw42
try turning off the alpha channel (which is the -negate of the image channel). I think your alpha channel is redundant

convert 11152013_PDF.pdf[0] -alpha off 11152013_PDF-0.jpg

That works for me on IM 6.8.7.6 Q16

Re: IM generating black screen when converting few PDFs to J

Posted: 2013-11-19T16:38:19-07:00
by papagi11
fmw42 wrote:try turning off the alpha channel (which is the -negate of the image channel). I think your alpha channel is redundant

convert 11152013_PDF.pdf[0] -alpha off 11152013_PDF-0.jpg

That works for me on IM 6.8.7.6 Q16
I tried with "-alpha off" option, it is a little bit better but the text is not readable and not as good as the one we got from previous version of IM.

Looks like the problem is with "-resize 800X600" option, we are getting black background if we used this option, otherwise the background is white.

Whatever the option that I use 'resize with alpha off', 'without resize and without alpha off' the text is not as good as the one from previous version of IM.

Re: IM generating black screen when converting few PDFs to J

Posted: 2013-11-19T17:06:58-07:00
by fmw42
Note it is 800x600 NOT 800X600 (the x is not a cap X) and the resize should come after reading the input image


if that fails try

convert image.pdf[0] -channel rgba -resize 800x600 image-0.jpg

or

convert image.pdf[0] -background white -flatten -resize 800x600 image-0.jpg

Note that also in old versions of IM the alpha channel was reverse, so try

convert image.pdf[0] \( +clone -channel a -negate +channel \) -alpha off -compose copy_opacity -composite -resize 800x600 image-0.jpg