Created
November 14, 2015 21:03
-
-
Save chatchavan/69f14bb5739862ad6f46 to your computer and use it in GitHub Desktop.
Extract the first page of PDF files in the current directory and combine them into a single PDF.
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
# requires: pip install pyPDF2 | |
from PyPDF2 import PdfFileReader, PdfFileWriter | |
import os | |
# prepare output writer | |
pdfWriter = PdfFileWriter() | |
# loop reading the first page of each files | |
for aFileName in [fname for fname in os.listdir(".") if ".pdf" in fname]: | |
pdfReader = PdfFileReader(open(aFileName, "rb")) | |
firstPage = pdfReader.getPage(0) | |
pdfWriter.addPage(firstPage) | |
# save target PDF file | |
fOut = open("FirstPages.pdf", "wb") | |
pdfWriter.write(fOut) | |
fOut.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment