Skip to content

Instantly share code, notes, and snippets.

@poxip
Created September 5, 2019 09:14
Show Gist options
  • Select an option

  • Save poxip/985136ce174e7d9d6231cec2bb992131 to your computer and use it in GitHub Desktop.

Select an option

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

poxip commented Sep 5, 2019

Copy link
Copy Markdown
Author

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