PDA

View Full Version : [JAVA] Problema stampa


bobby1112
07-07-2010, 10:53
salve ragazzi sto realizzando un' applicazione per mandare in stampa dei documenti in formato A4 adesso ho questo problema , quando eseguo la stampa la stampante non mi riconosce il formatoi come A4 ecco il codice


FramePreview framePreview=new FramePreview(gestore);

PrinterJob pj = PrinterJob.getPrinterJob();
PageFormat format = pj.defaultPage();
//PageFormat format = pj.pageDialog(pj.defaultPage());

//Aggiongo questi parametri per il mio pc

MediaPrintableArea area = new MediaPrintableArea(20,20,50,50, MediaPrintableArea.INCH);
HashPrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(area);


//inverto le dimensioni perchè stampo in modo orizzontale
float pageHeight = MediaSize.ISO.A4.getX(MediaSize.INCH) * 72;
float pageWidth = MediaSize.ISO.A4.getY(MediaSize.INCH) * 72;

System.out.println("A4:"+pageHeight+" "+pageWidth);


float margin = (1 / 2.54f) * 72; //1cm
Paper paper = new Paper();
paper.setImageableArea(margin, margin,585-margin,790-margin);




System.out.println("Pagina"+paper.getWidth()+paper.getHeight());


format.setPaper(paper);
format = pj.validatePage(format);

//ruoto la pagina in maniera orizzontale
format.setOrientation(PageFormat.LANDSCAPE);


//pj.printDialog();
pj.setPrintable(framePreview,format);

System.out.println("Area Stampabile"+margin+" "+margin+" "+pageWidth+" "+pageHeight);
try {
pj.print(aset);
} catch (PrinterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}





helpe me:muro:

Hardware Upgrade Forum Database Error
Database Error Database error
The Hardware Upgrade Forum database has encountered a problem.

Please try the following:
  • Load the page again by clicking the Refresh button in your web browser.
  • Open the www.hwupgrade.it home page, then try to open another page.
  • Click the Back button to try another link.
The www.hwupgrade.it forum technical staff have been notified of the error, though you may contact them if the problem persists.
 
We apologise for any inconvenience.