12

pypdf を使用して PDF ドキュメントのタイトルを作成/変更したいと思います。タイトルは読み取り専用のようです。このメタデータに r/w でアクセスする方法はありますか?

肯定的な答えがあれば、コードをいただければ幸いです。

ありがとう

4

1 に答える 1

9

タイトルはpyPDF(一種)で操作できます。reportlab-users リストで次の投稿を見つけました。

http://two.pairlist.net/pipermail/reportlab-users/2009-November/009033.html

pypdf も使用できます。 http://pybrary.net/pyPdf/

これにより、メタデータ自体を編集することはできませんが、1 つまたは複数の pdf ファイルを読み込んで、おそらく新しいメタデータとともに吐き出すことができます。

関連するコードは次のとおりです。

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()
于 2010-07-15T15:51:14.420 に答える