Question

One of our page templates is made up of a bunch of macros. These items are a bunch of html tables.

Now, I want a couple of these tables in a Python script to create a PDF. Is there a way call a macro from a Python script and get back the HTML that is produced?

If so, can you explain?

Thanks Eric

Was it helpful?

Solution

Maybe you could create a new template including (use-macro) just the macros you want to access from python and then use z3c.pt.pagetemplate.PageTemplateFile() to render it?

Actually, it might be possible (and certainly easier) to use chameleon.zpt.template.PageTemplate('<div tal:use-macro="<your-macro-here>" />'), but I've never did this myself.

OTHER TIPS

I'd probably use urllib.urlopen(url), pull the data from the page back to python and use BeautifulSoup to pull the table(s) out of the HTML... And then render that to PDF with XHTML2PDF (pisa.ho).

There might be a simpler way but for me, this would be the least stressful approach.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top