Tutorial :Report decent printing in the web



Question:

As a web systems programmer, I'd like to generate some reports and be able to send it to the printer directly from my user's browser, wich is in the client side, not needing to generate PDFs or something like this.

I would like to be able to:

  • Print user friendly paging, something like "Page 1 of 3"
  • Print some things in the bottom of every page, like "Generated in 2009-02-20"
  • not printing the URL

Is all this possible? Javascript? CSS? What are the best practices here?


Solution:1

All those things are controlled exclusively through browser preferences. If you want to be able to specify that, then you probably should be looking at PDF instead of HTML.


Solution:2

You're out of luck using the browser there... I think it is impossible to not print in the corners the URL, Date/Time Accessed etc.

However, Page 1 or 3 etc is generally always printed somewhere (bottom right corner I believe in FireFox)

Printing a 'Generated in 2009-02-20' is easy enough, however printing it at the bottom of every page will be difficult. Most browsers, IIRC, display the date and time accessed in a corner (though not in that format, in a more readily human readable format).

Anything you want to appear in print but not in the normal screen view, will need to be shown using a print stylesheet.

For what you want here (complete control of the printing output), I'd recommend generating a PDF. Perhaps if this is an internal tool, you might be able to program a plugin for Firefox that may print your pdfs automatically, but I'm not that familiar with the capabilities of Firefox plugins so you'd need to experiment.


Solution:3

Support from different browsers is surely lacking, but css has a media type called print, to use it, just define a section in your css file or tag like this:

@media print{  /* normal style declarations   but you probably want to hide menus    and other navigation, also use black on white,  etc.   */  }  @media screen{  /* your current stylesheet */  }  

This List Apart article covers the basics.

And here's an entry point to the wc3 specification.


Solution:4

you might be able to use SQL reporting services to generate your reports. It uses its own client print control activex though, but the results are good.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »