pyhanko.sign.signers.functions module
This module defines pyHanko’s high-level API entry points.
- pyhanko.sign.signers.functions.sign_pdf(pdf_out: BasePdfFileWriter, signature_meta: PdfSignatureMetadata, signer: Signer, timestamper: Optional[TimeStamper] = None, new_field_spec: Optional[SigFieldSpec] = None, existing_fields_only=False, bytes_reserved=None, in_place=False, output=None)
Thin convenience wrapper around
PdfSigner.sign_pdf().- Parameters:
pdf_out – An
IncrementalPdfFileWriter.bytes_reserved – Bytes to reserve for the CMS object in the PDF file. If not specified, make an estimate based on a dummy signature.
signature_meta – The specification of the signature to add.
signer –
Signerobject to use to produce the signature object.timestamper –
TimeStamperobject to use to produce any time stamp tokens that might be required.in_place – Sign the input in-place. If
False, write output to aBytesIOobject.existing_fields_only – If
True, never create a new empty signature field to contain the signature. IfFalse, a new field may be created if no field matchingfield_nameexists.new_field_spec – If a new field is to be created, this parameter allows the caller to specify the field’s properties in the form of a
SigFieldSpec. This parameter is only meaningful ifexisting_fields_onlyisFalse.output – Write the output to the specified output stream. If
None, write to a newBytesIOobject. Default isNone.
- Returns:
The output stream containing the signed output.
- async pyhanko.sign.signers.functions.async_sign_pdf(pdf_out: BasePdfFileWriter, signature_meta: PdfSignatureMetadata, signer: Signer, timestamper: Optional[TimeStamper] = None, new_field_spec: Optional[SigFieldSpec] = None, existing_fields_only=False, bytes_reserved=None, in_place=False, output=None)
Thin convenience wrapper around
PdfSigner.async_sign_pdf().- Parameters:
pdf_out – An
IncrementalPdfFileWriter.bytes_reserved – Bytes to reserve for the CMS object in the PDF file. If not specified, make an estimate based on a dummy signature.
signature_meta – The specification of the signature to add.
signer –
Signerobject to use to produce the signature object.timestamper –
TimeStamperobject to use to produce any time stamp tokens that might be required.in_place – Sign the input in-place. If
False, write output to aBytesIOobject.existing_fields_only – If
True, never create a new empty signature field to contain the signature. IfFalse, a new field may be created if no field matchingfield_nameexists.new_field_spec – If a new field is to be created, this parameter allows the caller to specify the field’s properties in the form of a
SigFieldSpec. This parameter is only meaningful ifexisting_fields_onlyisFalse.output – Write the output to the specified output stream. If
None, write to a newBytesIOobject. Default isNone.
- Returns:
The output stream containing the signed output.
- pyhanko.sign.signers.functions.embed_payload_with_cms(pdf_writer: BasePdfFileWriter, file_spec_string: str, payload: EmbeddedFileObject, cms_obj: ContentInfo, extension='.sig', file_name: Optional[str] = None, file_spec_kwargs=None, cms_file_spec_kwargs=None)
Embed some data as an embedded file stream into a PDF, and associate it with a CMS object.
The resulting CMS object will also be turned into an embedded file, and associated with the original payload through a related file relationship.
This can be used to bundle (non-PDF) detached signatures with PDF attachments, for example.
New in version 0.7.0.
- Parameters:
pdf_writer – The PDF writer to use.
file_spec_string – See
file_spec_stringinFileSpec.payload – Payload object.
cms_obj – CMS object pertaining to the payload.
extension – File extension to use for the CMS attachment.
file_spec_kwargs – Extra arguments to pass to the
FileSpecconstructor for the main attachment specification.cms_file_spec_kwargs – Extra arguments to pass to the
FileSpecconstructor for the CMS attachment specification.