1
#!/usr/local/bin/python
2
# -*- coding: ISO-8859-1 -*-
3
#############################################
4
## (C)opyright by Dirk Holtwick, 2008 ##
5
## All rights reserved ##
6
#############################################
9
import sx.pisa3 as pisa
10
import cStringIO as StringIO
17
class PDFDemo(object):
20
Simple demo showing a form where you can enter some HTML code.
21
After sending PISA is used to convert HTML to PDF and publish
28
return file("demo-cherrypy.html","r").read()
32
Please enter some HTML code:
33
<form action="download" method="post" enctype="multipart/form-data">
34
<textarea name="data">Hello <strong>World</strong></textarea>
36
<input type="submit" value="Convert HTML to PDF" />
42
def download(self, data):
45
data = """<?xml version="1.0" encoding="utf-8"?>
46
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
47
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
48
<html xmlns="http://www.w3.org/1999/xhtml"
49
xmlns:py="http://purl.org/kid/ns#">
51
<title>PDF Demo</title>
55
test = kid.Template(source=data)
56
data = test.serialize(output='xhtml')
58
result = StringIO.StringIO()
60
StringIO.StringIO(data),
64
return "We had some errors in HTML"
66
cp.response.headers["content-type"] = "application/pdf"
67
return result.getvalue()
69
cp.tree.mount(PDFDemo())
71
if __name__ == '__main__':
73
cp.config.update(os.path.join(__file__.replace(".py", ".conf")))
74
cp.server.quickstart()