Skip to content

Conversation

@radarhere
Copy link
Member

@radarhere radarhere commented Aug 1, 2022

Resolves #6453

The issue requests the CCITTTaxDecode filter be using to save 1 mode PDFs, to reduce file size.

}
)
]
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://opensource.adobe.com/dc-acrobat-sdk-docs/standards/pdfstandards/pdf/PDF32000_2008.pdf#page=38 indicates that K should be <0 for Group 4 encoding

On the next page of that document, it describes BlackIs1, that allows the colors to be inverted.

ImageFile._save(im, op, [("hex", (0, 0) + im.size, 0, im.mode)])
elif filter == "CCITTFaxDecode":
original_strip_size = TiffImagePlugin.STRIP_SIZE
TiffImagePlugin.STRIP_SIZE = math.ceil(im.width / 8) * im.height
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In writing this PR, I found that it was necessary to save the image as a single strip. This has actually been pointed out before, in #5740

# aim for given strip size (64 KB by default) when using libtiff writer
if libtiff:
rows_per_strip = 1 if stride == 0 else min(STRIP_SIZE // stride, im.size[1])
im_strip_size = encoderinfo.get("strip_size", STRIP_SIZE)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than updating STRIP_SIZE and needing to reset it afterwards, I've added "strip_size" as a TIFF encoder argument.

@hugovk hugovk merged commit ae14255 into python-pillow:main Aug 7, 2022
@radarhere radarhere deleted the pdf_ccittfaxdecode branch August 7, 2022 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When I convert TIFF to PDF, the PDF size is 10 times that of TIFF

2 participants