Writing metadata to a pdf using pyobjc

后端 未结 2 1385
终归单人心
终归单人心 2021-02-09 17:18

I\'m trying to write metadata to a pdf file using the following python code:

from Foundation import *
from Quartz import *

url = NSURL.fileURLWithPath_(\"test.p         


        
2条回答
  •  离开以前
    2021-02-09 17:46

    DISCLAIMER: I'm utterly new to Python, but an old hand at PDF.

    To avoid smashing all the existing attributes, you need to start attrs with pdfDoc.documentAttributes, not {}. setDocumentAttributes is almost certainly an overwrite rather than a merge (given your output here).

    Second, all the PDFDocument*Attribute constants are part of PDFDocument. My Python ignorance is undoubtedly showing, but shouldn't you be referencing them as attributes rather than as bare variables? Like this:

    attrs[PDFDocument.PDFDocumentTitleAttribute] = "THIS IS THE TITLE"
    

    That you can assign to PDFDocumentTitleAttribute leads me to believe it's not a constant.

    If I'm right, your attrs will have tried to assign numerous values to a null key. My Python is weak, so I don't know how you'd check that. Examining attrs prior to calling pdfDoc.setDocumentAttributes_() should be revealing.

提交回复
热议问题