# This program uses the PyPDF4 module to manipulate PDF documents
# Note:
# - Example PDFs can be downloaded from http://nostarch.com/automatestuff/
# - Book uses PyPDF2; I'm an overachiever that uses PyPDF4

# Copying Pages

import PyPDF4

pdf1File = open("meetingminutes.pdf", "rb")
pdf2File = open("meetingminutes2.pdf", "rb")
pdf1Reader = PyPDF4.PdfFileReader(pdf1File)
pdf2Reader = PyPDF4.PdfFileReader(pdf2File)
pdfWriter = PyPDF4.PdfFileWriter()

for pageNum in range(pdf1Reader.numPages):
    pageObj = pdf1Reader.getPage(pageNum)
    pdfWriter.addPage(pageObj)

for pageNum in range(pdf2Reader.numPages):
    pageObj = pdf2Reader.getPage(pageNum)
    pdfWriter.addPage(pageObj)

pdfOutputFile = open("combinedminutes.pdf", "wb")
pdfWriter.write(pdfOutputFile)
pdfOutputFile.close()
pdf1File.close()
pdf2File.close()

# Rotating Pages
minutesFile = open("meetingminutes.pdf", "rb")
pdfReader = PyPDF4.PdfFileReader(minutesFile)
page = pdfReader.getPage(0)
print(page.rotateClockwise(90))

pdfWriter = PyPDF4.PdfFileWriter()
pdfWriter.addPage(page)
resultPdfFile = open("rotatedPage.pdf", "wb")
pdfWriter.write(resultPdfFile)
resultPdfFile.close()
minutesFile.close()

# Overlaying Pages
minutesFile = open("meetingminutes.pdf", "rb")
pdfReader = PyPDF4.PdfFileReader(minutesFile)
minutesFirstPage = pdfReader.getPage(0)
pdfWatermarkReader = PyPDF4.PdfFileReader(open("watermark.pdf", "rb"))  # lol
minutesFirstPage.mergePage(pdfWatermarkReader.getPage(0))
pdfWriter = PyPDF4.PdfFileWriter()
pdfWriter.addPage(minutesFirstPage)

for pageNum in range(1, pdfReader.numPages):
    pageObj = pdfReader.getPage(pageNum)
    pdfWriter.addPage(pageObj)
resultPdfFile = open("watermarkedCover.pdf", "wb")
pdfWriter.write(resultPdfFile)
minutesFile.close()
resultPdfFile.close()

@@ -1750,28 +1750,383 @@
 ose()%0AresultPdfFile.close()%0A
+%0A# Encrypting PDFs%0ApdfFile = open(%22meetingminutes.pdf%22, %22rb%22)%0ApdfReader = PyPDF4.PdfFileReader(pdfFile)%0ApdfWriter = PyPDF4.PdfFileWriter()%0Afor pageNum in range(pdfReader.numPages):%0A    pdfWriter.addPage(pdfReader.getPage(pageNum))%0A%0ApdfWriter.encrypt(%22swordfish%22)%0AresultPdf = open(%22encryptedminutes.pdf%22, %22wb%22)%0ApdfWriter.write(resultPdf)%0AresultPdf.close()%0A

Update P02_writePDF added encrypting PDFs