中的每个元素
pdf.pages都是字典,因此假设它在第1页上,
pdf.pages[0]['/MYOBJECT']应该是您想要的元素。
您可以尝试单独打印或戳在它
help和
dir在提示更多关于如何得到你想要的字符串蟒蛇
编辑:
收到pdf副本后,我在找到了对象,
pdf.resolvedObjects[0][558]['/Resources']['/Properties']['/MC0']['/MYOBJECT']可以通过getData()检索值
以下函数通过递归查找有问题的密钥提供了一种更通用的解决方案
import typesimport pyPdfpdf = pyPdf.PdfFileReader(open('file.pdf'))pages = list(pdf.pages)def findInDict(needle,haystack): for key in haystack.keys(): try: value = haystack[key] except: continue if key == needle: return value if type(value) == types.DictType or isinstance(value,pyPdf.generic.DictionaryObject): x = findInDict(needle,value) if x is not None: return xanswer = findInDict('/MYOBJECT',pdf.resolvedObjects).getData()