Commit 326acf88 authored by Jérome Perrin's avatar Jérome Perrin

Initial support of checkboxs in PDFForms. The fields are retrieved correctly

but the rendering is still not functionnal (it might be due to a bug in the
scribus version I use)



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17294 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 946a8546
......@@ -178,9 +178,15 @@ class PDFTk:
fdf = "%FDF-1.2\x0d%\xe2\xe3\xcf\xd3\x0d\x0a"
fdf += "1 0 obj\x0d<< \x0d/FDF << /Fields [ "
for key, value in values.items():
fdf += "<< /T (%s) /V (%s) /ClrF 2 /ClrFf 1 >> \x0d" % (
self._escapeString(key),
self._escapeString(value))
if 0: # if the field is a check box
# ... but this is not working yet
fdf += "<< /V /%s\n/T (%s)>> \x0d" % (
value and 'Yes' or 'Off',
self._escapeString(key),)
else:
fdf += "<</V (%s) /T (%s) /ClrF 2 /ClrFf 1 >> \x0d" % (
self._escapeString(value),
self._escapeString(key))
fdf += "] \x0d"
......@@ -319,7 +325,8 @@ class PDFForm(File):
values = self.pdftk.dumpDataFields(file)
self.cells = {}
for v in values :
if v["FieldType"] != "Button" :
if v["FieldType"] not in ("Button", "Choice")\
or not int(v["FieldFlags"]) & 65536:
k = v["FieldName"]
if not self.all_cells.has_key(k) :
self.cells[k] = ""
......
This diff is collapsed.
......@@ -128,7 +128,37 @@ class TestPDFForm(unittest.TestCase):
self.assertEquals('Value', calculated_values['text_1'])
class TestPDFFormButtons(unittest.TestCase):
"""Tests PDF Form with buttons
"""
def setUp(self):
"""Creates a PDFForm with buttons, and a document on which the PDF form is
rendered.
"""
self.document = Document('doc_id')
pdf_file = open(os.path.join(os.path.dirname(__file__),
'data', 'test_button.pdf'), 'rb')
self.pdf_form = PDFForm('test_pdf_form').__of__(self.document)
self.pdf_form.manage_upload(pdf_file)
def test_getCellNames(self):
self.assertEquals(['check_box',],
self.pdf_form.getCellNames())
def test_SimpleGeneratePDF(self):
self.pdf_form.setCellTALES('check_box', 'python: 1')
self.failUnless(self.pdf_form.generatePDF())
# aliases
self.failUnless(self.pdf_form.index_html())
self.failUnless(self.pdf_form())
# XXX for debugging:
# file('/tmp/out.pdf', 'w').write(self.pdf_form())
# os.system('xpdf /tmp/out.pdf')
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestPDFForm))
suite.addTest(unittest.makeSuite(TestPDFFormButtons))
return suite
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment