Page 1 of 1

Resizing a converted PDF doesn't work

Posted: 2017-07-12T16:34:41-07:00
by johnrellis
Resizing of PDFs created by Powerpoint 2016 works, while resizing PDFs created by Word 2016 doesn't. Is this a bug or am I missing something?

Details: The following work:

Code: Select all

magick Word.pdf Word.jpg
magick Powerpoint.pdf Powerpoint.jpg
magick Powerpoint.pdf -resize 512x512 Powerpoint.512.jpg
But this generates an all-black image:

Code: Select all

magick Word.pdf -resize 512x512 Word.512.jpg
The input and output files are here: https://www.dropbox.com/sh/l0ata6szokkh ... bjea?dl=0

Version: ImageMagick 7.0.6-0 Q16 x64 2017-06-11
Windows 10

Re: Resizing a converted PDF doesn't work

Posted: 2017-07-12T16:41:21-07:00
by snibgo
If you examine word.pdf in Adobe Reader, you will see it has opaque black letters on a transparent background. JPEG can't record transparency, so you get black letters on a black background.

The cure is to flatter over whatever colour you want for the background, eg:

Code: Select all

magick word.pdf -background Yellow -layers Flatten w.png

Re: Resizing a converted PDF doesn't work

Posted: 2017-07-12T20:32:37-07:00
by johnrellis
Thanks much for your reply.

Why doesn't the background get turned black when there is no resizing?

Code: Select all

magick Word.pdf Word.jpg
Word.jpg has a white background.

Re: Resizing a converted PDF doesn't work

Posted: 2017-07-13T04:01:32-07:00
by snibgo
The converted word.pdf has fully-transparent white pixels.

Transparent pixels have colours. A pixel may be fully-transparent white, fully-transparent-yellow, or whatever. Saving as JPEG ignores transparency, so each pixel becomes opaque, whatever colour it is "beneath" the transparency.

Many IM operations such as "-resize" treat transparency carefully so the colour "beneath" the transparency doesn't get mixed with the opaque or semi-transparent pixels. But one side effect is that all fully-transparent pixels of any colour become fully-transparent black.

Re: Resizing a converted PDF doesn't work

Posted: 2017-07-13T16:03:48-07:00
by johnrellis
Thanks for the hint. I found this explanation of why -resize doesn't preserve the color of transparent pixels: viewtopic.php?f=22&t=22287 . I couldn't find anything in the documentation about this, though.

Re: Resizing a converted PDF doesn't work

Posted: 2017-07-13T16:59:07-07:00
by snibgo
Yes. See also the SVG Compositing Specification.

When two or more pixels are combined, because of composite or resize or whatever, the resulting pixel colour values usually come from the colour values of each pixel multiplied by its alpha. (The resulting alpha comes from the alphas only, not the colours, of the individual pixels.)

When an input alpha is zero, multiplying this by any colour gives zero. Hence output pixels have colour values of zero, black.

Mathematically, it makes sense.

Re: Resizing a converted PDF doesn't work

Posted: 2017-07-13T17:05:07-07:00
by johnrellis
Thanks again.