Skip to content

Instantly share code, notes, and snippets.

@YuigaWada
Last active June 16, 2020 06:12
Show Gist options
  • Select an option

  • Save YuigaWada/5adc1670f3ac40898b132003321cceec to your computer and use it in GitHub Desktop.

Select an option

Save YuigaWada/5adc1670f3ac40898b132003321cceec to your computer and use it in GitHub Desktop.
[Python] 編集権限がないためiPad等でメモを書き込めないPDFを撲滅するコード
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