Forums Register Login

Javax.print .API Please help

+Pie Number of slices to send: Send
Hello all,

I am trying to print out the contents on the Jpanel.
When i pass the object of Jpanel in the construcor of
Doc doc = new SimpleDoc(jPanel1, flavor, das);

I get the following exception.
java.lang.IllegalArgumentException: data is not of declared type
at javax.print.SimpleDoc.<init>(SimpleDoc.java:82)
at com.wp.gui.PrintPreviewFrame.print(PrintPreviewFrame.java:573).


Following is the method i use to print.




public void print(){

DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;

//If mote than one printer is connected to the machine needs to be changed.
PrintService printService =PrintServiceLookup.lookupDefaultPrintService();

DocPrintJob job = printService.createPrintJob();
PrintJobListener pjlistener = new PrintJobAdapter() {
public void printDataTransferCompleted(PrintJobEvent e) {
System.out.println("Good-bye");
System.exit(0);
}
};
job.addPrintJobListener(pjlistener);

PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();

DocAttributeSet das = new HashDocAttributeSet();

//TRY WITH OTHER ATTRIBUTES HERE.
//Attributes can be obtained from
//Package javax.print.attribute.standard OR
//Package javax.print.attribute

das.add(Finishings.STAPLE_TOP_LEFT);//Here we can set with the atttributes to make Resolution adjustment and Positioning.

//Setting the Document to be printed as Component...

Doc doc = new SimpleDoc(jPanel1, flavor, das);
try {
job.print(doc, pras);
} catch (PrintException pe) {
pe.printStackTrace();
}




}

Can anyone please help me.

Thanks for your effort.
Karishma
Bring out your dead! Or a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1149 times.
Similar Threads
Landscape Printing
Need help Printing
help in java printing
[PrintService] Pb while printing
help in java printing
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:31:15.