Created
October 7, 2021 02:16
-
-
Save CanOfBees/b1aee3a0139b3759c16eed99a2c8d0ed to your computer and use it in GitHub Desktop.
python - create subset PDFs for error checking
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
import sys | |
import os | |
from PyPDF2 import PdfFileReader, PdfFileWriter | |
inpfn = sys.argv[1] | |
file_base_name = inpfn.replace('.pdf','') | |
pdf = PdfFileReader(inpfn) | |
pages = [0,1,2,3,4,5] | |
pdfWriter = PdfFileWriter() | |
for page_num in pages: | |
pdfWriter.addPage(pdf.getPage(page_num)) | |
with open('{0}_subset.pdf'.format(file_base_name), 'wb') as f: | |
pdfWriter.write(f) | |
f.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment