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 –
Signer
object to use to produce the signature object.timestamper –
TimeStamper
object to use to produce any time stamp tokens that might be required.in_place – Sign the input in-place. If
False
, write output to aBytesIO
object.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_name
exists.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_only
isFalse
.output – Write the output to the specified output stream. If
None
, write to a newBytesIO
object. 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 –
Signer
object to use to produce the signature object.timestamper –
TimeStamper
object to use to produce any time stamp tokens that might be required.in_place – Sign the input in-place. If
False
, write output to aBytesIO
object.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_name
exists.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_only
isFalse
.output – Write the output to the specified output stream. If
None
, write to a newBytesIO
object. 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_string
inFileSpec
.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
FileSpec
constructor for the main attachment specification.cms_file_spec_kwargs – Extra arguments to pass to the
FileSpec
constructor for the CMS attachment specification.