Skip to content

Instantly share code, notes, and snippets.

@Shusei-E
Created June 19, 2016 22:27
Show Gist options
  • Save Shusei-E/a2d3a4dcf0eb38ebfaf1896a55e5c982 to your computer and use it in GitHub Desktop.
Save Shusei-E/a2d3a4dcf0eb38ebfaf1896a55e5c982 to your computer and use it in GitHub Desktop.
main pdfファイルのページに対して交互に空白ページを挿入
import argparse
from PyPDF2 import PdfFileWriter, PdfFileReader
import os
def main(main_path, blank_path):
output = PdfFileWriter()
main_file = PdfFileReader(open(main_path, "rb"))
blank_file = PdfFileReader(open(blank_path, "rb"))
num_pages = main_file.getNumPages()
for new_page in range(num_pages):
output.addPage(main_file.getPage(new_page))
output.addPage(blank_file.getPage(0))
main_folder = os.path.dirname(main_path)
save_path = main_folder + "/output.pdf"
outputStream = open(save_path, "wb")
output.write(outputStream)
outputStream.close()
if __name__ == '__main__':
main_path = input("main file path: ")
blank_path = input("blank file path: ")
main(main_path, blank_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment