Skip to content

Instantly share code, notes, and snippets.

@CanOfBees
Created October 7, 2021 02:16
Show Gist options
  • Save CanOfBees/b1aee3a0139b3759c16eed99a2c8d0ed to your computer and use it in GitHub Desktop.
Save CanOfBees/b1aee3a0139b3759c16eed99a2c8d0ed to your computer and use it in GitHub Desktop.
python - create subset PDFs for error checking
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