Last active
June 16, 2020 06:12
-
-
Save YuigaWada/5adc1670f3ac40898b132003321cceec to your computer and use it in GitHub Desktop.
[Python] 編集権限がないためiPad等でメモを書き込めないPDFを撲滅するコード
This file contains hidden or 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 pdf2image import convert_from_path | |
| from PIL import Image | |
| import sys | |
| args = sys.argv | |
| if not len(args) > 1: | |
| print("Error: without pdf file") | |
| exit() | |
| pdf_filepath = args[1] | |
| imgs = convert_from_path(pdf_filepath) | |
| if len(imgs) == 0: | |
| print("No Images") | |
| exit() | |
| output_path = "/".join(pdf_filepath.split("/")[:-1]) + "/output.pdf" | |
| print("files:",len(imgs)) | |
| print("output >",output_path) | |
| imgs[0].save(output_path, "PDF" ,resolution=100.0, save_all=True, append_images=imgs[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment