Commit 7380b5d7 authored by Thibaut Deheunynck's avatar Thibaut Deheunynck

add a render PDF for checkBoxField

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21715 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a72a2ebc
......@@ -38,7 +38,6 @@ from AccessControl import ClassSecurityInfo
from AccessControl.SecurityInfo import allow_class
from zLOG import LOG, PROBLEM, WARNING
import types
import popen2
import os
......@@ -87,7 +86,7 @@ class PDFTk:
def fillFormWithDict(self, pdfFile, values) :
""" fill the form with values in """
return self.fillFormWithFDF(pdfFile, self._createFdf(values))
return self.fillFormWithFDF(pdfFile, self._createFdf(pdfFile, values))
def fillFormWithFDF(self, pdfFile, fdfFile) :
""" fill the form of pdfFile with the FDF data fdfFile """
......@@ -178,20 +177,32 @@ class PDFTk:
escaped += c
return escaped
def _createFdf(self, values, pdfFormUrl=None) :
def _createFdf(self, pdfFile, values, pdfFormUrl=None) :
""" create an fdf document with the dict values """
fields = self.dumpDataFields(pdfFile)
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():
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),)
for field in fields:
# if the field is a check box
if field.get('FieldType') == 'Button' and \
field.get('FieldStateOption') in ('Yes','Off'):
# if the check box is check
fdf += "<< /Ft /%s\n/V /%s\n/T(%s)>> \x0d" % (
'Btn',
values.get(field.get('FieldName')) and 'Yes' or 'Off',
self._escapeString(field.get('FieldName')))
# if the field is a Input Button
# ... but this is not working yet
# so there is a Warning
elif field.get('FieldType') == 'Button' and \
field.get('FieldStateOption') is None:
LOG("Field " + field.get('FieldName'),
WARNING,
"can't be returned in PDF file")
else:
fdf += "<</V (%s) /T (%s) /ClrF 2 /ClrFf 1 >> \x0d" % (
self._escapeString(value),
self._escapeString(key))
self._escapeString(values.get(field.get('FieldName'))),
self._escapeString(field.get('FieldName')))
fdf += "] \x0d"
......@@ -199,7 +210,7 @@ class PDFTk:
if pdfFormUrl not in ("", None) :
fdf += "/F ("+self._escapeString(pdfFormUrl)+") \x0d"
fdf += ">> \x0d>> \x0dendobj\x0d";
fdf += ">> \x0d>> \x0dendobj\x0d"
fdf += "trailer\x0d<<\x0d/Root 1 0 R \x0d\x0d>>\x0d%%EOF\x0d\x0a"
return fdf
......
This diff is collapsed.
......@@ -155,6 +155,8 @@ class TestPDFFormButtons(unittest.TestCase):
# XXX for debugging:
# file('/tmp/out.pdf', 'w').write(self.pdf_form())
# os.system('xpdf /tmp/out.pdf')
# os.system('kpdf /tmp/out.pdf')
# os.system('acroread /tmp/out.pdf')
def test_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