How to print a report from a web application

Here's what I'd like to be able to do:

Using PHP/JavaScript, I'd like to create a <div> that's 8 1/2 by 11 inches in dimensions. It's contents will be details of a report of whatever kind. I then would like to be able to have the user click a "Print Report" button to print out this <div> to an 8 1/2 by 11 inch paper. I don't want any extraneous details like the URL link at the top or bottom. In short, I want the <div> to print out exactly the way it is, no more, no less.

Is there any way I can do this? Any advice that points me to the right path would be greatly appreciated.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
This is a bit of an open ended question

You can style your div with unit cm, mm, inches etc (refer spec here). There are some caveats with this
1) This may work on some but not other monitors - depends on the age of the monitor and if they support EDI or not which gives back a dpi reading which then can be translated into a width based on screen resolution. In older monitors where your could have your display configured to different resolutions without EDI it is not possible to get the width.

With respect to the URL at the bottom - this is variable in what you can do with it - in some cases you can and others not refer to the @page spec here - browser dependent.

My thoughts are that you don't use HTML for printing reports. I would look at a PDF library and use output to PDF as the printed version of the report. This way you are guaranteed of getting the same output all the time and you loose the URL's at the bottom by default.

Requires extra coding to output the PDF but there are a lot of good libraries out there that can assist with this.
elepilAuthor Commented:
JulianH, thank you for responding.

My goal is simplicity. I am actually rewriting a standalone desktop application as a PHP application. In the desktop version, the user could just click print and a pop window comes up to give them a print preview, after which they can just click the Print button and get a hardcopy.

Prior to making this post in this forum, my plan was to open a popup with no URL address field, and then just use window.print() to print the entire page which would've already been preformatted and prepopulated with the report data; I haven't tested it yet, but I'm assuming if I size the report content properly, it should print out neatly within 8 1/2 x 11 sheets of paper. Do you think this is viable?

My purpose for making this post was to get ideas from other people like yourself on even more streamlined ways than what I was intending to do. Your suggestion to output to PDF is a good one, but it would take more steps than my plan, both for the user and programmatically for myself. Do you know of any printing frameworks out there that would facilitate what I'm trying to do? I was hoping there'd be something like just adding a <script> tag the way we do in jQuery, and voila, we have a whole host of features available. Anything like that for printing?
Julian HansenCommented:
Not offhand - although most solutions in this space focus on the backend - things like htmltopdf etc are available as PHP / C# plugins that render out the page that is then sent to the browser.

Remember you can have different style sheets for screen and print - so you can style the printed output for printing separately.

Not sure if any of these are of any use

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
elepilAuthor Commented:
Thanks for your help, Julian.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Applications

From novice to tech pro — start learning today.