Adding an image to a pdf with pdftk

前端 未结 4 2153
走了就别回头了
走了就别回头了 2021-01-31 11:36

Hello I am using pdftk to generate a PDF based on a form that is submitted.

I have everything working fine until here. Which is adding an image of a signature. I am usi

4条回答
  •  误落风尘
    2021-01-31 11:58

    pdfjinja for Python

    https://github.com/rammie/pdfjinja

    This library will allow you to to add images to a signature or button object in your PDF, without the need for merging or vector location information.

    1. Add signature element to your PDF template

    Adobe Pro allows creation and modification of PDF fillable forms. Go to Tools>Forms>Edit, then from the Add New Field dropdown, choose Digital Signature.

    After placement, go to the properties of the Digital Signature element.

    In the Tooltip property, add

    {{ Sig | paste }}
    

    Save and close.

    2. Save your signature image as a jpg or png

    You may need a separate method to retrieve signatures as images, and place in an accessible folder.

    3. Add method to your Python script

    from pdfjinja import PdfJinja
    
    pdf_jinja_object = PdfJinja("path_to_pdf_template")
    
    filled_out_pdf = pdf_jinja_object({
        'firstName': 'John',
        'lastName': 'Smith',
        'sig': 'path_to_signature_image',
    })
    
    filled_out_pdf.write(open("output_file.pdf", 'wb'))
    

    This should give you a form with your signature image placed in the location created in your template.

提交回复
热议问题