Se tiene la imagen barcode1.gif que se agrega a la impresion en el metodo print.
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.*;
import javax.swing.ImageIcon;
import java.awt.Image;
public class imprimir2 implements Printable {
public static void main(String[] args) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(new imprimir2());
//job.setPrintable(this);
boolean doPrint = job.printDialog();
System.out.println(doPrint);
if (doPrint) {
try {
job.print();
} catch (PrinterException e) {
e.printStackTrace();
}
}
}
@Override
public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
if (page > 0) {
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D) g;
Image img1;
ImageIcon icon = new ImageIcon("barcode1.gif");
img1 = icon.getImage();
g.drawString("minuvaHard10 corp.", 100, 100);
g.drawString("Simulacion de Ticket", 100, 130);
g.drawImage(img1, 200, 170,null);
return PAGE_EXISTS;
}
}
e-mail: minuvasoft10@gmail.com Miguel Nunez Programador de Proyectos Software en Java.
No hay comentarios:
Publicar un comentario