wood burning stoves 2.0*
The moose likes Servlets and the fly likes getting a html page in printable form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "getting a html page in printable form" Watch "getting a html page in printable form" New topic
Author

getting a html page in printable form

khushi paul
Greenhorn

Joined: Feb 08, 2005
Posts: 26
hi all,
can any body tell me is there any java api or other open source code available so that i can have a print option on the html pages i generate through servlet.

actually some pages are divided into frames and i want to give a print button or clickable image on each frame so that when user click that the page get set in printable format.

is this thing possible and if yes pls guide me how.
thanks and regards
khushi
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What you are asking for is client side code - which would be awkward. You'd need to write an applet which used the Java Print Service to find a printer (if the user has any set up), which used the static(?) HTML page to build a printable object and then print it. You could do it this way, but a far easier way of doing it would be to popup just the frame your user wants to print and let them print this as they would any other web page. And you could do that with a little bit of JavaScript.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
hi

Use Javascript code

<script language="java">
window.print(1);
</script>

This will print the output of page where you will write this code

Regards
Rohit
khushi paul
Greenhorn

Joined: Feb 08, 2005
Posts: 26
hi rohit,i used this code on click event of a button,i get my frame printed but complete frame is not printed.
actually it is a scrollable frame and only the contents that are visible on the screen at a time are printed.
what might be the problem?
regards
khushi
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Actually I never faced such problem,as I didnt had any scrollable frame.

I dont know the solution but will have to think on it..

Will get back to you later

Regards
Rohit
Thomas Hubschman
Ranch Hand

Joined: Sep 25, 2002
Posts: 88
The typical solution would be for you to have an alternate 'view' of the page which is printer friendly (reduced graphics, no frames, etc. etc.)

If your app is not database driven this could be a pain to develop alternate versions of all your pages.

Then again what is in the top/side frame that needs to printed? Usually these are used for menus while the content is stored in the center frame.

Is there a reason why a roundtrip to the server to generate a printable page is unacceptable to the user? It would save you the headache of fooling with javascript.

Tom


SCJP '02, SCWCD '02, SCJD '08, SCSNB '09, SCEA '10
khushi paul
Greenhorn

Joined: Feb 08, 2005
Posts: 26
thanks thomas,
yes i am developing a database oriented application but it is not possibel for me to rewrite all the pages.

actually there are two frames row wise.the upper frame contains alot of information which is fetched from 2-3 database tables and presented in a tabular form,moreover various links are also present on that page.
when any link is clicked the related information(page) appears in the lower frame.

i hope i am clear to you.
any other suggestion pls....

regards
khushi
Sarath Mohan
Ranch Hand

Joined: Mar 17, 2001
Posts: 213
Hi,

I feel print this page is the same page without frames ideally in a pop up window.

You may need to convert the scollable frame to a html page.

You can get the complete html source of the frame if utilise a java.net.URLConnection class and display the same for printing in a new html page.

Regards


Sarath Mohan
khushi paul
Greenhorn

Joined: Feb 08, 2005
Posts: 26
thanks sarath,
can you give a code snippet for that?
regards
khushi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting a html page in printable form
 
Similar Threads
Printing multiple pages in Java
Printable version of jsp/HTML
print applet
Documents
how to give print option to any page?