Print a JTable with multi-line header...
hello all,
i am facing problem in printing...
i have gone through many posts in this forum but did not find a solution for my problem. some posts say about few softwares like "Smart JPrint", "JFreeReport". but these are not free software. we can download demos but it will expire soon.
now my problem is:
i want to print a multi-line header (about 3 lines.) & below it i want to print JTable.
i want my output to be:
**********************//not this line
<Departmental Store Name> <Date>
<Transaction No>
<Clint Name>
<Clint Address> <Clint Ph>
<JTable 1>
<JTable 2>
<JTable 3>
<Thx Note>
******************//not this line
i need 3 tables because all tables have different no. of columns...
i want to print in continues rolled paper (the once used as supermarket bill, not separate papers.) telling u in case it makes any difference.
till now i thought of few ways to do it...
1. i make a table, each row contains the component to be printed & than call this new table's print method. it is some sort of Nesting of Tables.
but i don't know how to Nest Tables.
2. i make a Dialog biiiiiiiiiiiigggggggggggg enough to hold these tables and all stuff. & than call to print this Dialog.
made the dialog already but i failed to implement the print method. i have read about printUtilities & print methods using Graphics2D (etc.) but not able to implement it.
if u ppl have some other ideas also please tell me...
plz provide me some help...
thx in advance...
Regards,
Rashmirathi
hay thx,
i can think on this option. but the thing is that my client is not having that much computer knowledge.
so i can't explain & expect him to create a PDF first & that to take print from a PDF file.
i have not read fully on iText, may be it solve my problem.
BTW will it allow me to create PDF in a roll paper. see my printout would be on a sheet that would be arround 3/4 inches in width & it may long to 30-50 inches...or even more than that depending on the items purchased by the client. my experience with PDF says that it breaks pages...?
any more IDEA! plz?//
thx
hi,
thx for ur help.
i m trying to learn by the examples to make pdf's .
plz tell me have u worked on iText?
also i read about the 'Silent Printing' thru the link u have provided.
as per it, we need one extra 'jar' file known as 'servlet.jar'
i tried but failed to find that file. plz tell me how can i get it. coz iText along with silent printing feature will help me solve my problem...
thx agn....
>plz tell me have u worked on iText?
Yes, I made complex PDFs with this Java library.
NB : Several leader frameworks like Spring, JBoss seam integrate iText to produce PDF.
>as per it, we need one extra 'jar' file known as 'servlet.jar'
servlet.jar is a Servlet implementation library of the web application.
For example, if you are using a Tomcat server, you'll find this jar in :
TOMCAT_DIR/common/lib/.
Normally, every application server has its servlet.jar (jasper-runtime.jar for jsp).
HTH
hi again,
To print pdf in a swing application you don't need servlet.jar.
You'll only need itext.jar and a printer connected to your pc.
Download the iText source code and unzip it. See the following classes:
com.lowagie.tools.LPR and com.lowagie.tools.BuildTutorial. This latter is the main class of a swing tool that you can run.
Silent Print:
You have only to embed this javascript code in your pdf:
writer.addJavaScript("this.print(false);", false);
document.add(new Chunk("Silent Auto Print"));
Then, you have to send the document to the printer.
Google : java print pdf
http://forum.java.sun.com/thread.jspa?threadID=523898or
http://www.exampledepot.com/egs/javax.print/pkg.html for printing task.
Under unix system, I used this:
String PRINTER = ...;
try {
String cmd = "lp -d " + PRINTER + " " + PDF_PATH;
Runtime.getRuntime().exec(new String[] { "sh", "-c", cmd });
} catch (Exception e) {
//handle the exception
e.printStackTrace();
}
hth