Last active
January 18, 2022 20:15
-
-
Save noveoko/dd307cc60c61c6c216884a918095da96 to your computer and use it in GitHub Desktop.
This file contains 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 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