Hallo,
ist es möglich das der Druckvorgang auch ohne Druckdialog
gestartet werden kann.
Für Eure Hilfe wär ich echt dankbar
Ciao
Uwe
class BarcodePrint
extends Frame
{
public void doDraw(Graphics2D g, boolean printer) {
try {
int y = 40;
int x = 10;
int linespace = 25;
int fontSize = 8;
int barHeight = 10;
int barWidth = 1;
if (printer) {
y = 50;
x = 20;
linespace = 60;
fontSize = 25;
barHeight = 25;
barWidth = 2;
}
g.setColor(Color.black);
Font ft = new Font(null, Font.TRUETYPE_FONT, fontSize);
String testLine = "Mein TEst";
Barcode bc = BarcodeFactory.createCode128B("My Barcode");
bc.setBarHeight(barHeight);
bc.setBarWidth(barWidth);
bc.setFont(ft);
bc.draw(g, x, y);
y += linespace;
}
catch (BarcodeException e) {
System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
}
}
public void toPrinter() {
JobAttributes attr = new JobAttributes();
int[] printerResolution = new int[3];
printerResolution[0] = 200;
printerResolution[1] = 200;
printerResolution[2] = 3;
PageAttributes pgattr = new PageAttributes(PageAttributes.ColorType.MONOCHROME ,
PageAttributes.MediaType.NA_LETTER,
PageAttributes.OrientationRequestedType.PORTRAIT,
PageAttributes.OriginType.PRINTABLE, PageAttributes.PrintQualityType.HIGH,
printerResolution);
//Und hier kommt nun der Dilalog ins Spiel//////////////
PrintJob pj= Toolkit.getDefaultToolkit().getPrintJob(this, "Print Barcode Test", attr, pgattr);
if (pj != null) {
BufferedImage bi = new BufferedImage(
pj.getPageDimension().width,
pj.getPageDimension().height,
BufferedImage.TYPE_BYTE_BINARY);
Graphics2D g2 = (Graphics2D) bi.getGraphics();
g2.setBackground(Color.white);
g2.clearRect(0, 0, 20000, 20000);
doDraw(g2, true);
System.out.println("Printer resolution " + pj.getPageResolution());
System.out.println("Print Dimension " + pj.getPageDimension());
Graphics g = pj.getGraphics();
g.drawImage(bi, 0, 0, this);
pj.end();
}
System.out.println("BarcodeProto.toPrinter: Done");
}
}
ist es möglich das der Druckvorgang auch ohne Druckdialog
gestartet werden kann.
Für Eure Hilfe wär ich echt dankbar
Ciao
Uwe
class BarcodePrint
extends Frame
{
public void doDraw(Graphics2D g, boolean printer) {
try {
int y = 40;
int x = 10;
int linespace = 25;
int fontSize = 8;
int barHeight = 10;
int barWidth = 1;
if (printer) {
y = 50;
x = 20;
linespace = 60;
fontSize = 25;
barHeight = 25;
barWidth = 2;
}
g.setColor(Color.black);
Font ft = new Font(null, Font.TRUETYPE_FONT, fontSize);
String testLine = "Mein TEst";
Barcode bc = BarcodeFactory.createCode128B("My Barcode");
bc.setBarHeight(barHeight);
bc.setBarWidth(barWidth);
bc.setFont(ft);
bc.draw(g, x, y);
y += linespace;
}
catch (BarcodeException e) {
System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
}
}
public void toPrinter() {
JobAttributes attr = new JobAttributes();
int[] printerResolution = new int[3];
printerResolution[0] = 200;
printerResolution[1] = 200;
printerResolution[2] = 3;
PageAttributes pgattr = new PageAttributes(PageAttributes.ColorType.MONOCHROME ,
PageAttributes.MediaType.NA_LETTER,
PageAttributes.OrientationRequestedType.PORTRAIT,
PageAttributes.OriginType.PRINTABLE, PageAttributes.PrintQualityType.HIGH,
printerResolution);
//Und hier kommt nun der Dilalog ins Spiel//////////////
PrintJob pj= Toolkit.getDefaultToolkit().getPrintJob(this, "Print Barcode Test", attr, pgattr);
if (pj != null) {
BufferedImage bi = new BufferedImage(
pj.getPageDimension().width,
pj.getPageDimension().height,
BufferedImage.TYPE_BYTE_BINARY);
Graphics2D g2 = (Graphics2D) bi.getGraphics();
g2.setBackground(Color.white);
g2.clearRect(0, 0, 20000, 20000);
doDraw(g2, true);
System.out.println("Printer resolution " + pj.getPageResolution());
System.out.println("Print Dimension " + pj.getPageDimension());
Graphics g = pj.getGraphics();
g.drawImage(bi, 0, 0, this);
pj.end();
}
System.out.println("BarcodeProto.toPrinter: Done");
}
}
Comment