本文整理匯總了Python中pdfrw.PdfReader方法的典型用法代碼示例。如果您正苦於以下問題:Python pdfrw.PdfReader方法的具體用法?Python pdfrw.PdfReader怎麽用?Python pdfrw.PdfReader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pdfrw
的用法示例。
在下文中一共展示了pdfrw.PdfReader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def __init__(self, file_or_reader, scale=None, compress=True):
"""Draw annotations directly on PDFs. Annotations are always drawn on
as if you're drawing them in a viewer, i.e. they take into account page
rotation and weird, translated coordinate spaces.
:param str|PdfReader file_or_reader: filename of PDF or pdfrw.PdfReader
:param number|tuple|None scale: number by which to scale coordinates
to get to default user space. Use this if, for example, your points
in the coordinate space of the PDF viewed at a dpi. In this case,
scale would be 72/dpi. Can also specify a 2-tuple of x and y scale.
:param bool compress: whether to output flate-compressed PDFs
"""
if isinstance(file_or_reader, str):
file_or_reader = PdfReader(file_or_reader)
self._pdf = PDF(file_or_reader)
self._scale = self._expand_scale(scale)
self._dimensions = {}
self._compress = compress
示例2: get_issuer_address
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def get_issuer_address(pdf_file):
pdf = PdfReader(pdf_file)
try:
version = pdf.Info.version
if(version == '1'):
issuer = json.loads( pdf.Info.issuer.decode() )
return issuer['identity']['address']
else:
issuer_address = pdf.Info.issuer_address
if issuer_address:
return issuer_address.decode()
else:
metadata_object = json.loads( pdf.Info.metadata_object.decode() )
return metadata_object['issuer_address']
except AttributeError:
raise ValueError("Could not find issuer address in pdf")
示例3: __init__
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def __init__(self, filename_or_object, width=None, height=None, kind='direct'):
if hasattr(filename_or_object, 'read'):
filename_or_object.seek(0)
page = PdfReader(filename_or_object, decompress=False).pages[0]
self.xobj = pagexobj(page)
self.dynamic = 0
# Actual image size
x1, y1, x2, y2 = self.xobj.BBox
imgw, imgh = x2 - x1, y2 - y1
self._imgw, self._imgh = imgw, imgh
if kind in ['direct', 'absolute']:
self.drawWidth = width or imgw
self.drawHeight = height or imgh
elif kind in ['percentage', '%']:
self.drawWidth = imgw * width * 0.01
self.drawHeight = imgh * height * 0.01
elif kind in ['bound', 'proportional']:
w, h = width or imgw, height or imgh
factor = min(float(w) / imgw, float(h) / imgh)
self.drawWidth = imgw * factor
self.drawHeight = imgh * factor
elif kind in ['dynamic']:
self.dynamic = 1
示例4: set_pagelabel
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def set_pagelabel(self,count,style="arabic"):
if self.isPDF:
from pdfrw import PdfReader, PdfWriter
from pagelabels import PageLabels, PageLabelScheme
reader = PdfReader(self.filename)
labels = PageLabels.from_pdf(reader)
newlabels = PageLabels()
for label in labels:
if label.startpage != self.page:
newlabels.append(label)
newlabel = PageLabelScheme(startpage=self.page,
style=style,
prefix="",
firstpagenum=count)
newlabels.append(newlabel)
newlabels.write(reader)
writer = PdfWriter()
writer.trailer = reader
logging.debug("writing new pagelabels...")
writer.write(self.filename)
# unused; using pdfrw instead
示例5: merge
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def merge(overlay, basename):
'''
Merge the overlay with the original form, and return the result.
'''
input_pdf_path = os.path.join('templates', basename)
template_pdf = pdfrw.PdfReader(input_pdf_path)
overlay_pdf = pdfrw.PdfReader(overlay)
for page, data in zip(template_pdf.pages, overlay_pdf.pages):
overlay = pdfrw.PageMerge().add(data)[0]
pdfrw.PageMerge(page).add(overlay).render()
form = io.BytesIO()
pdfrw.PdfWriter().write(form, template_pdf)
form.seek(0)
return form
示例6: test_init_with_reader
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def test_init_with_reader(self):
a = PdfAnnotator(PdfReader(files.SIMPLE))
assert a._pdf is not None
示例7: test_write_with_compress_off_smoke_test
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def test_write_with_compress_off_smoke_test(self):
a = PdfAnnotator(PdfReader(files.SIMPLE), compress=False)
with write_to_temp(a) as t:
assert load_annotations_from_pdf(t) is None
示例8: load_annotations_from_pdf
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def load_annotations_from_pdf(filename, page=0):
reader = PdfReader(filename)
return reader.pages[page].Annots
示例9: _check_num_annotations
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def _check_num_annotations(self, output_file):
f = pdfrw.PdfReader(output_file)
assert len(f.pages[0].Annots) == self.EXPECTED_ANNOTATIONS
示例10: get_issuer_verification
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def get_issuer_verification(pdf_file):
pdf = PdfReader(pdf_file)
try:
version = pdf.Info.version
if(version == '1'):
issuer = json.loads( pdf.Info.issuer.decode() )
return issuer['identity']['verification']
except AttributeError:
raise ValueError("Could not find issuer address verification in pdf")
示例11: get_and_remove_chainpoint_proof
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def get_and_remove_chainpoint_proof(pdf_file):
pdf = PdfReader(pdf_file)
try:
proof = json.loads( pdf.Info.chainpoint_proof.decode() )
except AttributeError:
return None
metadata = PdfDict(chainpoint_proof='')
pdf.Info.update(metadata)
PdfWriter().write(pdf_file, pdf)
return proof
示例12: insert_proof_to_certificates
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def insert_proof_to_certificates(conf, cp, txid, cert_files, interactive=False):
if interactive:
print('')
for ind, val in enumerate(cert_files):
proof = json.dumps( cp.get_receipt(ind, txid) )
metadata = PdfDict(chainpoint_proof=proof)
pdf = PdfReader(val)
pdf.Info.update(metadata)
PdfWriter().write(val, pdf)
if interactive:
# print progress
print('.', end="", flush=True)
示例13: insert_proof_to_certificates
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def insert_proof_to_certificates(conf, cp, txid, cert_files, interactive=False):
if interactive:
print('')
for ind, val in enumerate(cert_files):
proof = json.dumps( cp.get_receipt(ind, txid) )
metadata = PdfDict(chainpoint_proof=proof)
pdf = PdfReader(val)
pdf.Info.update(metadata)
PdfWriter().write(val, pdf)
if interactive:
# print progress
print('.', end="", flush=True)
示例14: parse_pagelabels
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def parse_pagelabels(self):
if self.isPDF:
from pdfrw import PdfReader
from pagelabels import PageLabels, PageLabelScheme
try:
reader = PdfReader(self.filename)
labels = PageLabels.from_pdf(reader)
labels = sorted(labels, key=attrgetter('startpage'))
except:
labels = []
else:
labels = []
return labels
示例15: form_xo_reader
# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfReader [as 別名]
def form_xo_reader(imgdata):
page, = PdfReader(imgdata).pages
return pagexobj(page)