Skip to content

Instantly share code, notes, and snippets.

@sinofp
Created May 27, 2021 13:56
Show Gist options
  • Save sinofp/a59dc27365f7351b2d2d11e7cb138cc1 to your computer and use it in GitHub Desktop.
Save sinofp/a59dc27365f7351b2d2d11e7cb138cc1 to your computer and use it in GitHub Desktop.
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