views:

2003

answers:

4

I was looking for a solution for client side printing of reports and pre formatted forms from a PHP web based app. Note that these are not printing of HTML pages. Rather nicely aligned fixed formated Receipts, Order Forms, Ledger etc.

Something that I have though of.

Using PDF: Is there a simple one click way to print the report from client side? The obvious choice of opening the PDF in a window, then select File -> Print seems too cumbersome.

Using Flash: I saw some site providing single click printing through flash. Not sure what's working in the background. Any insight on this regard will be helpful.

Active-X/Silverlight(?): I won’t want to constraint my users on IE only. But this one-click printing requirement is so rigid that I would rather switch to MS only platforms if it achieves the task.

Note that it’s ok for the single click to bring up the print dialog box and user clicking a second time for printing. But any more complexity than that is a disadvantage.

+1  A: 
<a href = "#" onclick = "window.print(); return false;">Print!</a>
nlaq
A: 

Furter to Nelson LaQuet, you could put window.print() in the onload attribute of the body tag so that the print dialog pops up at page load,

(or use jquery's document.ready() to achieve the same, or whatever other JS frameworks offer)

benlumley
+1  A: 

If the format is so rigid you need a format like PDF. HTML/CSS is so variable you'll never get it the same on all browsers. Plug Web pages have no real concept of pages (although there is some support for things like CSS print media styling).

Also not all people actually have a printer. Trying to force something to be printed is really the wrong approach and will generally put some of your customers off.

The minimal solution is to create a receipt page with the emdia print CSS to make it appear responable most of the time.

If that's not enough you need to go PDF. Unfortunately that then becomes hard as this question regarding HTML+CSS to PDF conversion illustrates. PrinceXML does an outstanding job at this conversion but it's not cheap. Html2PDF is the best of the open source bunch but has issues (see that answer for more detail). I've had this same problem in the Java space and for invoices there ending up using Jasper Reports. I haven't really seen an equivalent reporting solution for PHP though. Python has reportlab, which seems a likely candidate for doing that kind of job too.

Perhaps your best option is to generate the PDF directly. It's a bit more tedious but it avoids the many pitfalls of HTML to PDF conversion. This tutorial (Part 2) explains how.

cletus
A: 

Please check the answer in the following link. It is helpful to u. http://helptodeveloper.blogspot.com/

Sowjanya