I have been working on implementing a simple application that reads pdf, then put some of the infos in a JPanel, then generate a bufferedimage and try to send it to the printer. the code generates the image perfectly and send it to be printed. it works perfectly with A4 format and many other format, but I'm looking to print it on a pvc cr80 Card (the printer prints 1016*642 pixels)
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
Container c = jPanel3;
BufferedImage im = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
c.paint(im.getGraphics());
try {
String cn = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(cn); // Use the native L&F
} catch (Exception cnf) {
}
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(new Printable() {
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if (pageIndex > 0) {
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D)graphics;
g2d.translate((int) pageFormat.getImageableWidth(),pageFormat.getImageableHight());
g2d.drawImage(im, 0, 0,1016,642, null);
return PAGE_EXISTS;
}
});
boolean ok = printJob.printDialog();
if (ok) {
try {
printJob.print();
} catch (PrinterException ex) {
System.out.println("Can't print");
}
}
}
this code doesn't print on the pvc cr80 Card printer (1016*642 pixels). how can I fix that?