我使用 awt.print 编写了一个打印程序,该程序适用于网络连接的喷墨打印机。当我在 USB 点阵打印机上运行程序时,它似乎不起作用。(程序可以识别打印机)谁能告诉我为什么。这是一些代码片段:
public int print(Graphics g, PageFormat pf, int page)
throws PrinterException {
/* We have only one page, and 'page' is zero-based */
if (page > 0) return Printable.NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D) g;
g2.setPaint(Color.black);
drawPage(g2, page);
return Printable.PAGE_EXISTS;
}
public void drawPage(Graphics2D g2, int page) {
Font font1 = new Font("宋体", Font.BOLD, 14);
g2.setFont(font1);
g2.drawString(printStr1, 10.0, 10.0);
}