Skip to content

Instantly share code, notes, and snippets.

@poxip
Created September 5, 2019 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poxip/985136ce174e7d9d6231cec2bb992131 to your computer and use it in GitHub Desktop.
Save poxip/985136ce174e7d9d6231cec2bb992131 to your computer and use it in GitHub Desktop.
A simple way to convert any image to PDF with Pillow
import sys
from PIL import Image
image = Image.open(sys.argv[1])
background = Image.new("RGBA", image.size, (255, 255, 255))
composite = Image.alpha_composite(background, image).convert("RGB")
composite.save(sys.argv[2], "PDF")
@poxip
Copy link
Author

poxip commented Sep 5, 2019

python img2pdf.py pngfile.png pngfile.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment