• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing jframe in A5 paper  RSS feed

 
Shashika Thiran
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to print jframe contain in A5 paper.I've print it.But i don't know how to set A5 paper.
this is my printing code.

PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
boolean ok = job.printDialog();
if (ok) {
try {
job.print();
} catch (PrinterException ex) {

}
}

Can any one help me.
Thank.
 
Shashika Thiran
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've find out answer for my problem.I've post it everyone to know.
It's simply like this

try {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
PrintRequestAttributeSet printRequestAttrSet = new HashPrintRequestAttributeSet();
printRequestAttrSet.add(MediaSizeName.ISO_A5);
printRequestAttrSet.add(new MediaPrintableArea((float)0.0,(float)0.0,350,500, MediaPrintableArea.MM));
printJob.printDialog(printRequestAttrSet);
printJob.print(printRequestAttrSet);

}catch (PrinterException ex) {
ex.printStackTrace();
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!