Skip to content

Instantly share code, notes, and snippets.

@noveoko
Last active January 18, 2022 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noveoko/dd307cc60c61c6c216884a918095da96 to your computer and use it in GitHub Desktop.
Save noveoko/dd307cc60c61c6c216884a918095da96 to your computer and use it in GitHub Desktop.
import PyPDF2
from glob import glob
from pathlib import Path
from os import sys
try:
ROOT = Path(sys.argv[0]).as_posix()
TITLE = sys.argv[1]
except KeyError as ke:
print(ke)
files = glob(ROOT + "**/*.pdf", recursive=True)
pdfWriter = PyPDF2.PdfFileWriter()
for file in files:
pdf1Reader = PyPDF2.PdfFileReader(file)
for pageNum in range(pdf1Reader.numPages):
pageObj = pdf1Reader.getPage(pageNum)
pdfWriter.addPage(pageObj)
pdfOutputFile = open(f"{TITLE}.pdf", 'wb')
pdfWriter.write(pdfOutputFile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment