[reportlab-users] Problem with pdfform (textField)

Arnaud Fontaine arnaud at andesi.org
Fri Jan 22 05:57:31 EST 2010


Hello,

I'm trying to generate a PDF document containing Tables where some cells
are PDF form (textField only). Here is the code (based on some code from
xhtml2pdf project):

from reportlab.platypus import Table, SimpleDocTemplate, Flowable
from reportlab.pdfbase import pdfform

class PDFFormTextField(Flowable):
def __init__(self, name, width=10, height=10):
self.name = name
self.width = width
self.height = height

def wrap(self, *args):
return (self.width, self.height)

def draw(self):
self.canv.saveState()

pdfform.textFieldRelative(self.canv, self.name, 0, 0, self.width,
self.height, value='foo')
self.canv.restoreState()

doc = SimpleDocTemplate("test2.pdf")
t = Table([['col1', PDFFormTextField('123333')]])
doc.build([t])

However, this code produces an invalid document with the form object
itself instead of the generated form:

% 'Annot.NUMBER1': class PDFPattern
4 0 obj
<reportlab.pdfbase.pdfpattern.PDFPattern instance at 0x85c040c>
[...]
% 'R6': class PDFCatalog
6 0 obj
% Document Root
<< /AcroForm <reportlab.pdfbase.pdfform.AcroForm instance at 0x85c030c>

On a given element, format() function (pdfbase/pdfdoc.py) calls the
format() method of the element only if element object has an attribute
__PDFObject__. However, this is not the case for PDFPattern and Acroform
classes. I have attached to this email a short patch which works fine for
me. Hope that's ok.

Regards,
Arnaud Fontaine
-------------- next part --------------
A non-text attachment was scrubbed...
Name: reportlab_pdfform_not_generated.patch
Type: application/octet-stream
Size: 721 bytes
Desc: not available
Url : <http://two.pairlist.net/pipermail/reportlab-users/attachments/20100122/234c28db/attachment.obj>


More information about the reportlab-users mailing list