How to create a PDF-Document on the fly?
Created by .
Last modified on 2003/08/05.
How to create a PDF-Document on the fly?
Please report comments and bug-reports to: [email protected]
- Please note: This script works only for pages where
anyonmous has the right to view...
- Download and install 'htmldoc' from
"http://www.easysw.com/htmldoc/":http://www.easysw.com/htmldoc/
- Copy the following script as "html2pdf.py" to
your Zope-Installation-Path/Extensions::
# HTML2PDF - converts HTML to PDF
# Needs 'htmldoc' from Easy Software Products
# Send comments to [email protected]
import AccessControl, cgi, os
def html2pdf(self):
""" html2pdf converts a HTML-Page to a PDF-Document """
securityContext=AccessControl.getSecurityManager()
if securityContext.checkPermission('View', self):
QUERY_STRING = ''
for (key,value) in self.REQUEST.form.items():
if QUERY_STRING:
QUERY_STRING=QUERY_STRING + '&'
QUERY_STRING = QUERY_STRING + "%s=%s" % (key, cgi.escape(value))
URL = self.absolute_url()
if QUERY_STRING:
URL = URL + "?" + QUERY_STRING
(stin,stout) = os.popen2('htmldoc --footer " : " --webpage -t pdf --quiet --jpeg "%s"' % URL)
stin.close()
pdf = stout.read()
stout.close()
self.REQUEST.RESPONSE.setHeader('Content-type','application/pdf')
self.REQUEST.RESPONSE.setHeader('Content-disposition','inline; filename="%s.pdf"' % (self.getId()))
return pdf
else:
raise AccessControl.Unauthorized
- Add an External Method to your Root-Folder with
'Id / Module Name / Function Name = html2pdf'
- To create a PDF-Document on the fly, add '/html2pdf' to a ZOPE-URL. That's all!
|