I am trying to create a signature box on the first page of the PDF file. I am getting the following error.
Any help would be appreciated.
I use Python version 3.11.
pdfrw.PdfWriter().write(pdf_file, pdf_file.getobject(), signature_box)
^^^^^^^^^^^^^^^^^^
AttributeError: ‘_io.BufferedReader’ object has no attribute ‘getobject’
My code is
import sys
import os
import pdfrw
import pdfkit
Load the PDF file.
pdf_file = open(“document.pdf”, “rb”)
Create a signature box on the first page of the PDF file.
signature_box = pdfrw.PdfDict(Rect = [100, 100, 200, 200], AP=pdfrw.PdfArray([pdfrw.PdfName(“Sig”)]) )
signature_box[“/Rect”] = [100, 100, 200, 200]
signature_box[“/AP”] = pdfrw.PdfArray([pdfrw.PdfName(“Sig”)])
Add the signature box to the first page of the PDF file.
print ("signature_box = ", signature_box )
pdf_file.seek(0)
pdfrw.PdfWriter().write(pdf_file, pdf_file.getobject(), signature_box)
pdf_file.close()
Create a HTML file that will serve the PDF file as a template.
html_file = open(“index.html”, “w”)
html_file.write(“\n”)
html_file.write(“\n”)
html_file.write(“PDF Signature\n”)
html_file.write(“\n”)
html_file.write(“\n”)
html_file.write(“
PDF Signature
\n”)html_file.write(“<iframe src="document.pdf" width="100%" height="100%">\n”)
html_file.write(“\n”)
html_file.write(“\n”)
Save the HTML file.
html_file.close()
Serve the HTML file on a webpage.
pdfkit.from_file(“index.html”, “index.pdf”)