Skip to main content

Sign PDFs using a signature image

Project description

signpdf2

  • This package is used to insert a signature image (png) into a pdf at a specified location using python.

  • We use units instead of pixel. Units are pdf-standard units (1/72 inch).

  • You may have your input files stored on your system or on cloud with a GET url to them.

    • Following example shows how you can insert a signature in a pdf (stored locally or available through a GET url)
    • Then save the signed pdf locally or make a PUT request to a PUT url
  • Works for python 3.12

  • pdf_utilities.py files is not used anywhere in this package. It's just provided as an accessory.

Github

https://github.com/aseem-hegshetye/signpdf

Installation

Install with pip:

pip install signpdf2

Example

"""
:param sign_w: signature width in units
:param sign_h: signature height in units
:param pdf_file:  name and path of pdf file on local system
:param signature_file: name and path of signature image file
:param page_num: page number of pdf to sign. Index starts at 0
:param offset_x: offset units horizontally from left
:param offset_y: offset units vertically from bottom
:param signature_expand: Original page dimension is expanded to
    accomodate signature if signature dimensions are more than original
:param signature_over: Signature is over or under the original pdf
:param sign_timestamp: Bool. If true, then add current timestamp below
    signature
"""
from file_utilities import GetFileFromUrl, WritePdfToDisk, WritePdfToUrl
from sign_pdf import SignPdf


class SigningExample:
    @classmethod
    def sign_using_urls(cls):
        put_url = 'xyz/xyz'
        pdfurl = 'https:/xyz.pdf'
        sign_url = 'https://xyz.png'
        output_file_name = 'signed_pdf.pdf'

        pdf_file_name = GetFileFromUrl().get_file_from_url(pdfurl)
        signature_file_name = GetFileFromUrl().get_file_from_url(sign_url)

        sign_pdf = SignPdf(
            sign_w=100,
            sign_h=60,
            page_num=0,
            offset_x=400,
            offset_y=200,
            pdf_file=pdf_file_name,
            signature_file=signature_file_name
        )
        pdf_writer = sign_pdf.sign_pdf()
        WritePdfToUrl().write_pdf_to_url(pdf_writer, put_url)
        WritePdfToDisk().write_pdf_to_disk(pdf_writer, output_file_name)

    @classmethod
    def sign_using_local_files(
            cls,
            pdf_file_name: str,
            signature_file_name: str,
            signature_expand: bool = False,
            signature_over: bool = True
    ):
        """
        Sign without any urls
        """
        output_file_name = 'signed_pdf.pdf'
        sign_pdf = SignPdf(
            sign_w=100,
            sign_h=60,
            page_num=0,
            offset_x=54,  # margin from left side
            offset_y=237,  # margin from bottom
            pdf_file=pdf_file_name,
            signature_file=signature_file_name,
            signature_expand=signature_expand,
            signature_over=signature_over,
            sign_timestamp=True
        )
        pdf_writer = sign_pdf.sign_pdf()
        WritePdfToDisk().write_pdf_to_disk(pdf_writer, output_file_name)


if __name__ == '__main__':
    pdf_file_name = 'file1.pdf'
    signature_file_name = 'sample_signature.png'
    SigningExample.sign_using_local_files(
        pdf_file_name=pdf_file_name,
        signature_file_name=signature_file_name,
        signature_expand=False,
        signature_over=False

    )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

signpdf2-7.0.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

signpdf2-7.0.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file signpdf2-7.0.0.tar.gz.

File metadata

  • Download URL: signpdf2-7.0.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for signpdf2-7.0.0.tar.gz
Algorithm Hash digest
SHA256 9e44ff178c1dfb416dda400d5041f9dfd8013102faa520a38c1aa0e81acd5459
MD5 f07c8ce8fb1ba79ae61ae8a642a757f5
BLAKE2b-256 26d06077afa43a3c4bff80d828abe515ee312eaba7c91c45a0175917f7561244

See more details on using hashes here.

File details

Details for the file signpdf2-7.0.0-py3-none-any.whl.

File metadata

  • Download URL: signpdf2-7.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for signpdf2-7.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a8e267e1b7ef01a78a2d06c9151b674729a82b76dd3f26bf6ffd658ac9d59fff
MD5 675c0e34aaedb921783a2e69e0f80840
BLAKE2b-256 972b0c8dfc588e04241ddfb0c3b1e960732041b40d5b051e72059ff1fc8ef925

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page