Olá!
Estou imprimindo diretamente do JAVA em uma impressora EPSON TM-T20 com sucesso, mas somente com o PrinterJob.printDialog(). Se eu programo para não aparecer o diálogo de impressão, a impressão sai com uma margem maior, de 3cm, lateral e superior.
Gostaria de saber porque isso ocorre, já que quando eu imprimo com o PrinterJob.printDialog() eu não configuro nada na impressão, apenas dou OK.
Segue o código:
public class Testeimpressora implements Printable, ActionListener {
@Override
public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
if (page > 0) { /* We have only one page, and 'page' is zero-based */
return NO_SUCH_PAGE;
}
/* User (0,0) is typically outside the imageable area, so we must
* translate by the X and Y values in the PageFormat to avoid clipping
*/
Graphics2D g2d = (Graphics2D) g;
g2d.translate(pf.getImageableX(), pf.getImageableY());
//g2d.translate(0, 0);
/* Now we perform our rendering */
/* tell the caller that this page is part of the printed document */
return PAGE_EXISTS;
}
public void actionPerformed(ActionEvent e) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
boolean ok = job.printDialog();
if (ok) {
try {
job.print();
} catch (PrinterException ex) {
/* The job did not successfully complete */
}
}
}
public static void main(String args[]) {
UIManager.put("swing.boldMetal", Boolean.FALSE);
JFrame f = new JFrame("Hello World Printer");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
JButton printButton = new JButton("Print Hello World");
printButton.addActionListener(new Testeimpressora());
f.add("Center", printButton);
f.pack();
f.setVisible(true);
}
}
Gostaria de conseguir imprimir sem margens sem o printDialog().
Obrigado!