Is There A Better Layout Language Than Html For Printing?
Solution 1:
I have been fighting with printed (or PDF) output from Python for 8 years now and so far I came across the following approaches (in order of personal preference):
- Using JasperReports via pyJasper (written by me) or JasperServer. You can use the WYSIWYG design tool iReport to define your layout. Your Python code will contact the Java based Jasper engine via HTTP and make it render a PDF (pyJasper handles that). We use that for a few thousand pages a day.
- Use plain text output. You can't get any faster. We use that for a few hundred pages per day.
- Use XSLT-FO. You also have to call a Java based rendering engine like FOB. Might result in performance issues but can be mitigated by having a long running Java server process - same approach than with Jasper. We use that for a few hundred pages per day but writing XSLT-FO documents made my head hurt. Not used for new code.
- Generate LaTeX source and use a latex software package to render to PDF. Getting LaTeX to look like you like is quite difficult. But as long as you go with the provided LaTeX styles, you are fine. Not used in production at my shop.
- PDF generation with the ReportLab Toolkit. Somewhat low level. Even more low level: FPDF. We use FPDF-Ruby for a few hundred pages a day. Took a lot of fiddeling to get the layout we wanted.
- Directly generate Postscript. Strange but you nearly can't get more in terms of speed and control. We used that to generate contact sheets with a few hundred thousand Jpegs per day. Takes fiddling but is fun.
- use troff/groff to generate Postscript/PDF. Very low level bute nice to do simple, high volume things. Never used it thus in production.
For orders, invoices and the like I highly recommend JasperReports. The ability to use a visual editor to define the layout is a huge time saver.
Solution 2:
There's LaTeX. Not sure if that falls into the "as easy to use as html" category, but it's not hard.
Solution 3:
By print do you mean a printer? If so, check ReportLab's PDF tools.
from reportlab.pdfgenimport canvas
from reportlab.lib.unitsimport cm
c = canvas.Canvas("hello.pdf")
c.drawString(9*cm, 22*cm, "Hello World!")
c.showPage()
c.save()
Solution 4:
You might consider Sphinx, a package that translates reStructuredText files into various output formats, including HTML, and LaTeX, for printable PDF. It's licensed under BSD and is now the official Python documentation tool.
Solution 5:
Have you seen http://www.w3.org/TR/css3-page/ ? The print media is highly customizable. In my new project I'm going to replace PDF generator by this one.
Post a Comment for "Is There A Better Layout Language Than Html For Printing?"