Also so sieht der Code im Moment aus:
public class PrintTest implements Printable {
public int print(Graphics g, PageFormat pf, int pageNr) {
if (pageNr==1) return NO_SUCH_PAGE;
BufferedImage image;
try {
image = ImageIO.read(new File("out.png"));
g.setColor(Color.black);
g.setFont(new Font("Times", Font.PLAIN, 47));
//g.drawImage(image, 0, 0, 200, 1060, null);
g.drawImage(image, 0, 0, null);
} catch (IOException ex) {
Logger.getLogger(BarcodeView.class.getName()).log(Level.SEVERE, null, ex);
}
return PAGE_EXISTS;
}
}
try {
//Create the barcode bean
EAN13Bean bean = new EAN13Bean();
final int dpi = 150;
//Configure the barcode generator
bean.setModuleWidth(UnitConv.in2mm(2.0f / dpi)); //makes the narrow bar
//width exactly one pixel
bean.setBarHeight(10);
bean.doQuietZone(false);
//Open output file
File outputFile = new File("out.png");
OutputStream out;
out = new FileOutputStream(outputFile);
//Set up the canvas provider for monochrome PNG output
BitmapCanvasProvider canvas = new BitmapCanvasProvider(out, "image/x-png", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 90);
// 200x 10
//Generate the barcode
bean.generateBarcode(canvas, "234567891231");
//Signal end of generation
canvas.finish();
System.out.println("width:" + canvas.getBufferedImage().getData().getWidth());
System.out.println("height:" + canvas.getBufferedImage().getData().getHeight());
out.close();
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(new PrintTest());
pj.printDialog();
try {
pj.print();
} catch (PrinterException pe) {
}
} catch (IOException ex) {
Logger.getLogger(BarcodeView.class.getName()).log(Level.SEVERE, null, ex);
}