本文整理匯總了Python中pdfminer.psparser.PSLiteral方法的典型用法代碼示例。如果您正苦於以下問題:Python psparser.PSLiteral方法的具體用法?Python psparser.PSLiteral怎麽用?Python psparser.PSLiteral使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pdfminer.psparser
的用法示例。
在下文中一共展示了psparser.PSLiteral方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: decode_psl_list
# 需要導入模塊: from pdfminer import psparser [as 別名]
# 或者: from pdfminer.psparser import PSLiteral [as 別名]
def decode_psl_list(_list):
return [ decode_text(value.name) if isinstance(value, PSLiteral) else value
for value in _list ]
# via pdfminer.pdftypes, altered slightly
示例2: __init__
# 需要導入模塊: from pdfminer import psparser [as 別名]
# 或者: from pdfminer.psparser import PSLiteral [as 別名]
def __init__(self,
stream,
pages = None,
laparams = None,
precision = 0.001,
password = ""
):
self.laparams = None if laparams == None else LAParams(**laparams)
self.stream = stream
self.pages_to_parse = pages
self.precision = precision
rsrcmgr = PDFResourceManager()
self.doc = PDFDocument(PDFParser(stream), password = password)
self.metadata = {}
for info in self.doc.info:
self.metadata.update(info)
for k, v in self.metadata.items():
if hasattr(v, "resolve"):
v = v.resolve()
if type(v) == list:
self.metadata[k] = list(map(decode_text, v))
elif isinstance(v, PSLiteral):
self.metadata[k] = decode_text(v.name)
elif isinstance(v, bool):
self.metadata[k] = v
else:
self.metadata[k] = decode_text(v)
self.device = PDFPageAggregator(rsrcmgr, laparams=self.laparams)
self.interpreter = PDFPageInterpreter(rsrcmgr, self.device)
示例3: main
# 需要導入模塊: from pdfminer import psparser [as 別名]
# 或者: from pdfminer.psparser import PSLiteral [as 別名]
def main():
fn = input("PDF filename: ")
character = {}
with open(fn, mode='rb') as f:
parser = PDFParser(f)
doc = PDFDocument(parser)
try:
fields = resolve1(doc.catalog['AcroForm'])
fields = resolve1(fields['Fields'])
except:
raise Exception('This is not a form-fillable character sheet!')
for i in fields:
field = resolve1(i)
name, value = field.get('T'), field.get('V')
if isinstance(value, PSLiteral):
value = value.name
elif value is not None:
try:
value = value.decode('iso-8859-1').strip()
except:
pass
character[name.decode('iso-8859-1').strip()] = value
print(character)
with open('./output/pdfsheet-test.json', mode='w') as f:
json.dump(character, f, skipkeys=True, sort_keys=True, indent=4)
示例4: make_pdf_metadata_str
# 需要導入模塊: from pdfminer import psparser [as 別名]
# 或者: from pdfminer.psparser import PSLiteral [as 別名]
def make_pdf_metadata_str(value) -> str:
if isinstance(value, bytes):
metadata_str = value.decode('utf-8')
elif isinstance(value, str):
metadata_str = value
elif isinstance(value, (PSLiteral, PSKeyword)):
metadata_str = make_pdf_metadata_str(value.name)
else:
metadata_str = ''
return metadata_str
示例5: resolve_dest
# 需要導入模塊: from pdfminer import psparser [as 別名]
# 或者: from pdfminer.psparser import PSLiteral [as 別名]
def resolve_dest(cls, dest):
if isinstance(dest, str):
dest = resolve1(doc.get_dest(dest))
elif isinstance(dest, psparser.PSLiteral):
dest = resolve1(doc.get_dest(dest.name))
if isinstance(dest, dict):
dest = dest['D']
return dest