List of usage examples for java.awt.print PrinterGraphics getPrinterJob
PrinterJob getPrinterJob();
From source file:MainClass.java
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { // pageIndex 0 corresponds to page number 1. if (pageIndex >= 1) return Printable.NO_SUCH_PAGE; PrinterGraphics p = (PrinterGraphics) g; System.out.println(p.getPrinterJob().getCopies()); System.out.println(p.getPrinterJob().getJobName()); Graphics2D g2 = (Graphics2D) g; double w = pf.getImageableWidth(); double h = pf.getImageableHeight(); int xo = (int) pf.getImageableX(); int yo = (int) pf.getImageableY(); Rectangle2D r = new Rectangle2D.Double(xo, yo, w, h); g2.setColor(Color.red);/*from www . j a v a2 s. co m*/ g2.draw(r); Shape s = new Ellipse2D.Double(xo + 4, yo + 4, 32, 32); g2.fill(s); return Printable.PAGE_EXISTS; }
From source file:MainClass.java
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { Graphics2D g2 = (Graphics2D) g; double w = pf.getImageableWidth(); double h = pf.getImageableHeight(); int xo = (int) pf.getImageableX(); int yo = (int) pf.getImageableY(); Rectangle2D r = new Rectangle2D.Double(xo, yo, w, h); g2.setColor(Color.red);/*w ww . ja v a 2 s . c o m*/ g2.draw(r); PrinterGraphics p = (PrinterGraphics) g2; String s = p.getPrinterJob().getJobName(); g2.setPaint(Color.black); g2.drawString(s, 0, 0); return Printable.PAGE_EXISTS; }