The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Precise Printing from a browser

I am trying to create HTML that will print in a sane layout on a standard sized piece of paper. I am using CSS and divs. Inches (in) don't seem to correspond to anything real, nor do pixels (px), and the results vary from browser to browser. Surely there is a way to do this? Like if I want to have 1 inch margins and format something to print with that from an html page in a browser.
Art Wilkins
Friday, May 12, 2006
 
 
No, and worse still is the word wrap issue which can cause it be be wider that your page if for example you have a long URL or something in the text.
onanon
Friday, May 12, 2006
 
 
I'm no web design expert, but this is probably a lot harder than you'd think - HTML is a markup language, not a layout language, despite people's best efforts to turn it into one.

No matter how beautifully-formatted your page is on-screen, when you print, you'll be at the mercy of the printing code of whatever browser someone uses to visit your site.

If I ever needed to do this, I'd be tempted to just generate a PDF with the fancy formatting, and link to that as the "printable" version.
Mark Bessey Send private email
Friday, May 12, 2006
 
 
And don't forget about the problem of PAGE BREAKS.

+1 for the idea of just using PDFs. PDFs were made for printing. HTML was made for screen layout.
Mr. Analogy {Shrinkwrap µISV since 1995} Send private email
Friday, May 12, 2006
 
 
Is there a version of pdf that is not overtly complex to generate as text? Is pdf an open standard then? I am not sure.

CSS2 has a page break command, so that's there, but actually I don't need page breaks.

What I want to do is generate stuff like invoices, with a bit of formatting like tables and logos, from the command line. I can do this in ways that are complex, but if I could just write HTML and print it it would seem to be the most straightforward since it can all be automated, and run remotely, or late at night in batchs, etc.

So far my attempts using the CSS sizing directives like inches and centimeters and margins and all that don't work right. I think because the browsers will shrink to fit in ways that are not consistent and don't make sense. Also, they will add additional margins for printing and reflow with that, and there doesn't seem to be any control over it, it all happens in a sort of hidden way.
Art Wilkins
Friday, May 12, 2006
 
 
OK, I found the PDF reference here:

http://partners.adobe.com/public/developer/pdf/index_reference.html

Will look at that.
Art Wilkins
Friday, May 12, 2006
 
 
OK, pdf is a waste of time. It's format is absurdly complex and the example pdf files in text, such as 'hello world', that are given in the text, won't even view in any pdf viewer, so the specification given isn't even correct.

Still hoping for info about html, but that's probably a lost cause. Apparently CSS3 has extended printing functions but none of my browsers seem to support them.
Art Wilkins
Friday, May 12, 2006
 
 
Why not look at a professional site that supports a "printer friendly version" of the page and see how they do it?
anon
Saturday, May 13, 2006
 
 
That was my first thought, but I didn't find any sites with both embedded tables and specified margins.
Art Wilkins
Saturday, May 13, 2006
 
 
Sounds like LaTeX will do what you want. It uses markup like HTML, but it's much more powerful and it's designed for typesetting. You can create .tex files by any means you want, and then compile the document to .pdf with I think it's pdftex.exe.

If you're using Windows, here's a pretty good distribution with its own package manager: http://www.miktex.org/
DHofmann Send private email
Saturday, May 13, 2006
 
 
I was starting to woder about that. OK I am downloading the enormous distribution.
Art Wilkins
Saturday, May 13, 2006
 
 
For those interested in the topic, this is the best of the few dozen pages I read on the subject of css printing:

http://css-discuss.incutio.com/?page=PrintStylesheets
Art Wilkins
Saturday, May 13, 2006
 
 
LaTeX is not a page layout language, it's a typesetting package designed for writing mathematical papers.  Unless your website consists of mathematical papers, you are rather unlikely to find LaTeX does what you want.  Even switching the font away from the ugly default is difficult, and things like adding graphics require guru-level skills.
Iago
Saturday, May 13, 2006
 
 
On the subject of CSS for print Eric Meyer is without a doubt the expert. I see that you have already found some of his stuff. Here is an other article by him:

http://www.alistapart.com/articles/alaprintstyles/

Best wishes by the way. Browser vendors neglect the printing part, so you'll have a lot of fighting before you. In other words: You're bleeding edge ;)
Peter Monsson Send private email
Saturday, May 13, 2006
 
 
For those that follow, what I am finding is that you should ignore measurements in inches and such. The trick is to select a specific browser, and determine the actual margins when printed & what percentage of the paper that is at. Then, compensate for the margins you really want relative to the known ones. Generate the whole page inside a giant div using *percentage* based margins. And then hope for the best, there is still lots of tweaking involved.
Art Wilkins
Saturday, May 13, 2006
 
 
Art,

I wouldn't start with the PDF reference as your guide. It's very complex to get going with. Better to use something like one of the .net/java/php/whatever libraries that people have already built.
Tim Almond Send private email
Saturday, May 13, 2006
 
 
PDF is certainly the way to go for the best consistancy and not having to worry about browser support.  You don't work directly in PDF though.  There are libraries for most languages for generating PDFs.  There are also standalond tools that convert text to PDF.  I haven't used any but one that I've heard mentioned alot is txt2pdf:
http://www.sanface.com/txt2pdf.html

There are also some converters from HTML to PDF. Two that I found very quickly are:
HTMLDOC: http://www.easysw.com/htmldoc/
html2pdf: http://www.tufat.com/script19.htm

For help in finding tools and libraries search Freshmeat:
http://freshmeat.net/
http://www.sanface.com/txt2pdf.html Send private email
Saturday, May 13, 2006
 
 
Thanks for the links. Some of those look nice, I've book marked them.

We currently have a system for generating invoices but it depends on a commercial program. The purpose of this project is to break away from dependencies on all platforms and all other software. Anything beyond a BSD license would be working backwards from what we're trying to do.

I have gotten it now where I can calibrate placement of objects on the page given the particular combination of print driver and browser and running a test page and measuring its features. It's just a matter of translating measurements to account for the browser's shrinking and offsetting. It seems pretty clear that being able to layout print in html has its advantages. Looks like CSS3 will have print support for headers and footers across multiple pages, but right now I'm Ok with a single page and it looks like I have it working.

I'll note the other stuff for possible use in a future project. Thanks again.
Art Wilkins
Saturday, May 13, 2006
 
 
Art

Have you ever looked at XSL:FO?

http://www-128.ibm.com/developerworks/library/x-xslfo/?n-x-11151

On that page, there is a diagram that shows a page laid out with regions that correspond to header, footer, left and right margins etc.

Here's a quote fronm that page:

<quote>
While FO seems to be an excellent format for word processors to use for storing documents, it isn't the only XML option for document storage. DocBook is a DTD that OASIS promotes as a standard for document writing. I've used it a few times and like the way my work is organized. (See Resources for a link to the OASIS Web site). The readers of the technical stuff I wrote using DocBook never realized that I used XML for the task. They received printed booklets created using the style sheets provided by Norman Walsh to generate FO files that Fop (Apache's FO Processor) converted to regular PDF files.
</quote>

And then you *can* have another link that lets people downloaded the PDF version for printing, as someone else mentioned.

Hope you find this useful.

Cheers
Brad Thomas Send private email
Monday, May 15, 2006
 
 
Art,
    You might be interested in iText - http://www.lowagie.com/itext
Generates PDFs. Good developer support and used by commercial organizations as well. Used in Coldfusion, Jasper Reports and Google Calendar to name a few. I can assure of you my help in this regard.
It has good abstractions to avoid browsing through the PDF reference every hour. Just might be the right fit.
Vineet Reynolds Send private email
Monday, May 15, 2006
 
 
Every Web dev platform has it's own PDF library, so this is your way to go.
Berislav Lopac Send private email
Monday, May 15, 2006
 
 
>>The trick is to select a specific browser, and determine the actual margins when printed & what percentage of the paper that is at.

Don't forget standard paper sizes are narrower in Europe, it's bad enough getting all these load letter messages but even worse when our print's are cropped.

With regards to the original question I'd check out FO as well, there is an open source Java implementation (FOP) which works quite well.
Tony
Monday, May 15, 2006
 
 
Why not use a report generation library and export to PDF?  We currently use DataDynamics Active Reports and then use the included PDF export library.  I assume that Crystal Reports has the same thing (but I recommend staying away from Crystal).
O Canader
Tuesday, May 16, 2006
 
 
I just think that it is sad that we can't get decent printing from a browser. When the standard answer becomes "use a pdf report generator" then there is something seriously wrong with the underlying technology. Hopefully, these issues will be corrected soon. :(

We went to using pdf's for web reports by incorporating iText into our app. I'm personally not very happy with it. It just bothers me that we have to distinguish between a "report" and any other standard "page" due to technology limitations/decisions. Not to mention the fact that opening up a pdf takes significant time and really interupts the user's workflow. Especially since users rarely actually ever print the darn things anyway! It is just for the "possibility" that someone might want to print something that we have to jump through all these hoops. Meanwhile, users who have no intention of printing could be much better served with standard HTML output. That just seems ridiculous.
Turtle Rustler
Wednesday, May 17, 2006
 
 
Thanks much for all he responses. There's a commercial system in place that already works, but it isn't expandible in the way we need, and it only easily interfaces with certain things. There was this big debate over what other solution to go to and it looked like it would be never ending and end up costing a fortune. So I replaced the whole system in a weekend of work, and pulled it out during the meeting about what to do next. Seems we'll be using this for now, with the idea that one of the CEO's golfing buddies will still be in the running to dump a inferior solution on us for a few hundred thousand. I may have gained a political enemy as well! :-)
Art Wilkins
Wednesday, May 17, 2006
 
 
Incidentally, a halfway decent print command is supposed to be one of the big improvements in IE7...
Chris Nahr Send private email
Tuesday, May 23, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz