Printing: Difference between revisions
Line 3: | Line 3: | ||
To achieve this goal, we had to write our own HTML printer, which sounds strange at first, but there seems to be no other option to print HTML with .net System.Drawing. | To achieve this goal, we had to write our own HTML printer, which sounds strange at first, but there seems to be no other option to print HTML with .net System.Drawing. | ||
Update: we are now using [https://wkhtmltopdf.org/ wkhtmltopdf]! | |||
== Testing project == | == Testing project == |
Revision as of 04:49, 27 Ocak 2022
Printing from HTML template
The idea is that form letters and other reports should be easily adjustable.
To achieve this goal, we had to write our own HTML printer, which sounds strange at first, but there seems to be no other option to print HTML with .net System.Drawing.
Update: we are now using wkhtmltopdf!
Testing project
Please see the testing project Tests.Common.Printing in solution Testing.sln; this project comes with a sample HTML file, and an editor for the HTML file, and the preview screen for the print result, with comparison to display in an HTML browser.
Another way for testing is with the PDFCreator (it saves a lot of paper...). But be careful: sometimes a real printer requires a wider margin. One other hint: sometimes PDFCreator behaves weird after a long sequence of testing; after you print, the job disappears from the printing queue, without asking you where to save the PDF. The solution that works for me is to stop the PDFCreator.exe task in task manager. Beware: all the disappeared jobs will end up in your PDFCreator printing queue again...
Features
Obviously, not all features of HTML could be implemented.
Generally, we limit ourselves to XHTML, which makes it easier to parse the document.
We support:
- tables: table, th, tr, td, tbody, colgroup, col width.
- Tables are automatically split across pages, and the line with th elements is repeated each time.
- td: align with values right or left or center
- td: nowrap="nowrap" avoids wrapping of lines
- special div with class PageHeader: this is repeated for each page
- #PAGENR and #PAGETOTAL in the HTML text will be replaced automatically with appropriate numbers
- font size: change the relative size
- b: bold text
- page margins:
- currently only supported: <body style="margin-left:0px, margin-right:0px"
- without this, a default margin for normal letters is used (approx 2cm margin?)