summaryrefslogtreecommitdiff
path: root/Chap13ProjCombinePagesPdf.py
diff options
context:
space:
mode:
authormlot <petri-rush-curvy@duck.com>2025-06-06 13:40:57 -0400
committermlot <petri-rush-curvy@duck.com>2025-06-06 13:40:57 -0400
commit75a42ec54dbf721caa659ddf02c1f46fc2cb4bef (patch)
tree84be794a2481e356a7784557a6f9fb6fbf29cfdd /Chap13ProjCombinePagesPdf.py
initial commit for archivingHEADmain
Diffstat (limited to 'Chap13ProjCombinePagesPdf.py')
-rw-r--r--Chap13ProjCombinePagesPdf.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Chap13ProjCombinePagesPdf.py b/Chap13ProjCombinePagesPdf.py
new file mode 100644
index 0000000..8bbac84
--- /dev/null
+++ b/Chap13ProjCombinePagesPdf.py
@@ -0,0 +1,26 @@
+#! /usr/bin/env python3
+
+# Chapter 13 Project Combining Select Pages from Many PDF's
+# Combines all PDF's in the current working directory into a single PDF
+
+import PyPDF2
+import os
+
+pdfFiles = []
+for filename in os.listdir('.'):
+ if filename.endswith('.pdf'):
+ pdfFiles.append(filename)
+pdfFiles.sort(key = str.lower)
+
+pdfWriter = PyPDF2.PdfFileWriter()
+
+for filename in pdfFiles:
+ pdfFileObj = open(filename, 'rb')
+ pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
+ for pageNum in range(1, pdfReader.numPages):
+ pageObj = pdfReader.getPage(pageNum)
+ pdfWriter.addPage(pageObj)
+
+pdfOutput = open('allminutes.pdf', 'wb')
+pdfWriter.write(pdfOutput)
+pdfOutput.close()