List of usage examples for java.awt.print Printable PAGE_EXISTS
int PAGE_EXISTS
To view the source code for java.awt.print Printable PAGE_EXISTS.
Click Source Link
From source file:MainClass.java
public static void main(String[] args) { try {/* w ww. ja v a2 s. c o m*/ PrinterJob pjob = PrinterJob.getPrinterJob(); pjob.setJobName("Graphics Demo Printout"); pjob.setCopies(1); pjob.setPrintable(new Printable() { public int print(Graphics pg, PageFormat pf, int pageNum) { if (pageNum > 0) // we only print one page return Printable.NO_SUCH_PAGE; // ie., end of job pg.drawString("www.java2s.com", 10, 10); return Printable.PAGE_EXISTS; } }); if (pjob.printDialog() == false) // choose printer return; pjob.print(); } catch (PrinterException pe) { pe.printStackTrace(); } }
From source file:BasicPrint.java
public int print(Graphics g, PageFormat pf, int pageIndex) { if (pageIndex > 0) { return Printable.NO_SUCH_PAGE; }/*from www . java 2 s. c o m*/ Graphics2D g2d = (Graphics2D) g; g2d.translate(pf.getImageableX(), pf.getImageableY()); drawGraphics(g2d, pf); return Printable.PAGE_EXISTS; }
From source file:PrintBook.java
public int print(Graphics g, PageFormat pf, int pageIndex) { drawGraphics(g, pf); return Printable.PAGE_EXISTS; }
From source file:ImagePrint.java
public int print(Graphics g, PageFormat pf, int pageIndex) { Graphics2D g2d = (Graphics2D) g; g.translate((int) (pf.getImageableX()), (int) (pf.getImageableY())); if (pageIndex == 0) { double pageWidth = pf.getImageableWidth(); double pageHeight = pf.getImageableHeight(); double imageWidth = printImage.getIconWidth(); double imageHeight = printImage.getIconHeight(); double scaleX = pageWidth / imageWidth; double scaleY = pageHeight / imageHeight; double scaleFactor = Math.min(scaleX, scaleY); g2d.scale(scaleFactor, scaleFactor); g.drawImage(printImage.getImage(), 0, 0, null); return Printable.PAGE_EXISTS; }//from w w w. ja v a 2 s . c o m return Printable.NO_SUCH_PAGE; }
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);/*w w w. ja v a2 s .c o 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 { System.out.println("Page index = " + pageIndex); // pageIndex 1 corresponds to page number 2. if (pageIndex > 2) return Printable.NO_SUCH_PAGE; 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 w ww . j a v a 2 s . c o m g2.draw(r); return Printable.PAGE_EXISTS; }
From source file:MainClass.java
public int print(Graphics g, PageFormat pageFormat, int pageIndex) { Enumeration printElements = pageContents.elements(); while (printElements.hasMoreElements()) { MyItem pe = (MyItem) printElements.nextElement(); pe.print(g);/*from w w w . j a v a2 s. com*/ } 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);/*from w w w. j a v a 2s .com*/ 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; }
From source file:PrintableComponent.java
/** * This is the "callback" method that the PrinterJob will invoke. * This method is defined by the Printable interface. */// w w w.j a v a2 s. c o m public int print(Graphics g, PageFormat format, int pagenum) { // The PrinterJob will keep trying to print pages until we return // this value to tell it that it has reached the end. if (pagenum > 0) return Printable.NO_SUCH_PAGE; // We're passed a Graphics object, but it can always be cast to Graphics2D Graphics2D g2 = (Graphics2D) g; // Use the top and left margins specified in the PageFormat Note // that the PageFormat methods are poorly named. They specify // margins, not the actual imageable area of the printer. g2.translate(format.getImageableX(), format.getImageableY()); // Tell the component to draw itself to the printer by passing in // the Graphics2D object. This will not work well if the component // has double-buffering enabled. c.paint(g2); // Return this constant to tell the PrinterJob that we printed the page. return Printable.PAGE_EXISTS; }
From source file:PrinterSettingUpDialogPrint.java
public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex >= 1) { return Printable.NO_SUCH_PAGE; }// w w w . j av a2 s . com Graphics2D g2D = (Graphics2D) g; canvas = new DrawingCanvas(); canvas.paintContent(g2D, (int) pageFormat.getImageableWidth(), (int) pageFormat.getImageableHeight()); return Printable.PAGE_EXISTS; }