Is there a templating system for generating PDFs?

145 views
Skip to first unread message

Ottavio

unread,
Apr 6, 2012, 2:43:31 AM4/6/12
to pylons-...@googlegroups.com
I'm looking for a templating system for generating pdf files from pyramid.

Is there something?

Or, in case it does not exist, where can I find information about implementing a new template system?

Malthe Borch

unread,
Apr 6, 2012, 2:49:50 AM4/6/12
to pylons-...@googlegroups.com
On 6 April 2012 08:43, Ottavio <ott...@campana.vi.it> wrote:
> I'm looking for a templating system for generating pdf files from pyramid.

You can use Chameleon to generate HTML which you'll then give to a PDF
formatter such as the CSS3-capable PrinceXML – that's a commercial
offering though.

An alternative is Apache FOP – that's free, but input is XML, not HTML.

\malthe

Ottavio

unread,
Apr 6, 2012, 3:17:00 AM4/6/12
to pylons-...@googlegroups.com
Il giorno venerdì 6 aprile 2012 08:49:50 UTC+2, malthe ha scritto:
You can use Chameleon to generate HTML which you'll then give to a PDF

formatter such as the CSS3-capable PrinceXML – that's a commercial
offering though.

An alternative is Apache FOP – that's free, but input is XML, not HTML.

\malthe

what I'm thinking about is more ore less wrapping reportlab or some other library in a renderer.

FOP is a java program, I don't have java on my servers...
 

Simon Oram

unread,
Apr 6, 2012, 3:25:13 AM4/6/12
to pylons-...@googlegroups.com
 I use 


with chameleon.

S.



--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/pylons-discuss/-/q7bAbZ6ncS8J.
To post to this group, send email to pylons-...@googlegroups.com.
To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.

Simon Oram
Lead Developer
Electrosoup

t:  07812757571




León Domingo

unread,
Apr 6, 2012, 3:27:58 AM4/6/12
to pylons-...@googlegroups.com
Hi,
I have a solution for this using wkhtmltopdf.

Firstly, render the template, then create a temporaty file, convert it into PDF with wkhtmltopdf, and return the PDF content of the generated file (temporary too) modifying the header list.

...
s = render('myproject:templates/mytemplate.pt',
                   dict(foo=1, bar=2), request=request)
       
# "topdf" gets the template, creates the temporary file, calls "wkhtmltopdf" and returns the pdf content
pdf = topdf(s.encode('utf-8'), page_size='A3', orientation='landscape')
       
response = Response(pdf)
response.content_type = 'application/pdf'
response.headerlist.append(('Content-Disposition', 'attachment;filename=prueba.pdf'))

Regards,
León Domingo

Ender - Factoría de Software
leon.d...@ender.es
Avda. Cerro del Águila, 7. S23 - 2ª Planta
28703 S.S. de los Reyes (MADRID)
Tlf. 902 01 44 01

   


--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.

Ottavio

unread,
Apr 6, 2012, 3:54:35 AM4/6/12
to pylons-...@googlegroups.com


Il giorno venerdì 6 aprile 2012 09:25:13 UTC+2, mr.jo...@googlemail.com ha scritto:

how do you attach it to chameleon?

Simon Oram

unread,
Apr 6, 2012, 4:01:52 AM4/6/12
to pylons-...@googlegroups.com
from cStringIO import StringIO
from pyramid.chameleon_zpt import render_template
from ho import pisa
import mimetypes

def pdf(request):
    buffer = StringIO()
    template = render_template('../templates/invoice.pt')
    template = template.encode('utf-8')
    pisa.CreatePDF(template, buffer)
    type, encoding = mimetypes.guess_type('*.pdf')
    response = Response(content_type=type)
    response.body = buffer.getvalue()
    response.headers.add('Content-Disposition',\
        'attachment; filename=blah.pdf' )
    return response

Ottavio

unread,
Apr 6, 2012, 4:09:14 AM4/6/12
to pylons-...@googlegroups.com
Il giorno venerdì 6 aprile 2012 09:27:58 UTC+2, León Domingo ha scritto:
Hi,
I have a solution for this using wkhtmltopdf.

Firstly, render the template, then create a temporaty file, convert it into PDF with wkhtmltopdf, and return the PDF content of the generated file (temporary too) modifying the header list.

interesting. I'll try to make it work it with cStringIO because I don't like temporary files :-)

Carsten Senger

unread,
Apr 6, 2012, 11:22:06 AM4/6/12
to pylons-...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I worked with z3c.rml a while back without problems. I don't think
there is an integration with pyramid, but it's not difficult to work with.

http://pypi.python.org/pypi/z3c.rml/1.0.0

..Carsten

> -- You received this message because you are subscribed to the
> Google Groups "pylons-discuss" group. To view this discussion on
> the web visit

> https://groups.google.com/d/msg/pylons-discuss/-/0Er7W_cdQ78J. To


> post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discus...@googlegroups.com. For more options,
> visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.

- --
Carsten Senger - Schumannstr. 38 - 65193 Wiesbaden
sen...@rehfisch.de - (0611) 5324176
PGP: gpg --recv-keys --keyserver hkp://subkeys.pgp.net 0xE374C75A
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iQEcBAEBAgAGBQJPfwoeAAoJEAOSv+HjdMdaOywH/AwWnREb6kFJncHhEauFygxc
WgKH3wtRg6imv864JnY1dJOnMVq9bHzHcjWs/2Jtqfvgps6McuLLsfenWJ1kq1PM
TtVrqg3thoBedAh9hxK35MvZtxQvHwbQXBCghDjSBgDwJPEpJlpbpyA10g4QW/2/
M1KhosPF6+C/V0gd7iASRo31ujBWk1Wk6TtTG6eQc45bg/FKpq7jGKLphke3wrd7
DG+FQNzx8OPLSSvEfUzhG0smdcn7j7Cb1oE+U33mW/Bi45et0Cgsjxuf6YCYGn/8
8tAjynSRwV6nOexmghwpAy8gFW7cC6yTxv+fsRDr7+PNNtmWpVCrcNb95yafwgY=
=B/Xg
-----END PGP SIGNATURE-----

Nicola Senno

unread,
Apr 7, 2012, 2:40:04 PM4/7/12
to pylons-...@googlegroups.com
Hi
I just completed a project using both z3c.rml and Chameleon.
I would suggest them for sure.

Nicola

To post to this group, send email to pylons-...@googlegroups.com.

To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.




--
Nicola Senno



Jason

unread,
Apr 9, 2012, 9:09:25 AM4/9/12
to pylons-...@googlegroups.com
I use xhtml2pdf  ( http://www.xhtml2pdf.com/ ) and it works well with simple templates. For more advances layouts I create the PDF imperatively using reportlab, but its much easier to use xhtml2pdf. I'm planning to try using a ReST to PDF converter like whatever is used in Sphinx, but I haven't gotten there yet.

-- Jason

Andreas Jung

unread,
Apr 9, 2012, 11:50:48 PM4/9/12
to pylons-...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You may look into

http://pypi.python.org/pypi/zopyx.convert2/2.4.2.1

which provides a unified API around several PDF converters.

The functionality is also exposed as a web-service through

http://pypi.python.org/pypi/zopyx.smartprintng.server/1.1.1

You use the conversion service from a Python client through

http://pypi.python.org/pypi/zopyx.smartprintng.client/

- - -aj

> -- You received this message because you are subscribed to the
> Google Groups "pylons-discuss" group. To view this discussion on the
> web visit
> https://groups.google.com/d/msg/pylons-discuss/-/0Er7W_cdQ78J. To
> post to this group, send email to pylons-...@googlegroups.com. To
> unsubscribe from this group, send email to
> pylons-discus...@googlegroups.com. For more options, visit
> this group at http://groups.google.com/group/pylons-discuss?hl=en.

- --
ZOPYX Limited | zopyx group
Charlottenstr. 37/1 | The full-service network for Zope & Plone
D-72070 T�bingen | Produce & Publish
www.zopyx.com | www.produce-and-publish.com
- ------------------------------------------------------------------------
E-Publishing, Python, Zope & Plone development, Consulting


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQGUBAEBAgAGBQJPg64YAAoJEADcfz7u4AZj+AELvA117I6QadUv3Uvp886WMsQ+
HGoTkQbi18SuvYRp4POm+UmuQStAE5cfdm5YNbJvsVyXZ22msUXcHxPWk/69viq0
Px8jaF2GIqjyigQgp4oI+EEiPh30PzErkA6hOe9FVgdxnr0bx/76WFHyuFrss4Eh
FmfzlkQkiHkmOIyP9o9FAOATUE1C0GEv3i5fH4N2gi4m5vq+OaaAa4AtOOH1nbjo
bj0QmCoPKyhpAHv3i9vyyijM4AhOmQYrX6noyVCR8QgUaVkSirZzV0dRxWDLvG6o
ZpqyyMA6ORUEyuABfOcqcCidrnTNVsjn6zAzgltp9B5UBgG/wfEPxmoPclHx5HFe
WHE/sHpX8qNXaPa1+d43vOmmktdD2vx34cuWKFGmwKLIwEFGWCN81y+OgbxXmLz+
FpcwjKxctZLdWAxE33uSwEW/giW/2fU4e76f9P9H6y1qH31K9sp9i2wg2kqiigmB
Q6a39vQ2R6gY5KFkB8zr5h1MMuYoiXk=
=y7P/
-----END PGP SIGNATURE-----

lists.vcf
Reply all
Reply to author
Forward
0 new messages