/** * Returns the given page as an RGB image at the given scale. * A scale of 1 will render at 72 DPI. * @param pageIndex the zero-based index of the page to be converted * @param scale the scaling factor, where 1 = 72 DPI * @return the rendered page image * @throws IOException if the PDF cannot be read */ public BufferedImage renderImage(int pageIndex, float scale) throws IOException { return renderImage(pageIndex, scale, ImageType.RGB); }
/** * Returns a new PageDrawer instance, using the given parameters. May be overridden. */ protected PageDrawer createPageDrawer(PageDrawerParameters parameters) throws IOException { PageDrawer pageDrawer = new PageDrawer(parameters); pageDrawer.setAnnotationFilter(annotationFilter); return pageDrawer; }
@Override public void endText() throws IOException { endTextClip(); }
public static BufferedImage pageConvertToImage(PDPage page, int dpi, ImageType imageType) throws IOException { try (PDDocument document = new PDDocument()) { document.addPage(page); PDFRenderer renderer = new PDFRenderer(document); document.close(); return renderer.renderImageWithDPI(0, dpi, imageType); } }
/** * Creates a new PDFPrintable with the given page scaling and with optional page borders shown. * The image will be rasterized at the given DPI before being sent to the printer. * * @param document the document to print * @param scaling page scaling policy * @param showPageBorder true if page borders are to be printed * @param dpi if non-zero then the image will be rasterized at the given DPI * @param center true if the content is to be centered on the page (otherwise top-left). */ public PDFPrintable(PDDocument document, Scaling scaling, boolean showPageBorder, float dpi, boolean center) { this.document = document; this.renderer = new PDFRenderer(document); this.scaling = scaling; this.showPageBorder = showPageBorder; this.dpi = dpi; this.center = center; }
private Paint getNonStrokingPaint() throws IOException { return applySoftMaskToPaint( getPaint(getGraphicsState().getNonStrokingColor()), getGraphicsState().getSoftMask()); }
/** * Constructor. * * @param parameters Parameters for page drawing. * @throws IOException If there is an error loading properties from the file. */ public PageDrawer(PageDrawerParameters parameters) throws IOException { super(parameters.getPage()); this.renderer = parameters.getRenderer(); this.subsamplingAllowed = parameters.isSubsamplingAllowed(); this.destination = parameters.getDestination(); this.renderingHints = parameters.getRenderingHints(); }
/** * 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); }
@Override public void beginText() throws IOException { setClip(); beginTextClip(); }
@Override public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints) { PaintContext ctx = paint.createContext(cm, deviceBounds, userBounds, xform, hints); return new SoftPaintContext(ctx); }
/** * Creates a new PDFRenderer. * @param document the document to render */ public PDFRenderer(PDDocument document) { this.document = document; if (!kcmsLogged) { suggestKCMS(); kcmsLogged = true; } }
/** * {@inheritDoc} */ @Override public void showForm(PDFormXObject form) throws IOException { if (isContentRendered()) { super.showForm(form); } }
private RenderingHints createDefaultRenderingHints(Graphics2D graphics) { RenderingHints r = new RenderingHints(null); r.put(RenderingHints.KEY_INTERPOLATION, isBitonal(graphics) ? RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR : RenderingHints.VALUE_INTERPOLATION_BICUBIC); r.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); r.put(RenderingHints.KEY_ANTIALIASING, isBitonal(graphics) ? RenderingHints.VALUE_ANTIALIAS_OFF : RenderingHints.VALUE_ANTIALIAS_ON); return r; }
/** * Returns the given page as an RGB image at 72 DPI * @param pageIndex the zero-based index of the page to be converted. * @return the rendered page image * @throws IOException if the PDF cannot be read */ public BufferedImage renderImage(int pageIndex) throws IOException { return renderImage(pageIndex, 1); }
private Paint getStrokingPaint() throws IOException { return applySoftMaskToPaint( getPaint(getGraphicsState().getStrokingColor()), getGraphicsState().getSoftMask()); }
/** * 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); }
/** * Returns the given page as an RGB image at the given DPI. * @param pageIndex the zero-based index of the page to be converted * @param dpi the DPI (dots per inch) to render at * @return the rendered page image * @throws IOException if the PDF cannot be read */ public BufferedImage renderImageWithDPI(int pageIndex, float dpi) throws IOException { return renderImage(pageIndex, dpi / 72f, ImageType.RGB); }
/** * 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); }
/** * Returns the given page as an RGB image at the given DPI. * @param pageIndex the zero-based index of the page to be converted * @param dpi the DPI (dots per inch) to render at * @param imageType the type of image to return * @return the rendered page image * @throws IOException if the PDF cannot be read */ public BufferedImage renderImageWithDPI(int pageIndex, float dpi, ImageType imageType) throws IOException { return renderImage(pageIndex, dpi / 72f, imageType); }
/** * Returns the given page as an RGB or ARGB image at the given scale. * @param pageIndex the zero-based index of the page to be converted * @param scale the scaling factor, where 1 = 72 DPI * @param imageType the type of image to return * @return the rendered page image * @throws IOException if the PDF cannot be read */ public BufferedImage renderImage(int pageIndex, float scale, ImageType imageType) throws IOException { return renderImage(pageIndex, scale, imageType, defaultDestination == null ? RenderDestination.EXPORT : defaultDestination); }