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 ...@@ -38,7 +38,6 @@ from AccessControl import ClassSecurityInfo
from AccessControl.SecurityInfo import allow_class from AccessControl.SecurityInfo import allow_class
from zLOG import LOG, PROBLEM, WARNING from zLOG import LOG, PROBLEM, WARNING
import types import types
import popen2 import popen2
import os import os
...@@ -87,7 +86,7 @@ class PDFTk: ...@@ -87,7 +86,7 @@ class PDFTk:
def fillFormWithDict(self, pdfFile, values) : def fillFormWithDict(self, pdfFile, values) :
""" fill the form with values in """ """ 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) : def fillFormWithFDF(self, pdfFile, fdfFile) :
""" fill the form of pdfFile with the FDF data fdfFile """ """ fill the form of pdfFile with the FDF data fdfFile """
...@@ -178,20 +177,32 @@ class PDFTk: ...@@ -178,20 +177,32 @@ class PDFTk:
escaped += c escaped += c
return escaped return escaped
def _createFdf(self, values, pdfFormUrl=None) : def _createFdf(self, pdfFile, values, pdfFormUrl=None) :
""" create an fdf document with the dict values """ """ create an fdf document with the dict values """
fields = self.dumpDataFields(pdfFile)
fdf = "%FDF-1.2\x0d%\xe2\xe3\xcf\xd3\x0d\x0a" fdf = "%FDF-1.2\x0d%\xe2\xe3\xcf\xd3\x0d\x0a"
fdf += "1 0 obj\x0d<< \x0d/FDF << /Fields [ " fdf += "1 0 obj\x0d<< \x0d/FDF << /Fields [ "
for key, value in values.items(): for field in fields:
if 0: # if the field is a check box # if the field is a check box
# ... but this is not working yet if field.get('FieldType') == 'Button' and \
fdf += "<< /V /%s\n/T (%s)>> \x0d" % ( field.get('FieldStateOption') in ('Yes','Off'):
value and 'Yes' or 'Off', # if the check box is check
self._escapeString(key),) 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: else:
fdf += "<</V (%s) /T (%s) /ClrF 2 /ClrFf 1 >> \x0d" % ( fdf += "<</V (%s) /T (%s) /ClrF 2 /ClrFf 1 >> \x0d" % (
self._escapeString(value), self._escapeString(values.get(field.get('FieldName'))),
self._escapeString(key)) self._escapeString(field.get('FieldName')))
fdf += "] \x0d" fdf += "] \x0d"
...@@ -199,7 +210,7 @@ class PDFTk: ...@@ -199,7 +210,7 @@ class PDFTk:
if pdfFormUrl not in ("", None) : if pdfFormUrl not in ("", None) :
fdf += "/F ("+self._escapeString(pdfFormUrl)+") \x0d" 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" fdf += "trailer\x0d<<\x0d/Root 1 0 R \x0d\x0d>>\x0d%%EOF\x0d\x0a"
return fdf return fdf
......
This diff is collapsed.
...@@ -155,6 +155,8 @@ class TestPDFFormButtons(unittest.TestCase): ...@@ -155,6 +155,8 @@ class TestPDFFormButtons(unittest.TestCase):
# XXX for debugging: # XXX for debugging:
# file('/tmp/out.pdf', 'w').write(self.pdf_form()) # file('/tmp/out.pdf', 'w').write(self.pdf_form())
# os.system('xpdf /tmp/out.pdf') # os.system('xpdf /tmp/out.pdf')
# os.system('kpdf /tmp/out.pdf')
# os.system('acroread /tmp/out.pdf')
def test_suite(): 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