Search code examples
pdfimagemagickjpeg

ImageMagick PDF to JPGs sometimes results in black background


I have the following:

ghostscript-fonts-5.50-24
ImageMagick-6.7.2-1
ghostscript-9.02-1

Which I use to create a series of JPGs for each page using:

convert -density 175 -colorspace sRGB test.pdf -resize 50% -quality 95 test.jpg

When I run this on my windows machine all appears to work ok, but on our linux server we get the black background problem.

The resulting JPGs have a black background rendering the image un-readable, what am I missing or is there something I should be doing to correct this?

I've been all over google for days but each suggestion doesnt seem to work for me.

Any help is much appreciated, thanks in advance :)

EDIT

Just noticed this output when converting one of the PDFs that produces the black background:

**** Warning: Fonts with Subtype = /TrueType should be embedded.
             The following fonts were not embedded:
                    Arial
                    Arial,Bold
                    Arial,BoldItalic
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Microsoft« Word 2010 <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.

This seems related but as we don't have control over how the PDFs are produced we need some way of fixing this server side.

Thanks again


Solution

  • Simple fix to this issue is to use an image format that supports transparency, such as png.

    So:

    convert -density 175 -colorspace sRGB test.pdf -resize 50% -quality 95 test.png
    

    Problem solved :)