1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| package src;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.Calendar;
import src.pos.article.ArticleList;
import src.pos.order.Order;
public class TestPrint implements Printable{
public TestPrint() {
}
public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
int x = 10;
int y=10;
if (page > 0) {
return NO_SUCH_PAGE;
}
Paper pfor=pf.getPaper();
pfor.setImageableArea(5, 5, 100,100);
System.out.println("getHeight()"+pfor.getHeight());
System.out.println("getImageableHeight"+pfor.getImageableHeight());
System.out.println("getImageableWidth"+pfor.getImageableWidth());
System.out.println("getImageableX"+pfor.getImageableX());
System.out.println("getImageableY"+pfor.getImageableY());
System.out.println("getWidth"+pfor.getWidth());
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pf.getImageableX(), pf.getImageableY());
//g2d.setFont(new java.awt.Font("Tahoma",1,5));
Font f=new Font("Arial",1,6);
g2d.setFont(f);
g.drawString(" BIENVENU A TMMS", x, y);
//y+=10;
g2d.drawString("***************************************************", x, (y+=10));
//System.out.println("order.getOrderID() : "+order.getOrderID());
Calendar cal=Calendar.getInstance();
g2d.drawString(cal.getTime().toLocaleString(), x, (y+=10));
//g.drawString(order.getSHeureNow(), x, (y+=10));
g2d.drawString("Commande N° : 1649879", x, (y+=10));
g2d.drawString("***************************************************", x, (y+=10));
int z=x;
for(int i=0;i<1;i++){
g2d.drawString("Unité central Hp Compaq", z, (y+=10));
g2d.drawString("450.0", (z+=150), y);
g2d.drawString("2", (z+=40), y);
g2d.drawString("900", (z+=20), y);
z=x;
}
/* tell the caller that this page is part of the printed document */
return PAGE_EXISTS;
}
public void printTicket(){
PrinterJob job = PrinterJob.getPrinterJob();
//PrinterJob job = new PrinterJob();
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){
TestPrint t=new TestPrint();
t.printTicket();
}
} |
Partager