Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Javax.print .API Please help  RSS feed

 
Rashmi Hegde
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!