Skip to content

Instantly share code, notes, and snippets.

Created October 15, 2014 07:14
Show Gist options
  • Save anonymous/47debcdf06de30f1b7e7 to your computer and use it in GitHub Desktop.
Save anonymous/47debcdf06de30f1b7e7 to your computer and use it in GitHub Desktop.
Pasted from IPython
xhtml = "<h1 align='center'>Test print</h1>\n"
xhtml += "<h2>This is printed from within a Python application</h2>\n"
xhtml += "<p style=\"color:red;\">Coloured red using css</p>\n"
xhtml
from xhtml2pdf import pisa
ls
filename = "simplePrint.pdf"
pdf = pisa.CreatePDF(xhtml, file(filename, "w"))
ls
pdf = pisa.CreatePDF(xhtml.encode('utf-8, file(filename, "w"))
pdf = pisa.CreatePDF(xhtml.encode('utf-8'), file(filename, "w"))
from StringIO import StringIO
output = StringIO()
pdf = pisa.CreatePDF(xhtml.encode('utf-8'), output)
output.getvalue()
%pastebin 1-16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment