Bạn có thể thao tác tiêu đề bằng pyPDF (sắp xếp). Tôi đã xem qua bài này vào danh sách ReportLab người dùng:
http://two.pairlist.net/pipermail/reportlab-users/2009-November/009033.html
Bạn cũng có thể sử dụng pypdf. http://pybrary.net/pyPdf/
này sẽ không cho phép bạn chỉnh sửa siêu dữ liệu cho mỗi gia nhập, nhưng sẽ cho phép bạn đọc một hoặc nhiều file pdf (s) và nhổ chúng trở lại ra, có thể với siêu dữ liệu mới.
Dưới đây là các mã có liên quan:
from pyPdf import PdfFileWriter, PdfFileReader
from pyPdf.generic import NameObject, createStringObject
OUTPUT = 'output.pdf'
INPUTS = ['test1.pdf', 'test2.pdf', 'test3.pdf']
# There is no interface through pyPDF with which to set this other then getting
# your hands dirty like so:
infoDict = output._info.getObject()
infoDict.update({
NameObject('/Title'): createStringObject(u'title'),
NameObject('/Author'): createStringObject(u'author'),
NameObject('/Subject'): createStringObject(u'subject'),
NameObject('/Creator'): createStringObject(u'a script')
})
inputs = [PdfFileReader(i) for i in INPUTS]
for input in inputs:
for page in range(input.getNumPages()):
output.addPage(input.getPage(page))
outputStream = file(OUTPUT, 'wb')
output.write(outputStream)
outputStream.close()
Nguồn
2010-07-15 15:51:14
Khi xây dựng một PdfFileReader, bạn cần phải vượt qua một đối tượng tập tin giống như, không phải là một chuỗi/tên file (ít nhất là với pyPdf 1,13) –
[PyPDF2] (http : //mstamy2.github.io/PyPDF2/) (dường như đã thay thế pyPDF) có một phương thức gốc thực hiện điều này cho bạn: 'output.addMetadata ({'/ Title': 'title'})' – gellej