Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black-and-white PDF export regression in Pillow 8.3.x #6149

Closed
za3k opened this issue Mar 21, 2022 · 4 comments · Fixed by #6151
Closed

Black-and-white PDF export regression in Pillow 8.3.x #6149

za3k opened this issue Mar 21, 2022 · 4 comments · Fixed by #6151

Comments

@za3k
Copy link

za3k commented Mar 21, 2022

Black-and-white image export to PDF seems to blanket fail starting in PIL/Pillow 8.3.x. The version was reported to me by a user--I have not verified the switchover point.

Below is code which causes PDF generation to succeed (print a rectangle) in greyscale, but fails for black-and-white.

#!/usr/bin/env python3
import PIL, PIL.Image, PIL.ImageDraw

# Works in 8.2.0, fails in 8.3.0
IMAGE_MODE="1"
WHITE=1
BLACK=0

# Works in 8.2.0 and 8.3.0
#IMAGE_MODE="L"
#WHITE=255
#BLACK=0

page = PIL.Image.new(mode=IMAGE_MODE, size=(200, 200), color=WHITE)
page_draw = PIL.ImageDraw.Draw(page)
page_draw.rectangle(((0,0), (99, 99)), outline=BLACK, fill=WHITE, width=1) # Rectangle for debugging print cutoff, and to look nice.

with open("test.pdf", "wb") as f:
    page.save(f, format="pdf")

Reproduced using two different Linux versions in Python 3.x, and multiple Pillow versions.
This bug report was verified with Python 3.10.2 and Pillow 9.0.1

Originally reported as: za3k/qr-backup#24

@za3k
Copy link
Author

za3k commented Mar 21, 2022

fail.pdf
success.pdf

Both files display fine on Chrome web preview, but on almost every other PDF viewer tried, one looks like random garbage.

@radarhere
Copy link
Member

radarhere commented Mar 22, 2022

While macOS Preview also displays the PDF correctly, I can see that Firefox does not.

Testing, I found this is due to #5430

@za3k
Copy link
Author

za3k commented Mar 22, 2022

From the original reporter: Moon Reader on Android; Firefox, Libreoffice Draw, and Evince on Linux

From me: xpdf on Linux

Aside: Looks like a great feature! I love tiny PDFs

@radarhere
Copy link
Member

I've created PR #6151 to resolve this.

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 a pull request may close this issue.

2 participants