1
votes

Given the short, 5 page PDF file (attached at the bottom), and the following python code to convert to a multi-page TIFF:

from wand.image import Image


with Image(filename='5-page-pdf.pdf', resolution=200) as img:
    img.type = "grayscale"
    img.format = "tiff"
    img.compression = "lzw"
    img.save(filename="test.tiff")

results in a TIFF file that has pages 2-4 as what appears to be black text on a dark-grey (or maybe transparent) background. Other image processing libraries cannot open the file or render it.

Converting the same PDF with ImageMagick, which Wand uses, works just fine

convert -density 200 5-page-pdf.pdf -type grayscale -compress lzw 5-page-pdf.tiff

this produces a file that does work with other imaging libraries and looks correct in a TIFF viewer.

I've tried removing the alpha channel, I've tried setting the background color to 'White', and a few other things, to no avail. The TIFF that comes out of Wand is always garbled. If it's doable in ImageMagick it should be doable in Wand, right? What parameter or setting am I missing?

Original PDF

Wand Produced TIFF

1

1 Answers

1
votes

Looks like setting the img.alpha_channel property is not propagating across the pages.

Try this workaround

from wand.api import library
from wand.image import Image

with Image(filename="5-page-pdf.pdf", resolution=200) as img:
    img.type = 'grayscale'
    img.compression = "lzw"
    # Manually iterate over all page, and turn off alpha channel.
    library.MagickResetIterator(img.wand)
    for idx in range(library.MagickGetNumberImages(img.wand)):
        library.MagickSetIteratorIndex(img.wand, idx)
        img.alpha_channel = 'off'
    img.save(filename="test.tiff")