0

I am trying to create a signature box on the first page of the PDF file. I am getting the following error.

pdfrw.PdfWriter().write(pdf_file, pdf_file.getobject(), signature_box) ^^^^^^^^^^^^^^^^^^ AttributeError: '_io.BufferedReader' object has no attribute 'getobject'

Any help would be appreciated. I use Python version 3.11.

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")]) )


# 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("<html>\n")
html_file.write("<head>\n")
html_file.write("<title>PDF Signature</title>\n")
html_file.write("</head>\n")
html_file.write("<body>\n")
html_file.write("<h1>PDF Signature</h1>\n")
html_file.write("<iframe src=\"document.pdf\" width=\"100%\" height=\"100%\"></iframe>\n")
html_file.write("</body>\n")
html_file.write("</html>\n")

# Save the HTML file.
html_file.close()
# Serve the HTML file on a webpage.
pdfkit.from_file("index.html", "index.pdf")  
Sapar
  • 1
  • 1

0 Answers0