java.awt.print.PageFormat Java Examples

The following examples show how to use java.awt.print.PageFormat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WrongPaperForBookPrintingTest.java    From openjdk-jdk8u with GNU General Public License v2.0 7 votes vote down vote up
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    Book pageable = new Book();
    pageable.append(new WrongPaperForBookPrintingTest(), pf);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPageable(pageable);
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
Example #2
Source File: ChartComposite.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Not implemented.
 *
 * @param graphics  the graphics.
 * @param pageFormat  the page format.
 * @param pageIndex  the page index.
 *
 * @return ?.
 *
 * @throws PrinterException if there is a problem.
 */
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
    throws PrinterException {
    if (pageIndex != 0) {
        return NO_SUCH_PAGE;
    }
    /*
    CairoImage image = new CairoImage(
            this.getBounds().width, this.getBounds().height);
    Graphics2D g2 = image.createGraphics2D();
    double x = pageFormat.getImageableX();
    double y = pageFormat.getImageableY();
    double w = pageFormat.getImageableWidth();
    double h = pageFormat.getImageableHeight();
    this.chart.draw(
        g2, new Rectangle2D.Double(x, y, w, h), this.anchor, null
    );
    */
    return PAGE_EXISTS;
}
 
Example #3
Source File: RasterPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page,
        double w, double h) {
    double ix, iw, iy, ih;
        if (w >= 72.0 * 6.0) {
            ix = 72.0;
            iw = w - 2 * 72.0;
        } else {
            ix = w / 6.0;
            iw = w * 0.75;
        }
        if (h >= 72.0 * 6.0) {
            iy = 72.0;
            ih = h - 2 * 72.0;
        } else {
            iy = h / 6.0;
            ih = h * 0.75;
        }

    return new MediaPrintableArea((float) (ix / DPI), (float) (iy / DPI),
            (float) (iw / DPI), (float) (ih / DPI), MediaPrintableArea.INCH);
}
 
Example #4
Source File: SnapshotTool.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
public void print() {
  PrinterJob printerJob = PrinterJob.getPrinterJob();
  PageFormat format = new PageFormat();
  java.awt.print.Book book = new java.awt.print.Book();
  book.append(this, format);
  printerJob.setPageable(book);
  if(printerJob.printDialog()) {
    try {
      printerJob.print();
    } catch(PrinterException pe) {
      // JOptionPane.showMessageDialog(c,
      // TrackerRes.getString("TActions.Dialog.PrintError.Message"), //$NON-NLS-1$
      // TrackerRes.getString("TActions.Dialog.PrintError.Title"), //$NON-NLS-1$
      // JOptionPane.ERROR_MESSAGE);
    }
  }
}
 
Example #5
Source File: RasterPrinterJob.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page,
        double w, double h) {
    double ix, iw, iy, ih;
        if (w >= 72.0 * 6.0) {
            ix = 72.0;
            iw = w - 2 * 72.0;
        } else {
            ix = w / 6.0;
            iw = w * 0.75;
        }
        if (h >= 72.0 * 6.0) {
            iy = 72.0;
            ih = h - 2 * 72.0;
        } else {
            iy = h / 6.0;
            ih = h * 0.75;
        }

    return new MediaPrintableArea((float) (ix / DPI), (float) (iy / DPI),
            (float) (iw / DPI), (float) (ih / DPI), MediaPrintableArea.INCH);
}
 
Example #6
Source File: WeirdLayoutIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testLayout() throws ResourceException, ContentProcessingException, ReportProcessingException {
  final MasterReport basereport = new MasterReport();
  basereport.setPageDefinition( new SimplePageDefinition( new PageFormat() ) );

  final URL target = WeirdLayoutIT.class.getResource( "weird-layouting.xml" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  final Band band = report.getReportHeader();
  band.setName( "ReportHeader1" );

  DebugReportRunner.layoutSingleBand( report, band, false, true );

}
 
Example #7
Source File: ExpressionTestBase.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected MasterReport createRelationalReport( final TableModel tableModel, final String... additionalFields ) {
  final MasterReport report = new MasterReport();
  report.setPageDefinition( new SimplePageDefinition( PageSize.A3, PageFormat.LANDSCAPE, new Insets( 0, 0, 0, 0 ) ) );
  report.setDataFactory( new TableDataFactory( "query", tableModel ) );
  report.setQuery( "query" );
  final DesignTimeDataSchemaModel dataSchemaModel = new DesignTimeDataSchemaModel( report );

  final RelationalReportBuilder builder = new RelationalReportBuilder( dataSchemaModel );
  builder.addGroup( ROW_DIMENSION_A );
  builder.addGroup( ROW_DIMENSION_B );
  builder.addGroup( COLUMN_DIMENSION_A );
  builder.addGroup( COLUMN_DIMENSION_B );
  builder.addDetails( VALUE, null, Color.lightGray );
  builder.addDetails( "relational", null, Color.yellow );
  for ( int i = 0; i < additionalFields.length; i++ ) {
    String additionalField = additionalFields[i];
    builder.addDetails( additionalField, null, null );
  }

  report.setRootGroup( builder.create() );
  return report;
}
 
Example #8
Source File: MinChunkWidthIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testMinChunkWidth() throws Exception {
  if ( DebugReportRunner.isSafeToTestComplexText() == false ) {
    return;
  }

  final MasterReport basereport = new MasterReport();
  basereport.setPageDefinition( new SimplePageDefinition( new PageFormat() ) );
  basereport.setCompatibilityLevel( null );
  basereport.getReportConfiguration().setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY,
      "true" );

  final URL target = LayoutIT.class.getResource( "min-chunkwidth.xml" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.getStyle().setStyleProperty( TextStyleKeys.WORDBREAK, true );

  final LogicalPageBox logicalPageBox =
      DebugReportRunner.layoutSingleBand( basereport, report.getReportHeader(), true, false );
  // simple test, we assert that all paragraph-poolboxes are on either 485 or 400
  // and that only two lines exist for each
  ModelPrinter.INSTANCE.print( logicalPageBox );
  new ValidateRunner( false, true ).startValidation( logicalPageBox );
}
 
Example #9
Source File: ChartPanel.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a print job for the chart.
 */
public void createChartPrintJob() {
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pf = job.defaultPage();
    PageFormat pf2 = job.pageDialog(pf);
    if (pf2 != pf) {
        job.setPrintable(this, pf2);
        if (job.printDialog()) {
            try {
                job.print();
            }
            catch (PrinterException e) {
                JOptionPane.showMessageDialog(this, e);
            }
        }
    }
}
 
Example #10
Source File: ChartPanel.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a print job for the chart.
 */
public void createChartPrintJob() {
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pf = job.defaultPage();
    PageFormat pf2 = job.pageDialog(pf);
    if (pf2 != pf) {
        job.setPrintable(this, pf2);
        if (job.printDialog()) {
            try {
                job.print();
            }
            catch (PrinterException e) {
                JOptionPane.showMessageDialog(this, e);
            }
        }
    }
}
 
Example #11
Source File: DlgAttrsBug.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public int print(Graphics g, PageFormat pf, int pi)
        throws PrinterException {
    System.out.println("pi = " + pi);
    if (pi >= 5) {
        return NO_SUCH_PAGE;
    }
    g.drawString("Page : " + (pi+1), 200, 200);
    return PAGE_EXISTS;
}
 
Example #12
Source File: MasterReport.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private PageDefinition createDefaultPageDefinition() {
  final PageDefinition format;
  final ExtendedConfiguration config = ClassicEngineBoot.getInstance().getExtendedConfig();
  if ( config.getBoolProperty( ClassicEngineCoreModule.NO_PRINTER_AVAILABLE_KEY ) ) {
    format = new SimplePageDefinition( new PageFormat() );
  } else {
    format = new SimplePageDefinition( PrinterJob.getPrinterJob().defaultPage() );
  }
  return format;
}
 
Example #13
Source File: PrintDocument.java    From DiskBrowser with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int print (Graphics g, PageFormat pageFormat, int page)
// ---------------------------------------------------------------------------------//
{
  Graphics2D g2 = (Graphics2D) g;
  if (lineHeight == 0)
  {
    LineMetrics lm = font.getLineMetrics ("0", g2.getFontRenderContext ());
    lineHeight = (int) lm.getHeight ();
    linesPerPage = (int) pageFormat.getImageableHeight () / lineHeight - 5;
    pages = (lines.length - 1) / linesPerPage;
  }

  if (pages < page)
    return Printable.NO_SUCH_PAGE;

  g2.translate (pageFormat.getImageableX (), pageFormat.getImageableY ());
  g2.setPaint (Color.black);
  g2.setStroke (new BasicStroke (2));

  g2.setFont (font);

  int first = page * linesPerPage;
  int last = first + linesPerPage;
  if (last > lines.length)
    last = lines.length;

  for (int line = first; line < last; line++)
    g2.drawString (lines[line], x, y + (line % linesPerPage + 2) * lineHeight);

  return (PAGE_EXISTS);
}
 
Example #14
Source File: ClusterViewer.java    From megan-ce with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Print the graph associated with this viewer.
 *
 * @param gc0        the graphics context.
 * @param format     page format
 * @param pagenumber page index
 */
public int print(Graphics gc0, PageFormat format, int pagenumber) throws PrinterException {
    JPanel panel = getPanel();

    if (panel != null && pagenumber == 0) {
        if (panel instanceof GraphView) {
            return ((GraphView) panel).print(gc0, format, pagenumber);
        } else {
            Graphics2D gc = ((Graphics2D) gc0);
            Dimension dim = panel.getSize();
            int image_w = dim.width;
            int image_h = dim.height;

            double paper_x = format.getImageableX() + 1;
            double paper_y = format.getImageableY() + 1;
            double paper_w = format.getImageableWidth() - 2;
            double paper_h = format.getImageableHeight() - 2;

            double scale_x = paper_w / image_w;
            double scale_y = paper_h / image_h;
            double scale = Math.min(scale_x, scale_y);

            double shift_x = paper_x + (paper_w - scale * image_w) / 2.0;
            double shift_y = paper_y + (paper_h - scale * image_h) / 2.0;

            gc.translate(shift_x, shift_y);
            gc.scale(scale, scale);

            panel.print(gc0);
            return Printable.PAGE_EXISTS;
        }
    }
    return Printable.NO_SUCH_PAGE;
}
 
Example #15
Source File: ImagePrinter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public int print(Graphics g, PageFormat pf, int index) {

        if (index > 0 || image == null) {
            return Printable.NO_SUCH_PAGE;
        }

        ((Graphics2D)g).translate(pf.getImageableX(), pf.getImageableY());
        int w = image.getWidth(null);
        int h = image.getHeight(null);
        int iw = (int)pf.getImageableWidth();
        int ih = (int)pf.getImageableHeight();

        // ensure image will fit
        int dw = w;
        int dh = h;
        if (dw > iw) {
            dh = (int)(dh * ( (float) iw / (float) dw)) ;
            dw = iw;
        }
        if (dh > ih) {
            dw = (int)(dw * ( (float) ih / (float) dh)) ;
            dh = ih;
        }
        // centre on page
        int dx = (iw - dw) / 2;
        int dy = (ih - dh) / 2;

        g.drawImage(image, dx, dy, dx+dw, dy+dh, 0, 0, w, h, null);
        return Printable.PAGE_EXISTS;
    }
 
Example #16
Source File: PSPrinterJob.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public PageFormat getPageFormat(int pgIndex) {
    if (pgIndex > 0) {
        throw new IndexOutOfBoundsException("pgIndex");
    } else {
        return pf;
    }
}
 
Example #17
Source File: ImagePrinter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public int print(Graphics g, PageFormat pf, int index) {

        if (index > 0 || image == null) {
            return Printable.NO_SUCH_PAGE;
        }

        ((Graphics2D)g).translate(pf.getImageableX(), pf.getImageableY());
        int w = image.getWidth(null);
        int h = image.getHeight(null);
        int iw = (int)pf.getImageableWidth();
        int ih = (int)pf.getImageableHeight();

        // ensure image will fit
        int dw = w;
        int dh = h;
        if (dw > iw) {
            dh = (int)(dh * ( (float) iw / (float) dw)) ;
            dw = iw;
        }
        if (dh > ih) {
            dw = (int)(dw * ( (float) ih / (float) dh)) ;
            dh = ih;
        }
        // centre on page
        int dx = (iw - dw) / 2;
        int dy = (ih - dh) / 2;

        g.drawImage(image, dx, dy, dx+dw, dy+dh, 0, 0, w, h, null);
        return Printable.PAGE_EXISTS;
    }
 
Example #18
Source File: PrintJob2D.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints the page at the specified index into the specified
 * {@link Graphics} context in the specified
 * format.  A <code>PrinterJob</code> calls the
 * <code>Printable</code> interface to request that a page be
 * rendered into the context specified by
 * <code>graphics</code>.  The format of the page to be drawn is
 * specified by <code>pageFormat</code>.  The zero based index
 * of the requested page is specified by <code>pageIndex</code>.
 * If the requested page does not exist then this method returns
 * NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned.
 * The <code>Graphics</code> class or subclass implements the
 * {@link PrinterGraphics} interface to provide additional
 * information.  If the <code>Printable</code> object
 * aborts the print job then it throws a {@link PrinterException}.
 * @param graphics the context into which the page is drawn
 * @param pageFormat the size and orientation of the page being drawn
 * @param pageIndex the zero based index of the page to be drawn
 * @return PAGE_EXISTS if the page is rendered successfully
 *         or NO_SUCH_PAGE if <code>pageIndex</code> specifies a
 *         non-existent page.
 * @exception java.awt.print.PrinterException
 *         thrown when the print job is terminated.
 */
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
             throws PrinterException {

    int result;

    /* This method will be called by the PrinterJob on a thread other
     * that the application's thread. We hold on to the graphics
     * until we can rendevous with the application's thread and
     * hand over the graphics. The application then does all the
     * drawing. When the application is done drawing we rendevous
     * again with the PrinterJob thread and release the Graphics
     * so that it knows we are done.
     */

    /* Add the graphics to the message queue of graphics to
     * be rendered. This is really a one slot queue. The
     * application's thread will come along and remove the
     * graphics from the queue when the app asks for a graphics.
     */
    graphicsToBeDrawn.append( (Graphics2D) graphics);

    /* We now wait for the app's thread to finish drawing on
     * the Graphics. This thread will sleep until the application
     * release the graphics by placing it in the graphics drawn
     * message queue. If the application signals that it is
     * finished drawing the entire document then we'll get null
     * returned when we try and pop a finished graphic.
     */
    if (graphicsDrawn.pop() != null) {
        result = PAGE_EXISTS;
    } else {
        result = NO_SUCH_PAGE;
    }

    return result;
}
 
Example #19
Source File: bug8023392.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public int print(Graphics graphics,
                 PageFormat pageFormat,
                 int pageIndex)
        throws PrinterException {
    if (pageIndex >= 1) {
        return Printable.NO_SUCH_PAGE;
    }

    this.paint(graphics);
    return Printable.PAGE_EXISTS;
}
 
Example #20
Source File: PaddingIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testFailure() throws Exception {
  final MasterReport basereport = new MasterReport();
  basereport.setPageDefinition( new SimplePageDefinition( new PageFormat() ) );
  final MasterReport report = createReport();
  final LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( basereport, report.getReportHeader() );
  // simple test, we assert that all paragraph-poolboxes are on either 485000 or 400000
  // and that only two lines exist for each
  // ModelPrinter.print(logicalPageBox);

}
 
Example #21
Source File: DlgAttrsBug.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public int print(Graphics g, PageFormat pf, int pi)
        throws PrinterException {
    System.out.println("pi = " + pi);
    if (pi >= 5) {
        return NO_SUCH_PAGE;
    }
    g.drawString("Page : " + (pi+1), 200, 200);
    return PAGE_EXISTS;
}
 
Example #22
Source File: PrintPageDirect.java    From haxademic with MIT License 5 votes vote down vote up
/**
 * Method: print
 * <p>
 * 
 * @param g
 *            a value of type Graphics
 * @param pageFormat
 *            a value of type PageFormat
 * @param page
 *            a value of type int
 * @return a value of type int
 */
public int print(Graphics g, PageFormat pageFormat, int page) {

	//--- Create the Graphics2D object
	Graphics2D g2d = (Graphics2D) g;

	//--- Translate the origin to 0,0 for the top left corner
	g2d.translate(pageFormat.getImageableX(), pageFormat
			.getImageableY());

	//--- Set the default drawing color to black
	g2d.setPaint(Color.black);

	//--- Draw a border arround the page
	Rectangle2D.Double border = new Rectangle2D.Double(0, 0, pageFormat
			.getImageableWidth(), pageFormat.getImageableHeight());
	g2d.draw(border);

	//--- Print the title
	String titleText = "Printing in Java Part 2";
	Font titleFont = new Font("helvetica", Font.BOLD, 36);
	g2d.setFont(titleFont);

	//--- Compute the horizontal center of the page
	FontMetrics fontMetrics = g2d.getFontMetrics();
	double titleX = (pageFormat.getImageableWidth() / 2)
			- (fontMetrics.stringWidth(titleText) / 2);
	double titleY = 3 * POINTS_PER_INCH;
	g2d.drawString(titleText, (int) titleX, (int) titleY);

	return (PAGE_EXISTS);
}
 
Example #23
Source File: RasterPrinterJob.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected void updatePageAttributes(PrintService service,
                                    PageFormat page) {
    if (this.attributes == null) {
        this.attributes = new HashPrintRequestAttributeSet();
    }

    updateAttributesWithPageFormat(service, page, this.attributes);
}
 
Example #24
Source File: PathGraphics.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected PathGraphics(Graphics2D graphics, PrinterJob printerJob,
                       Printable painter, PageFormat pageFormat,
                       int pageIndex, boolean canRedraw) {
    super(graphics, printerJob);

    mPainter = painter;
    mPageFormat = pageFormat;
    mPageIndex = pageIndex;
    mCanRedraw = canRedraw;
}
 
Example #25
Source File: PrintJob2D.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Prints the page at the specified index into the specified
 * {@link Graphics} context in the specified
 * format.  A {@code PrinterJob} calls the
 * {@code Printable} interface to request that a page be
 * rendered into the context specified by
 * {@code graphics}.  The format of the page to be drawn is
 * specified by {@code pageFormat}.  The zero based index
 * of the requested page is specified by {@code pageIndex}.
 * If the requested page does not exist then this method returns
 * NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned.
 * The {@code Graphics} class or subclass implements the
 * {@link java.awt.PrintGraphics} interface to provide additional
 * information.  If the {@code Printable} object
 * aborts the print job then it throws a {@link PrinterException}.
 * @param graphics the context into which the page is drawn
 * @param pageFormat the size and orientation of the page being drawn
 * @param pageIndex the zero based index of the page to be drawn
 * @return PAGE_EXISTS if the page is rendered successfully
 *         or NO_SUCH_PAGE if {@code pageIndex} specifies a
 *         non-existent page.
 * @exception java.awt.print.PrinterException
 *         thrown when the print job is terminated.
 */
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
             throws PrinterException {

    int result;

    /* This method will be called by the PrinterJob on a thread other
     * that the application's thread. We hold on to the graphics
     * until we can rendevous with the application's thread and
     * hand over the graphics. The application then does all the
     * drawing. When the application is done drawing we rendevous
     * again with the PrinterJob thread and release the Graphics
     * so that it knows we are done.
     */

    /* Add the graphics to the message queue of graphics to
     * be rendered. This is really a one slot queue. The
     * application's thread will come along and remove the
     * graphics from the queue when the app asks for a graphics.
     */
    graphicsToBeDrawn.append( (Graphics2D) graphics);

    /* We now wait for the app's thread to finish drawing on
     * the Graphics. This thread will sleep until the application
     * release the graphics by placing it in the graphics drawn
     * message queue. If the application signals that it is
     * finished drawing the entire document then we'll get null
     * returned when we try and pop a finished graphic.
     */
    if (graphicsDrawn.pop() != null) {
        result = PAGE_EXISTS;
    } else {
        result = NO_SUCH_PAGE;
    }

    return result;
}
 
Example #26
Source File: bug8023392.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public int print(Graphics graphics,
                 PageFormat pageFormat,
                 int pageIndex)
        throws PrinterException {
    if (pageIndex >= 1) {
        return Printable.NO_SUCH_PAGE;
    }

    this.paint(graphics);
    return Printable.PAGE_EXISTS;
}
 
Example #27
Source File: Printer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public int print(Graphics g, PageFormat pageFormat, int index) throws PrinterException {
//out("PAPER IS: " + myPapers.size());
        if (index == myPapers.size()) {
            return NO_SUCH_PAGE;
        }
//out("  print: " + index);
        myPapers.get(index).print(g);

        return PAGE_EXISTS;
    }
 
Example #28
Source File: PageFormatPreviewPane.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void draw( final Graphics2D graphics, final Rectangle2D bounds ) {
  final PageFormat gpf = getPageFormat();

  final Rectangle2D.Double imageableArea =
      new Rectangle2D.Double( gpf.getImageableX(), gpf.getImageableY(), gpf.getImageableWidth(), gpf
          .getImageableHeight() );
  graphics.setPaint( new Color( 225, 225, 225 ) );
  graphics.fill( imageableArea );
  graphics.setPaint( Color.gray );
  graphics.draw( imageableArea );

  final int pcH = pageDefinition.getPageCountHorizontal();
  final int pcW = pageDefinition.getPageCountVertical();

  final Line2D line = new Line2D.Double();
  for ( int splitH = 1; splitH < pcH; splitH += 1 ) {
    final double xPos = gpf.getImageableX() + ( splitH * gpf.getImageableWidth() );
    line.setLine( xPos, gpf.getImageableY(), xPos, gpf.getImageableY() + gpf.getImageableHeight() );
    graphics.draw( line );
  }

  for ( int splitW = 1; splitW < pcW; splitW += 1 ) {
    final double yPos = gpf.getImageableY() + ( splitW * gpf.getImageableHeight() );
    line.setLine( gpf.getImageableX(), yPos, gpf.getImageableX() + gpf.getImageableWidth(), yPos );
    graphics.draw( line );
  }
}
 
Example #29
Source File: PrintPageDirectNew.java    From haxademic with MIT License 5 votes vote down vote up
public int print(Graphics g, PageFormat pageFormat, int page) {
	// Create the Graphics2D object, Translate the origin to 0,0 for the top left corner, Set the default drawing color to black
	Graphics2D g2d = (Graphics2D) g;
	g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
	g2d.setPaint(Color.black);
	
	// Print the full-page PImage by converting to native BufferedImage
	P.out("PageFormat size: ", (int) pageFormat.getImageableWidth(), (int) pageFormat.getImageableHeight());
	g2d.drawImage((BufferedImage) printBuffer.getNative(), 0, 0, (int) pageFormat.getImageableWidth(), (int) pageFormat.getImageableHeight(), null);
	
	return (PAGE_EXISTS);
}
 
Example #30
Source File: RasterPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void updatePageAttributes(PrintService service,
                                    PageFormat page) {
    if (this.attributes == null) {
        this.attributes = new HashPrintRequestAttributeSet();
    }

    updateAttributesWithPageFormat(service, page, this.attributes);
}