/** * Renders a given page to an AWT Graphics2D instance. * @param pageIndex the zero-based index of the page to be converted * @param graphics the Graphics2D on which to draw the page * @throws IOException if the PDF cannot be read */ public void renderPageToGraphics(int pageIndex, Graphics2D graphics) throws IOException { renderPageToGraphics(pageIndex, graphics, 1); }
/** * Renders a given page to an AWT Graphics2D instance. * @param pageIndex the zero-based index of the page to be converted * @param graphics the Graphics2D on which to draw the page * @param scale the scale to draw the page at * @throws IOException if the PDF cannot be read */ public void renderPageToGraphics(int pageIndex, Graphics2D graphics, float scale) throws IOException { renderPageToGraphics(pageIndex, graphics, scale, scale); }
/** * Renders a given page to an AWT Graphics2D instance. * * @param pageIndex the zero-based index of the page to be converted * @param graphics the Graphics2D on which to draw the page * @param scaleX the scale to draw the page at for the x-axis * @param scaleY the scale to draw the page at for the y-axis * @throws IOException if the PDF cannot be read */ public void renderPageToGraphics(int pageIndex, Graphics2D graphics, float scaleX, float scaleY) throws IOException { renderPageToGraphics(pageIndex, graphics, scaleX, scaleY, defaultDestination == null ? RenderDestination.VIEW : defaultDestination); }
renderer.setSubsamplingAllowed(subsamplingAllowed); renderer.setRenderingHints(renderingHints); renderer.renderPageToGraphics(pageIndex, graphics2D, (float) scale, (float) scale, RenderDestination.PRINT);
/** * Renders a given page to an AWT Graphics2D instance. * @param pageIndex the zero-based index of the page to be converted * @param graphics the Graphics2D on which to draw the page * @param scale the scale to draw the page at * @throws IOException if the PDF cannot be read */ public void renderPageToGraphics(int pageIndex, Graphics2D graphics, float scale) throws IOException { renderPageToGraphics(pageIndex, graphics, scale, scale); }
/** * Renders a given page to an AWT Graphics2D instance. * @param pageIndex the zero-based index of the page to be converted * @param graphics the Graphics2D on which to draw the page * @throws IOException if the PDF cannot be read */ public void renderPageToGraphics(int pageIndex, Graphics2D graphics) throws IOException { renderPageToGraphics(pageIndex, graphics, 1); }
/** * Renders a given page to an AWT Graphics2D instance. * @param pageIndex the zero-based index of the page to be converted * @param graphics the Graphics2D on which to draw the page * @throws IOException if the PDF cannot be read */ public void renderPageToGraphics(int pageIndex, Graphics2D graphics) throws IOException { renderPageToGraphics(pageIndex, graphics, 1); }
RenderedImage extract(int pageIndex, Float x, Float y, Float w, Float h) throws IOException { Rectangle2D rect = new Rectangle2D.Float(x, y, w, h); double scale = dpi / POINTS_IN_INCH; double bitmapWidth = rect.getWidth() * scale; double bitmapHeight = rect.getHeight() * scale; BufferedImage image = new BufferedImage((int)bitmapWidth, (int)bitmapHeight, BufferedImage.TYPE_INT_RGB); AffineTransform transform = AffineTransform.getScaleInstance(scale, scale); transform.concatenate(AffineTransform.getTranslateInstance(-rect.getX(), -rect.getY())); Graphics2D graphics = image.createGraphics(); graphics.setBackground(Color.WHITE); graphics.setTransform(transform); renderer.renderPageToGraphics(pageIndex, graphics); graphics.dispose(); return image; } }
BufferedImage image = createImage(rect) Graphics2D graphics = createGraphics(image, rect) renderer.renderPageToGraphics(pageIndex, graphics) graphics.dispose() image
graphics2D.setBackground(Color.WHITE); renderer.setSubsamplingAllowed(subsamplingAllowed); renderer.renderPageToGraphics(pageIndex, graphics2D, (float)scale);
renderer.renderPageToGraphics(pageIndex, graphics2D, (float)scale);