2

I have a fillable PDF and I have filled out some of the fields and saved it.

I am able to add an image to the PDF using pdfrw and ReportLab; however, when the PDF is saved, the data entered into the fillable fields has disappeared.

Can anyone point me in the right direction so that I can add an image to a PDF while still maintaining the filled fields?

Here is the reproducible code:

An example PDF is here

from PIL import Image
from reportlab.pdfgen.canvas import Canvas
from pdfrw import PdfReader
from pdfrw.buildxobj import pagexobj
from pdfrw.toreportlab import makerl

inpfn = 'input.pdf'
outfn = 'output.pdf'

pages = PdfReader(inpfn).pages
page=pagexobj(pages[0])
canvas = Canvas(outfn)

canvas.doForm(makerl(canvas, page))
im = Image.open("photo.jpg")
canvas.drawInlineImage(im, 20, 175, width=100, height=60)
canvas.save()

Here is the output PDF. As you can see the image is there, but the fields are all empty.

Here is the output PDF

I can verify that the data from the fields is present when the PDF is initially read by inspecting the structure of the PDF with:

for p in page:
   for a in p['/Annots']:
     print(a['/V'])

This prints out a bunch of data (with weird characters) but I can indeed see data that was entered into the form (e.g., "trade_name")

campo
  • 624
  • 5
  • 15

0 Answers0