Quantcast
Viewing all articles
Browse latest Browse all 3535

Dylan Jay: PDF generation in a BrowserView using a single thread

Pisa is a very handy library which turns html and css into pdfs. It's easy enough to use inside Plone but there is a common gotcha. Images and css need to be fetched and Pisa will make additional http requests to the same zope instance. If you deployed Zope with a single thread (which is common) your pdf generation will fail with a "could not connect" error.
There is an under-documented feature of pisa that lets you get around this limitation. 'link_callback' allow you to define a function to return a path or another uri to the linked resource. However not all resources have paths, for example merge css. This can be solved by using plone.subrequest and converting the results to 'data:' style uris. Here is the final pdf BrowserView code.

 

 

Permalink | Leave a comment  »


Viewing all articles
Browse latest Browse all 3535

Trending Articles