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
TokenCriteria
PKCS11PinEntryMode
PKCS11SignatureConfig
PKCS11SignatureConfig.module_path
PKCS11SignatureConfig.cert_label
PKCS11SignatureConfig.cert_id
PKCS11SignatureConfig.signing_certificate
PKCS11SignatureConfig.token_criteria
PKCS11SignatureConfig.other_certs
PKCS11SignatureConfig.key_label
PKCS11SignatureConfig.key_id
PKCS11SignatureConfig.slot_no
PKCS11SignatureConfig.user_pin
PKCS11SignatureConfig.prompt_pin
PKCS11SignatureConfig.other_certs_to_pull
PKCS11SignatureConfig.bulk_fetch
PKCS11SignatureConfig.prefer_pss
PKCS11SignatureConfig.raw_mechanism
PKCS11SignatureConfig.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
DevExtensionMultivalued
DeveloperExtension
DeveloperExtension.prefix_name
DeveloperExtension.base_version
DeveloperExtension.extension_level
DeveloperExtension.url
DeveloperExtension.extension_revision
DeveloperExtension.compare_by_level
DeveloperExtension.subsumed_by
DeveloperExtension.subsumes
DeveloperExtension.multivalued
DeveloperExtension.as_pdf_object()
- pyhanko.pdf_utils.filters module
- pyhanko.pdf_utils.generic module
Dereferenceable
Reference
TrailerReference
PdfObject
IndirectObject
NullObject
BooleanObject
FloatObject
NumberObject
ByteStringObject
TextStringObject
NameObject
ArrayObject
DictionaryObject
StreamObject
read_object()
pdf_name
pdf_string()
pdf_date()
TextStringEncoding
EncryptedObjAccess
DecryptedObjectProxy
- pyhanko.pdf_utils.images module
- pyhanko.pdf_utils.incremental_writer module
IncrementalPdfFileWriter
IncrementalPdfFileWriter.IO_CHUNK_SIZE
IncrementalPdfFileWriter.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_view
IncrementalPdfFileWriter.write_in_place()
IncrementalPdfFileWriter.encrypt()
IncrementalPdfFileWriter.encrypt_pubkey()
- pyhanko.pdf_utils.layout module
- pyhanko.pdf_utils.misc module
PdfError
PdfReadError
PdfStrictReadError
PdfWriteError
PdfStreamError
IndirectObjectExpected
get_and_apply()
OrderedEnum
StringWithLanguage
is_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_SIZE
chunked_write()
chunked_digest()
chunk_stream()
ConsList
Singleton
rd()
isoparse()
lift_iterable_async()
- pyhanko.pdf_utils.qr module
PdfStreamQRImage
PdfStreamQRImage.kind
PdfStreamQRImage.allowed_kinds
PdfStreamQRImage.qr_color
PdfStreamQRImage.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()
PdfFancyQRImage
PdfFancyQRImage.centerpiece_corner_radius
PdfFancyQRImage.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
PdfFileReader
PdfFileReader.xrefs
PdfFileReader.last_startxref
PdfFileReader.has_xref_stream
PdfFileReader.security_handler
PdfFileReader.document_meta_view
PdfFileReader.input_version
PdfFileReader.encrypt_dict
PdfFileReader.trailer_view
PdfFileReader.root_ref
PdfFileReader.document_id
PdfFileReader.get_historical_root()
PdfFileReader.total_revisions
PdfFileReader.get_object()
PdfFileReader.cache_get_indirect_object()
PdfFileReader.cache_indirect_object()
PdfFileReader.decrypt()
PdfFileReader.decrypt_pubkey()
PdfFileReader.encrypted
PdfFileReader.get_historical_resolver()
PdfFileReader.embedded_signatures
PdfFileReader.embedded_regular_signatures
PdfFileReader.embedded_timestamp_signatures
HistoricalResolver
HistoricalResolver.document_meta_view
HistoricalResolver.document_id
HistoricalResolver.trailer_view
HistoricalResolver.get_object()
HistoricalResolver.root_ref
HistoricalResolver.explicit_refs_in_revision()
HistoricalResolver.refs_freed_in_revision()
HistoricalResolver.object_streams_used()
HistoricalResolver.is_ref_available()
HistoricalResolver.collect_dependencies()
parse_catalog_version()
RawPdfPath
process_data_at_eof()
- pyhanko.pdf_utils.rw_common module
- pyhanko.pdf_utils.text module
- pyhanko.pdf_utils.writer module
BasePdfFileWriter
BasePdfFileWriter.output_version
BasePdfFileWriter.stream_xrefs
BasePdfFileWriter.get_subset_collection()
BasePdfFileWriter.document_meta
BasePdfFileWriter.document_meta_view
BasePdfFileWriter.ensure_output_version()
BasePdfFileWriter.set_info()
BasePdfFileWriter.set_custom_trailer_entry()
BasePdfFileWriter.document_id
BasePdfFileWriter.mark_update()
BasePdfFileWriter.update_container()
BasePdfFileWriter.root_ref
BasePdfFileWriter.update_root()
BasePdfFileWriter.register_extension()
BasePdfFileWriter.get_object()
BasePdfFileWriter.allocate_placeholder()
BasePdfFileWriter.add_object()
BasePdfFileWriter.prepare_object_stream()
BasePdfFileWriter.trailer_view
BasePdfFileWriter.write()
BasePdfFileWriter.register_annotation()
BasePdfFileWriter.insert_page()
BasePdfFileWriter.import_object()
BasePdfFileWriter.import_page_as_xobject()
BasePdfFileWriter.add_stream_to_page()
BasePdfFileWriter.merge_resources()
PageObject
PdfFileWriter
init_xobject_dictionary()
copy_into_new_writer()
- pyhanko.pdf_utils.xref module
XRefCache
XRefCache.total_revisions
XRefCache.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
XRefBuilder
XRefType
XRefEntry
ObjStreamRef
ObjectHeaderReadError
XRefSection
XRefSectionData
XRefSectionType
XRefSectionMetaInfo
TrailerDictionary
read_object_header()
parse_xref_stream()
parse_xref_table()
write_xref_table()
ObjectStream
XRefStream
- 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.beid module
- pyhanko.sign.fields module
SigFieldSpec
SigFieldSpec.sig_field_name
SigFieldSpec.on_page
SigFieldSpec.box
SigFieldSpec.seed_value_dict
SigFieldSpec.field_mdp_spec
SigFieldSpec.doc_mdp_update_value
SigFieldSpec.combine_annotation
SigFieldSpec.empty_field_appearance
SigFieldSpec.invis_sig_settings
SigFieldSpec.readable_field_name
SigFieldSpec.visible_sig_settings
SigFieldSpec.format_lock_dictionary()
SigSeedValFlags
SigCertConstraints
SigCertConstraints.flags
SigCertConstraints.subjects
SigCertConstraints.subject_dn
SigCertConstraints.issuers
SigCertConstraints.info_url
SigCertConstraints.url_type
SigCertConstraints.key_usage
SigCertConstraints.from_pdf_object()
SigCertConstraints.as_pdf_object()
SigCertConstraints.satisfied_by()
SigSeedValueSpec
SigSeedValueSpec.flags
SigSeedValueSpec.reasons
SigSeedValueSpec.timestamp_server_url
SigSeedValueSpec.timestamp_required
SigSeedValueSpec.cert
SigSeedValueSpec.subfilters
SigSeedValueSpec.digest_methods
SigSeedValueSpec.add_rev_info
SigSeedValueSpec.seed_signature_type
SigSeedValueSpec.sv_dict_version
SigSeedValueSpec.legal_attestations
SigSeedValueSpec.lock_document
SigSeedValueSpec.appearance
SigSeedValueSpec.as_pdf_object()
SigSeedValueSpec.from_pdf_object()
SigSeedValueSpec.build_timestamper()
SigCertConstraintFlags
SigSeedSubFilter
SeedValueDictVersion
SeedLockDocument
SigCertKeyUsage
MDPPerm
FieldMDPAction
FieldMDPSpec
SignatureFormField
InvisSigSettings
VisibleSigSettings
enumerate_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()
NonexistentAttributeError
MultivaluedAttributeError
SigningError
UnacceptableSignerError
SignedDataCerts
extract_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()
CMSExtractionError
byte_range_digest()
ValueErrorWithMessage
CMSStructuralError
load_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.Certificate
object.
- 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.Certificate
objects.
- 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 –
bytes
object from which to extract certificates.- Returns:
A generator producing
asn1crypto.x509.Certificate
objects.
- 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 –
bytes
object 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:
object
Convenience 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
AnnotationAppearances
instance to a PDF dictionary.- Returns:
A
DictionaryObject
that can be plugged into the/AP
entry 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:
ConfigurableMixin
Base class for stamp styles.
- border_width: int = 3
Border width in user units (for the stamp, not the text box).
- background: PdfContent | None = None
PdfContent
instance 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 thebackground
configuration 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:
BaseStampStyle
Style 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
ts
that 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 theTextStamp
class in thetext_params
argument.
- 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:
TextStampStyle
Style 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_text
still applies, but an additional default interpolation parameterurl
is 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 thebackground
configuration 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:
BaseStampStyle
Stamp 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
StaticStampStyle
from 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:
Enum
QR 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
QRPosition
value.- 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
BaseStamp
instance.- 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:
BaseStamp
Class 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_params
init 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_params
init 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
BaseStamp
instance.- 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:
BaseStamp
Class 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).