Package java.awt.print

Examples of java.awt.print.Printable


    public void redrawRegion(Rectangle2D region, double scaleX, double scaleY,
                             Shape savedClip, AffineTransform savedTransform)
            throws PrinterException {

        WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
        Printable painter = getPrintable();
        PageFormat pageFormat = getPageFormat();
        int pageIndex = getPageIndex();

        /* Create a buffered image big enough to hold the portion
         * of the source image being printed.
         */
        BufferedImage deepImage = new BufferedImage(
                                        (int) region.getWidth(),
                                        (int) region.getHeight(),
                                        BufferedImage.TYPE_3BYTE_BGR);

        /* Get a graphics for the application to render into.
         * We initialize the buffer to white in order to
         * match the paper and then we shift the BufferedImage
         * so that it covers the area on the page where the
         * caller's Image will be drawn.
         */
        Graphics2D g = deepImage.createGraphics();
        ProxyGraphics2D proxy = new ProxyGraphics2D(g, wPrinterJob);
        proxy.setColor(Color.white);
        proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
        proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());

        proxy.translate(-region.getX(), -region.getY());

        /* Calculate the resolution of the source image.
         */
        float sourceResX = (float)(wPrinterJob.getXRes() / scaleX);
        float sourceResY = (float)(wPrinterJob.getYRes() / scaleY);

        /* The application expects to see user space at 72 dpi.
         * so change user space from image source resolution to
         *  72 dpi.
         */
        proxy.scale(sourceResX / DEFAULT_USER_RES,
                    sourceResY / DEFAULT_USER_RES);

        proxy.translate(
            -wPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
               / wPrinterJob.getXRes() * DEFAULT_USER_RES,
            -wPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
               / wPrinterJob.getYRes() * DEFAULT_USER_RES);
        /* NB User space now has to be at 72 dpi for this calc to be correct */
        proxy.transform(new AffineTransform(getPageFormat().getMatrix()));
        proxy.setPaint(Color.black);

        painter.print(proxy, pageFormat, pageIndex);

        g.dispose();

        /* We need to set the device clip using saved information.
         * savedClip intersects the user clip with a clip that restricts
View Full Code Here


                    image = readImage(url.openStream());
                } catch (IOException ioe) {
                    throw new PrintException(ioe);
                }
            } else if (docflavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)){
                Printable printable = (Printable)data;
                print(printable, null);
            } else if (docflavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE)) {
                Pageable pageable = (Pageable)data;
                print(null, pageable);
            } else {
View Full Code Here

        if (psDocument != null) {
            pages = psDocument.getNumberOfPages();
        }
        do {
            try {
                Printable page = null;
                PageFormat pageFormat = null;
                result = -1;
                if (psPrintable != null) {
                    page = psPrintable;
                    pageFormat = format;
                    result = psPrintable.print(fake, format, iPage);
                } else {
                    if (pages != Pageable.UNKNOWN_NUMBER_OF_PAGES &&
                        iPage >= pages) {
                        break;
                    }
                    page = psDocument.getPrintable(iPage);
                    pageFormat = psDocument.getPageFormat(iPage);
                    if (page != null) {
                        result = page.print(fake, pageFormat, iPage);
                    } else {
                        throw new PrinterException("No printable for page " +
                                iPage + " in given document.");
                    }
                }
                if (result == Printable.PAGE_EXISTS) {
                    converter.startPage(iPage + 1);
                    result = page.print(converter, pageFormat, iPage);
                    converter.endOfPage(iPage + 1);
                }
            } catch (PrinterException pe) {
                converter.finish();
                throw new PrintException(pe.getMessage());
View Full Code Here

                    image = readImage(url.openStream());
                } catch (IOException ioe) {
                    throw new PrintException(ioe);
                }
            } else if (docflavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)){
                Printable printable = (Printable)data;
                print(printable, null);
            } else if (docflavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE)) {
                Pageable pageable = (Pageable)data;
                print(null, pageable);
            } else {
View Full Code Here

        if (psDocument != null) {
            pages = psDocument.getNumberOfPages();
        }
        do {
            try {
                Printable page = null;
                PageFormat pageFormat = null;
                result = -1;
                if (psPrintable != null) {
                    page = psPrintable;
                    pageFormat = format;
                    result = psPrintable.print(fake, format, iPage);
                } else {
                    if (pages != Pageable.UNKNOWN_NUMBER_OF_PAGES &&
                        iPage >= pages) {
                        break;
                    }
                    page = psDocument.getPrintable(iPage);
                    pageFormat = psDocument.getPageFormat(iPage);
                    if (page != null) {
                        result = page.print(fake, pageFormat, iPage);
                    } else {
                        throw new PrinterException("No printable for page " +
                                iPage + " in given document.");
                    }
                }
                if (result == Printable.PAGE_EXISTS) {
                    converter.startPage(iPage + 1);
                    result = page.print(converter, pageFormat, iPage);
                    converter.endOfPage(iPage + 1);
                }
            } catch (PrinterException pe) {
                converter.finish();
                throw new PrintException(pe.getMessage());
View Full Code Here

                    image = readImage(url.openStream());
                } catch (IOException ioe) {
                    throw new PrintException(ioe);
                }
            } else if (docflavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)){
                Printable printable = (Printable)data;
                print(printable, null);
            } else if (docflavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE)) {
                Pageable pageable = (Pageable)data;
                print(null, pageable);
            } else {
View Full Code Here

        if (psDocument != null) {
            pages = psDocument.getNumberOfPages();
        }
        do {
            try {
                Printable page = null;
                PageFormat pageFormat = null;
                result = -1;
                if (psPrintable != null) {
                    page = psPrintable;
                    pageFormat = format;
                    result = psPrintable.print(fake, format, iPage);
                } else {
                    if (pages != Pageable.UNKNOWN_NUMBER_OF_PAGES &&
                        iPage >= pages) {
                        break;
                    }
                    page = psDocument.getPrintable(iPage);
                    pageFormat = psDocument.getPageFormat(iPage);
                    if (page != null) {
                        result = page.print(fake, pageFormat, iPage);
                    } else {
                        throw new PrinterException("No printable for page " +
                                iPage + " in given document.");
                    }
                }
                if (result == Printable.PAGE_EXISTS) {
                    converter.startPage(iPage + 1);
                    result = page.print(converter, pageFormat, iPage);
                    converter.endOfPage(iPage + 1);
                }
            } catch (PrinterException pe) {
                converter.finish();
                throw new PrintException(pe.getMessage());
View Full Code Here

                        throws PrintException {
            final long pdc = WinPrinterFactory.getPrinterDC(
                            service.printerName, service.getPrinterProps()
                                            .getStructPtr());
            final AttributeSet docAttrs = doc.getAttributes();
            final Printable printable = castDoc(doc, Printable.class);
            final PageFormat format = getPageFormat(docAttrs, attributes);
            final PageRanges ranges = getAttribute(PageRanges.class, docAttrs,
                            attributes);
            int res = Printable.PAGE_EXISTS;
View Full Code Here

                for (int i = 0; i < pages; i++) {
                    if ((ranges != null) && !ranges.contains(i)) {
                        continue;
                    }

                    final Printable printable = pageable.getPrintable(i);
                    final PageFormat format = null;

                    if (printable == null) {
                        throw new PrintException("No such page: " + i); //$NON-NLS-1$
                    }
View Full Code Here

        public void Invoke(Object paramObject, PrintPageEventArgs ev){

            try{
              int realPage = pageRanges.getPageForIndex(pageIndex);
             
                Printable printable = pageable.getPrintable(realPage);
                PageFormat pageFormat = pageable.getPageFormat(realPage);

               
                BufferedImage pBand = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR);
                Graphics2D imageGraphics = pBand.createGraphics();
                ((RasterPrinterJob)job).setGraphicsConfigInfo(imageGraphics.getTransform(), pageFormat.getImageableWidth(), pageFormat.getImageableHeight());
        PeekGraphics peekGraphics = new PeekGraphics(imageGraphics, job );

                /*
                 * Because Sun is calling first with a PeekGraphics that we do it else for compatibility
                 */
                if(realPage == 0){
                    int pageResult = printable.print(peekGraphics, pageFormat, realPage);
                    if(pageResult != Printable.PAGE_EXISTS){
                        ev.set_HasMorePages(false);
                        ev.set_Cancel(true);
                        return;
                    }
                }
                Graphics printGraphics = peer.createGraphics(ev.get_Graphics());
                if( printGraphics instanceof Graphics2D ){
                  Graphics2D g2d = ((Graphics2D)printGraphics);
                  int tX = (int) pageFormat.getWidth();
                  int tY = (int) pageFormat.getHeight();
                  // apply Java to .NET scaling (1/72 inch to 1/100 inch)
                  g2d.scale(100d/72d, 100d/72d);
                  // NOTE on Landscape printing:
                  // Setting landscape to true on the printer settings
                  // of a page already rotates the page! The orig. java code rotates the page itself,
                  // for .NET this is not required.
                  if( orient == OrientationRequested.REVERSE_LANDSCAPE){
                    g2d.translate( tX, tY );
                    g2d.rotate( Math.PI );
                  }
                }
                printable.print(printGraphics, pageFormat, realPage);
               
                realPage = pageRanges.getPageForIndex(++pageIndex);
                if( realPage >= 0 ){
                  printable = pageable.getPrintable(realPage);
                  pageFormat = pageable.getPageFormat(realPage);
                  int pageResult = printable.print(peekGraphics, pageFormat, realPage);
                  if( pageResult == Printable.PAGE_EXISTS ){
                    ev.set_HasMorePages( true );
                  } else {
                    if( pageRanges.checkJobComplete(pageIndex) ){
                      ev.set_HasMorePages( false );
View Full Code Here

TOP

Related Classes of java.awt.print.Printable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.