
java开发电子发票系统代码
5星
- 浏览量: 0
- 大小:None
- 文件类型:RAR
简介:
包 com.lenovo.union.printreceipt.test
该库通过$java.awt.*引入。该打印功能由$java.awt.print.*提供。此为Test类,该类实现Printable接口,并在私静态块中将字体设置为Helvetica字体的普通字号。public static void main(String[] args) {
获取一个PrinterJob实例
Get a PrinterJob instance;
PrinterJob job = PrinterJob.getPrinterJob();
将可打印对象指定为SimplePrint类的一个实例
job.setPrintable(new SimplePrint());
显示对话框
if (job.printDialog()) {
如果没有用户取消打印操作则执行打印逻辑
if (!job.printCanceled()) {
尝试执行打印操作
try {
job.print();
} catch (Exception e) {
捕获任意抛出的错误并进行处理
handle exception for any caught exception e;
}
}
退出程序
System.exit(0);
}
public int print(
Graphics g,
PageFormat pf,
int pageIndex) throws PrinterException {
the range of pageIndex values from 0 through 4 maps directly to the page numbering starting at 1 up to and including 5. If a pageIndex value greater than or equal to one is specified:
g.setFont(fnt);
g.setColor(Color.green);
if (pageIndex >=1) {
return Printable.NO_SUCH_PAGE;
}
The text will be positioned at coordinates x=100 and y=100.
g.drawString(
String.valueOf(Page + pageIndex +1),
100,
100);
The rectangular area defined by the four points (200,200) as top-left corner and width of 200 units will be drawn on the graphics object.
return Printable.PAGE_EXISTS;
}
全部评论 (0)


