-
-
Save sinofp/a59dc27365f7351b2d2d11e7cb138cc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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