-2

I want to generate a report depending upon the data entered by user into the form. The problem I am facing is that I cannot use server side interaction to generate a new page for printing, it needs to be done on client-side (using JAVASCRIPT) only.

Ex. Google Calendar shows a nice pop-up when you try printing something. Many ticketing systems use the similar technique to printout tickets.(like IRCTC)

Please dump whatever you have got about printing from web-browsers.

hvgotcodes
  • 118,147
  • 33
  • 203
  • 236
abhishek77in
  • 1,848
  • 21
  • 41
  • google it. You can find enough info on Printing. Use ActiveX or some other techniques – Kris Oct 31 '11 at 12:09
  • i have done enough of background work.. let me know if you have something! – abhishek77in Oct 31 '11 at 12:13
  • @Krishnanunni hope you got the question right.. – abhishek77in Oct 31 '11 at 12:14
  • use css (may be printcss) define your layout with tables or grids, apply styles. and then go for print. – Kris Oct 31 '11 at 12:17
  • i know about print-css but what I am trying is to open a pop-up with entirely different content.. (eg. header and footer which was not there when filling up the form) only some values filled in form are to be reused. – abhishek77in Oct 31 '11 at 12:20
  • use an iframe, load it with AJAX. define ur css. call the window.print() from iframe; maywrk. its an idea only; – Kris Oct 31 '11 at 12:25
  • See [this](http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Print-a-Web-Page-Using-JavaScript.htm) and [this](http://stackoverflow.com/questions/5220249/print-from-frontend-javascript). – Mudassir Oct 31 '11 at 12:29
  • "Please dump whatever..."? Seriously? That's how you're framing your question about a need that is, presumably, important to you? – David Thomas Oct 31 '11 at 23:36

1 Answers1

1

You can achieve this by creating a new page in a popup window or an <iframe>, writing a document into it containing whatever information and markup (and CSS) you need, and then having the page call "window.print()".

Pointy
  • 405,095
  • 59
  • 585
  • 614
  • 1
    That would be a better answer with an example - especially one that shows popup.document.close() – mplungjan Oct 31 '11 at 12:25
  • the problem is entering the HTML inside pop-up window, should i be using "document.writeln" for each line... how do I place the content in the new window ? I can do this using ERB or something similar but I cannot use server-side interaction here as I am trying to build an offline app – abhishek77in Oct 31 '11 at 12:31
  • Yes, you can use "document.write()" to build the page. You could build just a skeleton that way and then add more content with DOM manipulation, if you prefer. – Pointy Oct 31 '11 at 12:50
  • thanks i think this is the only way to do it.. this blog post looks helpful in my case - http://blog.dynom.nl/archives/Javascript-printing-a-popup-window_20091029_52.html – abhishek77in Oct 31 '11 at 14:00