Print Facility for the content on a servlet

Hello,

I have to provide a button called "Print" which will enable the printing facility for the data ( which is a data that is displayed from database with some constraints.)

So i wanted to know how to avail the Print Facility that will be printed as a text document .

Please help me in generating that facility.

[339 byte] By [Kranthi.Remalaa] at [2007-11-26 19:55:10]
# 1
What does it have to do with Java? You want a button that prints an HTML page.
CeciNEstPasUnProgrammeura at 2007-7-9 22:48:05 > top of Java-index,Java Essentials,Java Programming...
# 2

The problem is it should not print the page as it is.

It should print the data in the form as text document.

In a servlet books.java, there is data being displayed about which users are ordering for which books.

So, the customer wants a print out like a catalog for himself of that particular page.

Infact, i would like to know how to handle "printing facilty" by just giving the "print" button.

Kranthi.Remalaa at 2007-7-9 22:48:05 > top of Java-index,Java Essentials,Java Programming...
# 3

> The problem is it should not print the page as it

> is.

The problem is that servlet code has nothing to do with anything the client can or can not do. It's an HTML/Javascript problem, or you need to include an applet in that HTML that does what you want somehow.

> It should print the data in the form as text

> document.

"Text document"? Huh? As opposed to what?

> Infact, i would like to know how to handle "printing

> facilty" by just giving the "print" button.

However it is handled, it has nothing to do with servlets. By the time this button exists, the servlet instance is probably long gone. Don't you understand the difference between client and server?

CeciNEstPasUnProgrammeura at 2007-7-9 22:48:05 > top of Java-index,Java Essentials,Java Programming...
# 4

You can do quite a lot by defining separate style sheets for viewing and printing. This allows you, for example, to suppress buttons and stuff which are useless on the printout.

But if you really want to get fancy on the printing, such as presenting a multi-page listing with column headers on each page etc., then I think the best approach is to generate a PDF page (I prefer to open a new window).

This means using one of the PDF libraries like PDFBox and having a special purpose servlet to generate a PDF return.

That will allow you much finer control over the printing than is possible from HTML.

malcolmmca at 2007-7-9 22:48:05 > top of Java-index,Java Essentials,Java Programming...
# 5

I do understand the difference between the client and the server.

I actually wanted to know...

Just as for aplets, we use OLE to link to excel sheets and get the print out how can i do it from a web page.

Now if i normally take a printout of the web page as it is..i'll be getting all unwanted stuuf i.e. the headers etc and all.

So, i would like to know how do you link objects so that the data goes and sits in the word document or the excel sheets.

I'm sorry for the neglegence and innocence of my poor subject but i'm learning java by practically taking some live assignments.

So, my questions may sound silly but they are important to me.

And yeah i do understand the basic subject.

Kranthi.Remalaa at 2007-7-9 22:48:05 > top of Java-index,Java Essentials,Java Programming...
# 6
Ohh Okk...well i shall try it out.You specified PDFBox extension. Is that available in java 4 SE?.
Kranthi.Remalaa at 2007-7-9 22:48:05 > top of Java-index,Java Essentials,Java Programming...
# 7

>

> I actually wanted to know...

> Just as for aplets, we use OLE to link to excel

> sheets and get the print out how can i do it from a

> web page.

Would you want people's web pages to have access to your client machine's printer?

There are excellent reasons why web pages shouldn't have the kind of access that a stand-alone application does.

ps

PDFBox is a 3rd party library. Find it on www.sourceforge.net

But PDF works well enough. The user presses a button, up comes a window with the PDF version and they just press the print button on the page.

It allows them to retain proper control over the process, they can see how much printing is being contemplated and check that it's the right stuff.

Message was edited by:

malcolmmc

malcolmmca at 2007-7-9 22:48:05 > top of Java-index,Java Essentials,Java Programming...