Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a better layout language than HTML for printing? [closed]

I'm using Python and Qt 4.4 and I have to print some pages. Initially I thought I'd use HTML with CSS to produce those pages. But HTML has some limitations.

Now the question is: is there anything that's better than HTML but just (or almost) as easy to use? Additionally, it should be GPL-compatible.

Edit:

kdgregory & Mark G: The most obvious limitation is that I can't specify the printer margins. There is another problem: How do I add page numbers?

Jeremy French: One thing I have to print is a list of all the products someone ordered which can spread over a few pages.

like image 615
Georg Schölly Avatar asked Jan 19 '09 17:01

Georg Schölly


People also ask

How do I print a Web page to make it appear on the screen?

Open the web page. 2. Click on File – Print preview 3. Change the drop-down selection from “As Laid Out on Screen” to Only the Selected Frame” (this will not show the headers and footers upon printing).

How do I print an entire HTML page?

window. print() WILL print the whole page.

How do you print using JavaScript?

JavaScript does not have any print object or print methods. You cannot access output devices from JavaScript. The only exception is that you can call the window.print() method in the browser to print the content of the current window.


2 Answers

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.

like image 177
max Avatar answered Oct 12 '22 07:10

max


There's LaTeX. Not sure if that falls into the "as easy to use as html" category, but it's not hard.

like image 40
U62 Avatar answered Oct 12 '22 07:10

U62