PyPDF2
1..reader
实现读操作
reader = PdfReader('fifles/MySQL.pdf')
reader2 = PdfReader('fifles/HEU_KMS_Activator_v20.0.0用户使用手册.pdf')
num = reader.getNumPages()
page1 = reader.getPage(0)
cover = reader2.getPage(0)
2..Writer
写操作
writer1 = PdfWriter('fifles/MySQL.pdf')
writer1.addPage(cover)
writer1.write('fifles/MySQL.pdf')
writer1.addBlankPage()
writer1.insertPage(cover,2)
reader1 = PdfReader('fifles/water.pdf')
water = reader1.getPage(0)
reader2 = PdfReader('fifles/HEU_KMS_Activator_v20.0.0用户使用手册.pdf')
page = reader2.getPage(1)
page.mergePage(water)
witer1 = PdfWriter()
witer1.addPage(page)
witer1.write('fifles/new.pdf')
3.reportlab
创建水印
from reportlab.pdfgen.canvas import Canvas
from reportlab.pdfbase.pdfmetrics import registerFont
from reportlab.pdfbase.ttfonts import TTFont
registerFont(TTFont('f1', 'fifles/aa.ttf'))
file = Canvas('fifles/mywater.pdf')
file.setFont('f1', 60)
file.setFillColorRGB(0, 1, 1, alpha=0.5)
file.rotate(45)
file.drawString(500, 160, '你好世界')
file.rotate(-45)
file.drawImage('fifles/car.png', 0, 0, mask='auto')
file.save()