Skip to content

Instantly share code, notes, and snippets.

@sinofp
Created May 27, 2021
Embed
What would you like to do?
from PIL import Image
im = Image.open("QQMail_0.png")
width, height = im.size
ROW = int(width / 210 * 297) # A4
pages = []
box = (0, 0, width, ROW)
for i in range(0, height, ROW):
region = im.crop(box)
pages.append(region)
box = (0, box[3], width, box[3] + ROW if box[3] + ROW < height else height)
pages[0].save("QQ.pdf", "PDF", resolution=100, save_all=True, append_images=pages[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment