pyhanko package
Subpackages
- pyhanko.config package
- Submodules
- pyhanko.config.api module
- pyhanko.config.errors module
- pyhanko.config.local_keys module
- pyhanko.config.logging module
- pyhanko.config.pkcs11 module
TokenCriteriaPKCS11PinEntryModePKCS11SignatureConfigPKCS11SignatureConfig.module_pathPKCS11SignatureConfig.cert_labelPKCS11SignatureConfig.cert_idPKCS11SignatureConfig.signing_certificatePKCS11SignatureConfig.token_criteriaPKCS11SignatureConfig.other_certsPKCS11SignatureConfig.key_labelPKCS11SignatureConfig.key_idPKCS11SignatureConfig.slot_noPKCS11SignatureConfig.user_pinPKCS11SignatureConfig.prompt_pinPKCS11SignatureConfig.other_certs_to_pullPKCS11SignatureConfig.bulk_fetchPKCS11SignatureConfig.prefer_pssPKCS11SignatureConfig.raw_mechanismPKCS11SignatureConfig.check_config_keys()PKCS11SignatureConfig.process_entries()
- pyhanko.config.trust module
- pyhanko.cli package
- pyhanko.pdf_utils package
- Subpackages
- Submodules
- pyhanko.pdf_utils.barcodes module
- pyhanko.pdf_utils.content module
- pyhanko.pdf_utils.embed module
- pyhanko.pdf_utils.extensions module
DevExtensionMultivaluedDeveloperExtensionDeveloperExtension.prefix_nameDeveloperExtension.base_versionDeveloperExtension.extension_levelDeveloperExtension.urlDeveloperExtension.extension_revisionDeveloperExtension.compare_by_levelDeveloperExtension.subsumed_byDeveloperExtension.subsumesDeveloperExtension.multivaluedDeveloperExtension.as_pdf_object()
- pyhanko.pdf_utils.filters module
- pyhanko.pdf_utils.generic module
DereferenceableReferenceTrailerReferencePdfObjectIndirectObjectNullObjectBooleanObjectFloatObjectNumberObjectByteStringObjectTextStringObjectNameObjectArrayObjectDictionaryObjectStreamObjectread_object()pdf_namepdf_string()pdf_date()TextStringEncodingEncryptedObjAccessDecryptedObjectProxy
- pyhanko.pdf_utils.images module
- pyhanko.pdf_utils.incremental_writer module
IncrementalPdfFileWriterIncrementalPdfFileWriter.IO_CHUNK_SIZEIncrementalPdfFileWriter.from_reader()IncrementalPdfFileWriter.ensure_output_version()IncrementalPdfFileWriter.get_object()IncrementalPdfFileWriter.mark_update()IncrementalPdfFileWriter.update_container()IncrementalPdfFileWriter.update_root()IncrementalPdfFileWriter.set_info()IncrementalPdfFileWriter.set_custom_trailer_entry()IncrementalPdfFileWriter.write()IncrementalPdfFileWriter.document_meta_viewIncrementalPdfFileWriter.write_in_place()IncrementalPdfFileWriter.encrypt()IncrementalPdfFileWriter.encrypt_pubkey()
- pyhanko.pdf_utils.layout module
- pyhanko.pdf_utils.misc module
PdfErrorPdfReadErrorPdfStrictReadErrorPdfWriteErrorPdfStreamErrorIndirectObjectExpectedget_and_apply()OrderedEnumStringWithLanguageis_regular_character()read_non_whitespace()read_until_whitespace()read_until_delimiter()read_until_regex()skip_over_whitespace()skip_over_comment()instance_test()peek()assert_writable_and_random_access()prepare_rw_output_stream()finalise_output()DEFAULT_CHUNK_SIZEchunked_write()chunked_digest()chunk_stream()ConsListSingletonrd()isoparse()lift_iterable_async()
- pyhanko.pdf_utils.qr module
PdfStreamQRImagePdfStreamQRImage.kindPdfStreamQRImage.allowed_kindsPdfStreamQRImage.qr_colorPdfStreamQRImage.new_image()PdfStreamQRImage.drawrect()PdfStreamQRImage.append_single_rect()PdfStreamQRImage.format_qr_color()PdfStreamQRImage.setup_drawing_area()PdfStreamQRImage.render_command_stream()PdfStreamQRImage.save()PdfStreamQRImage.process()PdfStreamQRImage.drawrect_context()
PdfFancyQRImagePdfFancyQRImage.centerpiece_corner_radiusPdfFancyQRImage.save()PdfFancyQRImage.process()PdfFancyQRImage.append_single_rect()PdfFancyQRImage.is_major_position_pattern()PdfFancyQRImage.is_position_pattern()PdfFancyQRImage.draw_position_patterns()PdfFancyQRImage.draw_centerpiece()PdfFancyQRImage.setup_drawing_area()PdfFancyQRImage.render_command_stream()
rounded_square()
- pyhanko.pdf_utils.reader module
PdfFileReaderPdfFileReader.xrefsPdfFileReader.last_startxrefPdfFileReader.has_xref_streamPdfFileReader.security_handlerPdfFileReader.document_meta_viewPdfFileReader.input_versionPdfFileReader.encrypt_dictPdfFileReader.trailer_viewPdfFileReader.root_refPdfFileReader.document_idPdfFileReader.get_historical_root()PdfFileReader.total_revisionsPdfFileReader.get_object()PdfFileReader.cache_get_indirect_object()PdfFileReader.cache_indirect_object()PdfFileReader.decrypt()PdfFileReader.decrypt_pubkey()PdfFileReader.encryptedPdfFileReader.get_historical_resolver()PdfFileReader.embedded_signaturesPdfFileReader.embedded_regular_signaturesPdfFileReader.embedded_timestamp_signatures
HistoricalResolverHistoricalResolver.document_meta_viewHistoricalResolver.document_idHistoricalResolver.trailer_viewHistoricalResolver.get_object()HistoricalResolver.root_refHistoricalResolver.explicit_refs_in_revision()HistoricalResolver.refs_freed_in_revision()HistoricalResolver.object_streams_used()HistoricalResolver.is_ref_available()HistoricalResolver.collect_dependencies()
parse_catalog_version()RawPdfPathprocess_data_at_eof()
- pyhanko.pdf_utils.rw_common module
- pyhanko.pdf_utils.text module
- pyhanko.pdf_utils.writer module
BasePdfFileWriterBasePdfFileWriter.output_versionBasePdfFileWriter.stream_xrefsBasePdfFileWriter.get_subset_collection()BasePdfFileWriter.document_metaBasePdfFileWriter.document_meta_viewBasePdfFileWriter.ensure_output_version()BasePdfFileWriter.set_info()BasePdfFileWriter.set_custom_trailer_entry()BasePdfFileWriter.document_idBasePdfFileWriter.mark_update()BasePdfFileWriter.update_container()BasePdfFileWriter.root_refBasePdfFileWriter.update_root()BasePdfFileWriter.register_extension()BasePdfFileWriter.get_object()BasePdfFileWriter.allocate_placeholder()BasePdfFileWriter.add_object()BasePdfFileWriter.prepare_object_stream()BasePdfFileWriter.trailer_viewBasePdfFileWriter.write()BasePdfFileWriter.register_annotation()BasePdfFileWriter.insert_page()BasePdfFileWriter.import_object()BasePdfFileWriter.import_page_as_xobject()BasePdfFileWriter.add_stream_to_page()BasePdfFileWriter.merge_resources()
PageObjectPdfFileWriterinit_xobject_dictionary()copy_into_new_writer()
- pyhanko.pdf_utils.xref module
XRefCacheXRefCache.total_revisionsXRefCache.get_last_change()XRefCache.object_streams_used_in()XRefCache.get_introducing_revision()XRefCache.get_xref_container_info()XRefCache.get_xref_data()XRefCache.explicit_refs_in_revision()XRefCache.refs_freed_in_revision()XRefCache.get_startxref_for_revision()XRefCache.get_historical_ref()XRefCache.hybrid_xrefs_present
XRefBuilderXRefTypeXRefEntryObjStreamRefObjectHeaderReadErrorXRefSectionXRefSectionDataXRefSectionTypeXRefSectionMetaInfoTrailerDictionaryread_object_header()parse_xref_stream()parse_xref_table()write_xref_table()ObjectStreamXRefStream
- Module contents
- pyhanko.sign package
- Subpackages
- pyhanko.sign.ades package
- pyhanko.sign.diff_analysis package
- Guidelines for developing rules for use with
StandardDiffPolicy - Subpackages
- Submodules
- pyhanko.sign.diff_analysis.commons module
- pyhanko.sign.diff_analysis.constants module
- pyhanko.sign.diff_analysis.form_rules_api module
- pyhanko.sign.diff_analysis.policies module
- pyhanko.sign.diff_analysis.policy_api module
- pyhanko.sign.diff_analysis.rules_api module
- Guidelines for developing rules for use with
- pyhanko.sign.signers package
- pyhanko.sign.timestamps package
- pyhanko.sign.validation package
- Subpackages
- Submodules
- pyhanko.sign.validation.ades module
- pyhanko.sign.validation.dss module
- pyhanko.sign.validation.errors module
- pyhanko.sign.validation.generic_cms module
- pyhanko.sign.validation.ltv module
- pyhanko.sign.validation.pdf_embedded module
- pyhanko.sign.validation.policy_decl module
- pyhanko.sign.validation.settings module
- pyhanko.sign.validation.status module
- pyhanko.sign.validation.utils module
- Module contents
- Submodules
- pyhanko.sign.attributes module
- pyhanko.sign.fields module
SigFieldSpecSigFieldSpec.sig_field_nameSigFieldSpec.on_pageSigFieldSpec.boxSigFieldSpec.seed_value_dictSigFieldSpec.field_mdp_specSigFieldSpec.doc_mdp_update_valueSigFieldSpec.combine_annotationSigFieldSpec.empty_field_appearanceSigFieldSpec.invis_sig_settingsSigFieldSpec.readable_field_nameSigFieldSpec.visible_sig_settingsSigFieldSpec.format_lock_dictionary()
SigSeedValFlagsSigCertConstraintsSigCertConstraints.flagsSigCertConstraints.subjectsSigCertConstraints.subject_dnSigCertConstraints.issuersSigCertConstraints.info_urlSigCertConstraints.url_typeSigCertConstraints.key_usageSigCertConstraints.from_pdf_object()SigCertConstraints.as_pdf_object()SigCertConstraints.satisfied_by()
SigSeedValueSpecSigSeedValueSpec.flagsSigSeedValueSpec.reasonsSigSeedValueSpec.timestamp_server_urlSigSeedValueSpec.timestamp_requiredSigSeedValueSpec.certSigSeedValueSpec.subfiltersSigSeedValueSpec.digest_methodsSigSeedValueSpec.add_rev_infoSigSeedValueSpec.seed_signature_typeSigSeedValueSpec.sv_dict_versionSigSeedValueSpec.legal_attestationsSigSeedValueSpec.lock_documentSigSeedValueSpec.appearanceSigSeedValueSpec.as_pdf_object()SigSeedValueSpec.from_pdf_object()SigSeedValueSpec.build_timestamper()
SigCertConstraintFlagsSigSeedSubFilterSeedValueDictVersionSeedLockDocumentSigCertKeyUsageMDPPermFieldMDPActionFieldMDPSpecSignatureFormFieldInvisSigSettingsVisibleSigSettingsenumerate_sig_fields()append_signature_field()ensure_sig_flags()prepare_sig_field()apply_sig_field_spec_properties()annot_width_height()get_sig_field_annot()
- pyhanko.sign.general module
simple_cms_attribute()find_cms_attribute()find_unique_cms_attribute()NonexistentAttributeErrorMultivaluedAttributeErrorSigningErrorUnacceptableSignerErrorSignedDataCertsextract_signer_info()extract_certificate_info()get_cms_hash_algo_for_mechanism()get_pyca_cryptography_hash()get_pyca_cryptography_hash_for_signing()optimal_pss_params()process_pss_params()as_signing_certificate()as_signing_certificate_v2()match_issuer_serial()check_ess_certid()CMSExtractionErrorbyte_range_digest()ValueErrorWithMessageCMSStructuralErrorload_cert_from_pemder()load_certs_from_pemder()load_certs_from_pemder_data()load_private_key_from_pemder()load_private_key_from_pemder_data()
- pyhanko.sign.pkcs11 module
- Module contents
- Subpackages
Submodules
pyhanko.keys module
Utility module to load keys and certificates.
- pyhanko.keys.load_cert_from_pemder(cert_file)
A convenience function to load a single PEM/DER-encoded certificate from a file.
- Parameters:
cert_file – A file name.
- Returns:
An
asn1crypto.x509.Certificateobject.
- pyhanko.keys.load_certs_from_pemder(cert_files)
A convenience function to load PEM/DER-encoded certificates from files.
- Parameters:
cert_files – An iterable of file names.
- Returns:
A generator producing
asn1crypto.x509.Certificateobjects.
- pyhanko.keys.load_certs_from_pemder_data(cert_data_bytes: bytes)
A convenience function to load PEM/DER-encoded certificates from binary data.
- Parameters:
cert_data_bytes –
bytesobject from which to extract certificates.- Returns:
A generator producing
asn1crypto.x509.Certificateobjects.
- pyhanko.keys.load_private_key_from_pemder(key_file, passphrase: bytes | None) PrivateKeyInfo
A convenience function to load PEM/DER-encoded keys from files.
- Parameters:
key_file – File to read the key from.
passphrase – Key passphrase.
- Returns:
A private key encoded as an unencrypted PKCS#8 PrivateKeyInfo object.
- pyhanko.keys.load_private_key_from_pemder_data(key_bytes: bytes, passphrase: bytes | None) PrivateKeyInfo
A convenience function to load PEM/DER-encoded keys from binary data.
- Parameters:
key_bytes –
bytesobject to read the key from.passphrase – Key passphrase.
- Returns:
A private key encoded as an unencrypted PKCS#8 PrivateKeyInfo object.
pyhanko.stamp module
Utilities for stamping PDF files.
Here ‘stamping’ loosely refers to adding small overlays (QR codes, text boxes, etc.) on top of already existing content in PDF files.
The code in this module is also used by the sign module to render
signature appearances.
- class pyhanko.stamp.AnnotAppearances(normal: IndirectObject, rollover: IndirectObject | None = None, down: IndirectObject | None = None)
Bases:
objectConvenience abstraction to set up an appearance dictionary for a PDF annotation.
Annotations can have three appearance streams, which can be roughly characterised as follows:
normal: the only required one, and the default one;
rollover: used when mousing over the annotation;
down: used when clicking the annotation.
These are given as references to form XObjects.
Note
This class only covers the simple case of an appearance dictionary for an annotation with only one appearance state.
See § 12.5.5 in ISO 32000-1 for further information.
- as_pdf_object() DictionaryObject
Convert the
AnnotationAppearancesinstance to a PDF dictionary.- Returns:
A
DictionaryObjectthat can be plugged into the/APentry of an annotation dictionary.
- class pyhanko.stamp.BaseStampStyle(border_width: int = 3, background: ~pyhanko.pdf_utils.content.PdfContent | None = None, background_layout: ~pyhanko.pdf_utils.layout.SimpleBoxLayoutRule = SimpleBoxLayoutRule(x_align=<AxisAlignment.ALIGN_MID: 2>, y_align=<AxisAlignment.ALIGN_MID: 2>, margins=Margins(left=5, right=5, top=5, bottom=5), inner_content_scaling=<InnerScaling.SHRINK_TO_FIT: 4>), background_opacity: float = 0.6)
Bases:
ConfigurableMixinBase class for stamp styles.
- border_width: int = 3
Border width in user units (for the stamp, not the text box).
- background: PdfContent | None = None
PdfContentinstance that will be used to render the stamp’s background.
- background_layout: SimpleBoxLayoutRule = SimpleBoxLayoutRule(x_align=<AxisAlignment.ALIGN_MID: 2>, y_align=<AxisAlignment.ALIGN_MID: 2>, margins=Margins(left=5, right=5, top=5, bottom=5), inner_content_scaling=<InnerScaling.SHRINK_TO_FIT: 4>)
Layout rule to render the background inside the stamp’s bounding box. Only used if the background has a fully specified
PdfContent.box.Otherwise, the renderer will position the cursor at
(left_margin, bottom_margin)and render the content as-is.
- background_opacity: float = 0.6
Opacity value to render the background at. This should be a floating-point number between 0 and 1.
- classmethod process_entries(config_dict)
This implementation of
process_entries()processes thebackgroundconfiguration value. This can either be a path to an image file, in which case it will be turned into an instance ofPdfImage, or the special value__stamp__, which is an alias forSTAMP_ART_CONTENT.
- create_stamp(writer: BasePdfFileWriter, box: BoxConstraints, text_params: dict) BaseStamp
- class pyhanko.stamp.TextStampStyle(border_width: int = 3, background: ~pyhanko.pdf_utils.content.PdfContent | None = None, background_layout: ~pyhanko.pdf_utils.layout.SimpleBoxLayoutRule = SimpleBoxLayoutRule(x_align=<AxisAlignment.ALIGN_MID: 2>, y_align=<AxisAlignment.ALIGN_MID: 2>, margins=Margins(left=5, right=5, top=5, bottom=5), inner_content_scaling=<InnerScaling.SHRINK_TO_FIT: 4>), background_opacity: float = 0.6, text_box_style: ~pyhanko.pdf_utils.text.TextBoxStyle = TextBoxStyle(font=<pyhanko.pdf_utils.font.basic.SimpleFontEngineFactory object>, font_size=10, leading=None, border_width=0, box_layout_rule=None, vertical_text=False), inner_content_layout: ~pyhanko.pdf_utils.layout.SimpleBoxLayoutRule | None = None, stamp_text: str = '%(ts)s', timestamp_format: str = '%Y-%m-%d %H:%M:%S %Z')
Bases:
BaseStampStyleStyle for text-based stamps.
Roughly speaking, this stamp type renders some predefined (but parametrised) piece of text inside a text box, and possibly applies a background to it.
- text_box_style: TextBoxStyle = TextBoxStyle(font=<pyhanko.pdf_utils.font.basic.SimpleFontEngineFactory object>, font_size=10, leading=None, border_width=0, box_layout_rule=None, vertical_text=False)
The text box style for the internal text box used.
- inner_content_layout: SimpleBoxLayoutRule | None = None
Rule determining the position and alignment of the inner text box within the stamp.
Warning
This only affects the position of the box, not the alignment of the text within.
- stamp_text: str = '%(ts)s'
Text template for the stamp. The template can contain an interpolation parameter
tsthat will be replaced by the stamping time.Additional parameters may be added if necessary. Values for these must be passed to the
__init__()method of theTextStampclass in thetext_paramsargument.
- timestamp_format: str = '%Y-%m-%d %H:%M:%S %Z'
Datetime format used to render the timestamp.
- create_stamp(writer: BasePdfFileWriter, box: BoxConstraints, text_params: dict) TextStamp
- class pyhanko.stamp.QRStampStyle(border_width: int = 3, background: ~pyhanko.pdf_utils.content.PdfContent | None = None, background_layout: ~pyhanko.pdf_utils.layout.SimpleBoxLayoutRule = SimpleBoxLayoutRule(x_align=<AxisAlignment.ALIGN_MID: 2>, y_align=<AxisAlignment.ALIGN_MID: 2>, margins=Margins(left=5, right=5, top=5, bottom=5), inner_content_scaling=<InnerScaling.SHRINK_TO_FIT: 4>), background_opacity: float = 0.6, text_box_style: ~pyhanko.pdf_utils.text.TextBoxStyle = TextBoxStyle(font=<pyhanko.pdf_utils.font.basic.SimpleFontEngineFactory object>, font_size=10, leading=None, border_width=0, box_layout_rule=None, vertical_text=False), inner_content_layout: ~pyhanko.pdf_utils.layout.SimpleBoxLayoutRule | None = None, stamp_text: str = 'Digital version available at\nthis url: %(url)s\nTimestamp: %(ts)s', timestamp_format: str = '%Y-%m-%d %H:%M:%S %Z', innsep: int = 3, qr_inner_size: int | None = None, qr_position: ~pyhanko.stamp.QRPosition = QRPosition.LEFT_OF_TEXT, qr_inner_content: ~pyhanko.pdf_utils.content.PdfContent | None = None)
Bases:
TextStampStyleStyle for text-based stamps together with a QR code.
This is exactly the same as a text stamp, except that the text box is rendered with a QR code to the left of it.
- innsep: int = 3
Inner separation inside the stamp.
- stamp_text: str = 'Digital version available at\nthis url: %(url)s\nTimestamp: %(ts)s'
Text template for the stamp. The description of
TextStampStyle.stamp_textstill applies, but an additional default interpolation parameterurlis available. This parameter will be replaced with the URL that the QR code points to.
- qr_inner_size: int | None = None
Size of the QR code in the inner layout. By default, this is in user units, but if the stamp has a fully defined bounding box, it may be rescaled depending on
inner_content_layout.If unspecified, a reasonable default will be used.
- qr_position: QRPosition = SimpleBoxLayoutRule(x_align=<AxisAlignment.ALIGN_MIN: 1>, y_align=<AxisAlignment.ALIGN_MID: 2>, margins=Margins(left=0, right=0, top=0, bottom=0), inner_content_scaling=<InnerScaling.SHRINK_TO_FIT: 4>)
Position of the QR code relative to the text box.
- qr_inner_content: PdfContent | None = None
Inner graphics content to be included in the QR code (experimental).
- classmethod process_entries(config_dict)
This implementation of
process_entries()processes thebackgroundconfiguration value. This can either be a path to an image file, in which case it will be turned into an instance ofPdfImage, or the special value__stamp__, which is an alias forSTAMP_ART_CONTENT.
- create_stamp(writer: BasePdfFileWriter, box: BoxConstraints, text_params: dict) QRStamp
- class pyhanko.stamp.StaticStampStyle(border_width: int = 3, background: ~pyhanko.pdf_utils.content.PdfContent | None = None, background_layout: ~pyhanko.pdf_utils.layout.SimpleBoxLayoutRule = SimpleBoxLayoutRule(x_align=<AxisAlignment.ALIGN_MID: 2>, y_align=<AxisAlignment.ALIGN_MID: 2>, margins=Margins(left=5, right=5, top=5, bottom=5), inner_content_scaling=<InnerScaling.SHRINK_TO_FIT: 4>), background_opacity: float = 1.0)
Bases:
BaseStampStyleStamp style that does not include any custom parts; it only renders the background.
- background_opacity: float = 1.0
Opacity value to render the background at. This should be a floating-point number between 0 and 1.
- classmethod from_pdf_file(file_name, page_ix=0, **kwargs) StaticStampStyle
Create a
StaticStampStylefrom a page from an external PDF document. This is a convenience wrapper aroundImportedPdfContent.The remaining keyword arguments are passed to
StaticStampStyle’s init method.- Parameters:
file_name – File name of the external PDF document.
page_ix – Page index to import. The default is
0, i.e. the first page.
- create_stamp(writer: BasePdfFileWriter, box: BoxConstraints, text_params: dict) StaticContentStamp
- class pyhanko.stamp.QRPosition(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
EnumQR positioning constants, with the corresponding default content layout rule.
- LEFT_OF_TEXT = SimpleBoxLayoutRule(x_align=<AxisAlignment.ALIGN_MIN: 1>, y_align=<AxisAlignment.ALIGN_MID: 2>, margins=Margins(left=0, right=0, top=0, bottom=0), inner_content_scaling=<InnerScaling.SHRINK_TO_FIT: 4>)
- RIGHT_OF_TEXT = SimpleBoxLayoutRule(x_align=<AxisAlignment.ALIGN_MAX: 3>, y_align=<AxisAlignment.ALIGN_MID: 2>, margins=Margins(left=0, right=0, top=0, bottom=0), inner_content_scaling=<InnerScaling.SHRINK_TO_FIT: 4>)
- ABOVE_TEXT = SimpleBoxLayoutRule(x_align=<AxisAlignment.ALIGN_MID: 2>, y_align=<AxisAlignment.ALIGN_MAX: 3>, margins=Margins(left=0, right=0, top=0, bottom=0), inner_content_scaling=<InnerScaling.SHRINK_TO_FIT: 4>)
- BELOW_TEXT = SimpleBoxLayoutRule(x_align=<AxisAlignment.ALIGN_MID: 2>, y_align=<AxisAlignment.ALIGN_MIN: 1>, margins=Margins(left=0, right=0, top=0, bottom=0), inner_content_scaling=<InnerScaling.SHRINK_TO_FIT: 4>)
- property horizontal_flow
- classmethod from_config(config_str) QRPosition
Convert from a configuration string.
- Parameters:
config_str – A string: ‘left’, ‘right’, ‘top’, ‘bottom’
- Returns:
An
QRPositionvalue.- Raises:
ConfigurationError – on unexpected string inputs.
- class pyhanko.stamp.BaseStamp(writer: BasePdfFileWriter, style, box: BoxConstraints | None = None)
Bases:
PdfContent- render()
Compile the content to graphics operators.
- register() IndirectObject
Register the stamp with the writer coupled to this instance, and cache the returned reference.
This works by calling
PdfContent.as_form_xobject().- Returns:
An indirect reference to the form XObject containing the stamp.
- apply(dest_page: int, x: int, y: int)
Apply a stamp to a particular page in the PDF writer attached to this
BaseStampinstance.- Parameters:
dest_page – Index of the page to which the stamp is to be applied (starting at 0).
x – Horizontal position of the stamp’s lower left corner on the page.
y – Vertical position of the stamp’s lower left corner on the page.
- Returns:
A reference to the affected page object, together with a
(width, height)tuple describing the dimensions of the stamp.
- as_appearances() AnnotAppearances
Turn this stamp into an appearance dictionary for an annotation (or a form field widget), after rendering it. Only the normal appearance will be defined.
- Returns:
An instance of
AnnotAppearances.
- class pyhanko.stamp.TextStamp(writer: BasePdfFileWriter, style, text_params=None, box: BoxConstraints | None = None)
Bases:
BaseStampClass that renders a text stamp as specified by an instance of
TextStampStyle.- get_default_text_params()
Compute values for the default string interpolation parameters to be applied to the template string specified in the stamp style. This method does not take into account the
text_paramsinit parameter yet.- Returns:
A dictionary containing the parameters and their values.
- class pyhanko.stamp.QRStamp(writer: BasePdfFileWriter, url: str, style: QRStampStyle, text_params=None, box: BoxConstraints | None = None)
Bases:
TextStamp- get_default_text_params()
Compute values for the default string interpolation parameters to be applied to the template string specified in the stamp style. This method does not take into account the
text_paramsinit parameter yet.- Returns:
A dictionary containing the parameters and their values.
- apply(dest_page, x, y)
Apply a stamp to a particular page in the PDF writer attached to this
BaseStampinstance.- Parameters:
dest_page – Index of the page to which the stamp is to be applied (starting at 0).
x – Horizontal position of the stamp’s lower left corner on the page.
y – Vertical position of the stamp’s lower left corner on the page.
- Returns:
A reference to the affected page object, together with a
(width, height)tuple describing the dimensions of the stamp.
- class pyhanko.stamp.StaticContentStamp(writer: BasePdfFileWriter, style: StaticStampStyle, box: BoxConstraints)
Bases:
BaseStampClass representing stamps with static content.
- pyhanko.stamp.text_stamp_file(input_name: str, output_name: str, style: TextStampStyle, dest_page: int, x: int, y: int, text_params=None)
Add a text stamp to a file.
- Parameters:
input_name – Path to the input file.
output_name – Path to the output file.
style – Text stamp style to use.
dest_page – Index of the page to which the stamp is to be applied (starting at 0).
x – Horizontal position of the stamp’s lower left corner on the page.
y – Vertical position of the stamp’s lower left corner on the page.
text_params – Additional parameters for text template interpolation.
- pyhanko.stamp.qr_stamp_file(input_name: str, output_name: str, style: QRStampStyle, dest_page: int, x: int, y: int, url: str, text_params=None)
Add a QR stamp to a file.
- Parameters:
input_name – Path to the input file.
output_name – Path to the output file.
style – QR stamp style to use.
dest_page – Index of the page to which the stamp is to be applied (starting at 0).
x – Horizontal position of the stamp’s lower left corner on the page.
y – Vertical position of the stamp’s lower left corner on the page.
url – URL for the QR code to point to.
text_params – Additional parameters for text template interpolation.
- pyhanko.stamp.STAMP_ART_CONTENT = <pyhanko.pdf_utils.content.RawContent object>
Hardcoded stamp background that will render a stylised image of a stamp using PDF graphics operators (see below).