-
1. Re: How to let user print off a list?
wise_guybg Jul 26, 2007 12:32 PM (in response to ellenzhao)You can display it in a separate window as a printable page. The user can then print it using the browser. I think it's done this way normally
-
2. Re: How to let user print off a list?
ellenzhao Jul 26, 2007 12:36 PM (in response to ellenzhao)Thanks! I'll do it right away!
Just started to read this:
http://java.sun.com/javase/6/docs/technotes/guides/jps/index.html
But now there is no need to spend time there....Thanks!!
Regards,
Ellen -
3. Re: How to let user print off a list?
wise_guybg Jul 26, 2007 12:47 PM (in response to ellenzhao)Yes :-) I saw that on the Internet too and right before posting a link:
http://www.google.bg/search?q=java+print
I stopped and realized that you need printing on the client machine. The interface is the browser so you could simply use that. -
4. Re: How to let user print off a list?
ellenzhao Jul 26, 2007 1:05 PM (in response to ellenzhao)I tried out the "print this page" button here:
http://www.tizag.com/javascriptT/javascriptprint.php
The result is exactly what I want. But how to print off just a list provided by the backing bean but not the entire window? I'm very clueless on javascript, any help will be highly appreciated!
Regards,
Ellen -
5. Re: How to let user print off a list?
ellenzhao Jul 26, 2007 1:56 PM (in response to ellenzhao)<script type="text/javascript" language="JavaScript"><!-- if(window.print) { document.write('<a href="javascript:window.print()">[click to print]</a>'); } //--></script>
I found this code from here:
http://willmaster.com/blog/javascript/Four_Ways_To_Print_a_Web_Page.html
How to pass the formatted list to the "document" in the code above? And how do I use this javascript fragment in my .xhtml file? (I mean, how to bind this script to a button? ) Many thanks!
Regards,
Ellen -
6. Re: How to let user print off a list?
jcg3 Jul 26, 2007 5:39 PM (in response to ellenzhao)You can also use css to determine how the printing appears on paper... google "printing css" for examples.
You can go as far as to have only one div show up for printing, or show divs in print that aren't visible on screen. -
7. Re: How to let user print off a list?
smithbstl Jul 26, 2007 8:55 PM (in response to ellenzhao)Why not just create a separate page optimized for printing (ie "printer-friendly" version). Open it in a new window.
-
8. Re: How to let user print off a list?
ellenzhao Jul 27, 2007 3:51 AM (in response to ellenzhao)@smithbstl
because on the page there are several fragments should be printed off. One is a shopping list, which should be like a shopping list (slim, small, layout simple....), others might be suitable for A5 or A4 format. Mixing them on one page is easy for me but not good for my users. -
9. Re: How to let user print off a list?
wise_guybg Jul 27, 2007 6:07 AM (in response to ellenzhao)Well you can have a link for every fragment if you think they should display in a different way.
Anyway, I guess you have solved your issues with printing by now. -
10. Re: How to let user print off a list?
davidfed Jul 27, 2007 7:54 PM (in response to ellenzhao)I needed a way to print content without showing it first. And it is a completely different layout than the visible page and required data that was just entered on the page.
I have this at the bottom of the visible page (Event.observe() is from Prototype):<iframe id="printbox" name="printbox" src="#{referralController.faxUrl}" width="0" height="0" style="border:none"> </iframe> <script type="text/javascript"> Event.observe(window, 'load', printFax); </script>
Here's the javascript function:function printFax() { if (window.frames['printbox'].document.URL.indexOf("faxcover") != -1) { window.frames['printbox'].focus(); window.frames['printbox'].print(); } }
The function checks to see if the iframe contains any printable content by checking the URL.
I leave the URL blank when first loading the page. When the print button is clicked the backing bean method stores the data, sets the printing URL and then reloads the same page. I include the conversation id so the printing page can find the data.faxUrl = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/faxcover.seam?clr=true&cid=" + conversation.getId();
This works in both IE and FF. The page doesn't change visually but the print dialog appears for the hidden layout.