From bdb3ea78f0c73f3f635d858a6a4720c95427439d Mon Sep 17 00:00:00 2001 From: Ian Delaney Date: Mon, 4 Jun 2012 17:23:35 +0800 Subject: [dev-python/cookbook] Add HTML2PDF and matching epatch line (Portage version: 2.1.10.63/git/Linux x86_64, unsigned Manifest commit) --- dev-python/cookbook/cookbook-2.2.9.ebuild | 4 +++ dev-python/cookbook/files/HTML2PDF | 52 +++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 dev-python/cookbook/files/HTML2PDF (limited to 'dev-python') diff --git a/dev-python/cookbook/cookbook-2.2.9.ebuild b/dev-python/cookbook/cookbook-2.2.9.ebuild index cfe7551..1f7b6f9 100644 --- a/dev-python/cookbook/cookbook-2.2.9.ebuild +++ b/dev-python/cookbook/cookbook-2.2.9.ebuild @@ -25,6 +25,10 @@ DEPEND="${RDEPEND} dev-python/pytables sci-libs/scipy )" +src_prepare() { + cp -R "${FILESDIR}"/HTML2PDF python/${PN}/HTML2PDF.py || die +} + src_compile() { distutils_src_compile diff --git a/dev-python/cookbook/files/HTML2PDF b/dev-python/cookbook/files/HTML2PDF new file mode 100644 index 0000000..449cbed --- /dev/null +++ b/dev-python/cookbook/files/HTML2PDF @@ -0,0 +1,52 @@ +## {{{ http://code.activestate.com/recipes/572160/ (r1) +import cStringIO +import ho.pisa as pisa +import os + +# Shortcut for dumping all logs on screen +pisa.showLogging() + +def HTML2PDF(data, filename, open=False): + + """ + Simple test showing how to create a PDF file from + PML Source String. Also shows errors and tries to start + the resulting PDF + """ + + pdf = pisa.CreatePDF( + cStringIO.StringIO(data), + file(filename, "wb")) + + if open and (not pdf.err): + os.startfile(str(filename)) + + return not pdf.err + +if __name__=="__main__": + HTMLTEST = """ + +

Hello World +


+ + + + + + + + + + + + + + + +
AmountDescriptionTotal
1Good weather0 EUR
Sum0 EUR
+ + """ + + HTML2PDF(HTMLTEST, "test.pdf", open=True) +## end of http://code.activestate.com/recipes/572160/ }}} + -- cgit v1.2.3-65-gdbad