Example usage for java.awt.print Printable NO_SUCH_PAGE

List of usage examples for java.awt.print Printable NO_SUCH_PAGE

Introduction

In this page you can find the example usage for java.awt.print Printable NO_SUCH_PAGE.

Prototype

int NO_SUCH_PAGE

To view the source code for java.awt.print Printable NO_SUCH_PAGE.

Click Source Link

Document

Returned from print to signify that the pageIndex is too large and that the requested page does not exist.

Usage

From source file:PrinterSettingUpDialogPrint.java

public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
    if (pageIndex >= 1) {
        return Printable.NO_SUCH_PAGE;
    }//from w w  w .  j  a va2  s . c om
    Graphics2D g2D = (Graphics2D) g;
    canvas = new DrawingCanvas();
    canvas.paintContent(g2D, (int) pageFormat.getImageableWidth(), (int) pageFormat.getImageableHeight());
    return Printable.PAGE_EXISTS;
}

From source file:PrintTest.java

public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
    if (page >= 1)
        return Printable.NO_SUCH_PAGE;
    Graphics2D g2 = (Graphics2D) g;
    g2.translate(pf.getImageableX(), pf.getImageableY());
    g2.draw(new Rectangle2D.Double(0, 0, pf.getImageableWidth(), pf.getImageableHeight()));

    drawPage(g2);/*from  www .j a v a  2  s  .  c o m*/
    return Printable.PAGE_EXISTS;
}

From source file:com.floreantpos.jasperreport.engine.print.JRPrinterAWT.java

/**
 *
 *//*from   w ww .  j  a  va  2s . com*/
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
    if (Thread.interrupted()) {
        throw new PrinterException("Current thread interrupted.");
    }

    pageIndex += pageOffset;

    if (pageIndex < 0 || pageIndex >= jasperPrint.getPages().size()) {
        return Printable.NO_SUCH_PAGE;
    }

    try {
        JRGraphics2DExporter exporter = new JRGraphics2DExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
        exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
        exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));
        exporter.exportReport();
    } catch (JRException e) {
        if (log.isDebugEnabled())
            log.debug("Print failed.", e);

        throw new PrinterException(e.getMessage());
    }

    return Printable.PAGE_EXISTS;
}

From source file:org.fhaes.fhfilechecker.FrameViewOutput.java

@Override
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {

    try {//from   w  w  w . j av a  2 s  .  c om
        // For catching IOException
        if (pageIndex != rememberedPageIndex) {
            // First time we've visited this page
            rememberedPageIndex = pageIndex;
            // If encountered EOF on previous page, done
            if (rememberedEOF) {
                return Printable.NO_SUCH_PAGE;
            }
            // Save current position in input file
            rememberedFilePointer = raf.getFilePointer();
        } else {
            raf.seek(rememberedFilePointer);
        }
        g.setColor(Color.black);
        g.setFont(fnt);
        int x = (int) pf.getImageableX() + 10;
        int y = (int) pf.getImageableY() + 12;
        // Title line
        g.drawString("File: " + fileName + ", page: " + (pageIndex + 1), x, y);
        // Generate as many lines as will fit in imageable area
        y += 36;
        while (y + 12 < pf.getImageableY() + pf.getImageableHeight()) {
            String line = raf.readLine();
            if (line == null) {
                rememberedEOF = true;
                break;
            }
            g.drawString(line, x, y);
            y += 12;
        }
        return Printable.PAGE_EXISTS;
    } catch (Exception e) {
        return Printable.NO_SUCH_PAGE;
    }
}

From source file:com.openbravo.pos.util.JRPrinterAWT411.java

/**
 *
 *///  w w  w  .j a v a2  s .c  o m
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
    if (Thread.currentThread().isInterrupted()) {
        throw new PrinterException("Current thread interrupted.");
    }

    pageIndex += pageOffset;

    if (pageIndex < 0 || pageIndex >= jasperPrint.getPages().size()) {
        return Printable.NO_SUCH_PAGE;
    }

    try {
        JRGraphics2DExporter exporter = new JRGraphics2DExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
        exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
        exporter.setParameter(JRExporterParameter.PAGE_INDEX, Integer.valueOf(pageIndex));
        exporter.exportReport();
    } catch (JRException e) {
        if (log.isDebugEnabled()) {
            log.debug("Print failed.", e);
        }

        throw new PrinterException(e.getMessage()); //NOPMD
    }

    return Printable.PAGE_EXISTS;
}

From source file:BookTest.java

public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
    Graphics2D g2 = (Graphics2D) g;
    if (page > getPageCount(g2, pf))
        return Printable.NO_SUCH_PAGE;
    g2.translate(pf.getImageableX(), pf.getImageableY());

    drawPage(g2, pf, page);/*  w w w  . j a  v a2 s .c  om*/
    return Printable.PAGE_EXISTS;
}

From source file:com.openbravo.pos.util.JRPrinterAWT.java

/**
 *
 *//*from  w  ww .ja  v a2  s  . com*/
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
    if (Thread.currentThread().isInterrupted()) {
        throw new PrinterException("Current thread interrupted.");
    }

    pageIndex += pageOffset;

    if (pageIndex < 0 || pageIndex >= jasperPrint.getPages().size()) {
        return Printable.NO_SUCH_PAGE;
    }

    try {
        JRGraphics2DExporter exporter = new JRGraphics2DExporter(jasperReportsContext);
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
        exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
        exporter.setParameter(JRExporterParameter.PAGE_INDEX, Integer.valueOf(pageIndex));
        exporter.exportReport();
    } catch (JRException e) {
        if (log.isDebugEnabled()) {
            log.debug("Print failed.", e);
        }

        throw new PrinterException(e.getMessage()); //NOPMD
    }

    return Printable.PAGE_EXISTS;
}

From source file:com.alvermont.terraj.util.io.ImagePrinter.java

/**
 * Render an image for printing./* w  w  w  . ja  va 2  s  .c o m*/
 *
 * @param graphics The graphics context to print on
 * @param pageFormat The page format being used
 * @param pageIndex The page being printed
 * @throws java.awt.print.PrinterException If there is an error in printing
 * @return An indication of the result of page rendering for this page
 */
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
    final Graphics2D g2 = (Graphics2D) graphics;

    // we only expect to be printing 1 page as the image is scaled
    if (pageIndex >= 1) {
        return Printable.NO_SUCH_PAGE;
    }

    // translate the coordinate system to match up the image with 
    // the printable area
    g2.translate(getFormat().getImageableX(), pageFormat.getImageableY());

    final Rectangle componentBounds = new Rectangle(getImage().getWidth(), getImage().getHeight());
    g2.translate(-componentBounds.x, -componentBounds.y);

    // scale the image to fit
    scaleToFit(true);
    g2.scale(getScaleX(), getScaleY());

    // render the image
    g2.drawImage(getImage(), null, 0, 0);

    // done
    return Printable.PAGE_EXISTS;
}

From source file:net.sf.jasperreports.engine.print.JRPrinterAWT.java

/**
 *
 *///from  ww  w. jav a2 s .  c om
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
    if (Thread.interrupted()) {
        throw new PrinterException("Current thread interrupted.");
    }

    pageIndex += pageOffset;

    if (pageIndex < 0 || pageIndex >= jasperPrint.getPages().size()) {
        return Printable.NO_SUCH_PAGE;
    }

    try {
        JRGraphics2DExporter exporter = new JRGraphics2DExporter(jasperReportsContext);
        exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
        SimpleGraphics2DExporterOutput output = new SimpleGraphics2DExporterOutput();
        output.setGraphics2D((Graphics2D) graphics);
        exporter.setExporterOutput(output);
        SimpleGraphics2DReportConfiguration configuration = new SimpleGraphics2DReportConfiguration();
        configuration.setPageIndex(pageIndex);
        exporter.setConfiguration(configuration);
        exporter.exportReport();
    } catch (JRException e) {
        if (log.isDebugEnabled()) {
            log.debug("Print failed.", e);
        }

        throw new PrinterException(e.getMessage()); //NOPMD
    }

    return Printable.PAGE_EXISTS;
}

From source file:com.l3.info.magenda.emplois_du_temps.EmploisDuTemps.java

@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
    // Par dfaut, retourne NO_SUCH_PAGE => la page n'existe pas
    int code_retour = Printable.NO_SUCH_PAGE;
    System.out.println(pageIndex);
    // Rcuprer l'ensemble des cls de la liste
    for (Semaine sem : value) {
        //sem.get_nbr_page();
    }/*from  w w w .ja  v a 2  s . com*/
    if (value.size() > pageIndex) {
        value.get(pageIndex).paint(graphics);
        // La page est valide
        code_retour = Printable.PAGE_EXISTS;
    }
    // Rcupre la dimension de la zone imprimable
    //double xLeft  = pageFormat.getImageableX();
    //double yTop   = pageFormat.getImageableY();
    //double width  = pageFormat.getImageableWidth();
    //double height = pageFormat.getImageableHeight();

    return code_retour;
}