/** * 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 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); }
/** * 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); }
/** * 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); }
public static void main(String[] args) throws IOException { File file = new File("src/main/resources/org/apache/pdfbox/examples/rendering/", "custom-render-demo.pdf"); try (PDDocument doc = PDDocument.load(file)) { PDFRenderer renderer = new MyPDFRenderer(doc); BufferedImage image = renderer.renderImage(0); ImageIO.write(image, "PNG", new File("custom-render.png")); } }
@Override protected BufferedImage doInBackground() throws IOException { label.setIcon(null); labelText = "Rendering..."; label.setText(labelText); statuslabel.setText(labelText); PDFRenderer renderer = new DebugPDFRenderer(document, this.showGlyphBounds); renderer.setSubsamplingAllowed(allowSubsampling); long t0 = System.nanoTime(); BufferedImage image = renderer.renderImage(pageIndex, scale); long t1 = System.nanoTime(); long ms = TimeUnit.MILLISECONDS.convert(t1 - t0, TimeUnit.NANOSECONDS); labelText = "Rendered in " + ms + " ms"; statuslabel.setText(labelText); // debug overlays DebugTextOverlay debugText = new DebugTextOverlay(document, pageIndex, scale, showTextStripper, showTextStripperBeads, showFontBBox); Graphics2D g = image.createGraphics(); debugText.renderTo(g); g.dispose(); return ImageUtil.getRotatedImage(image, rotation); }
private void stripPage(int page) throws IOException image = pdfRenderer.renderImage(page, SCALE);
/** * 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 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); }
/** * 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); }
/** * 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 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 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); }
/** * 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); }
return new PDFRenderer(doc).renderImage(0);
@Override public Result call() throws Exception { BufferedImage image = renderer.renderImage(pageIndex, 1f, ImageType.BINARY); return detector.detect(image); } }
try { BufferedImage image = renderer.renderImage(pageIndex, config.getOcrImageScale(), config.getOcrImageType()); Path tmpFile = tmp.createTempFile(); try (OutputStream os = Files.newOutputStream(tmpFile)) {
PDDocument document = PDDocument.load(new File("filePath")); //filePath is the path to your .pdf PDFRenderer pdfRenderer = new PDFRenderer(document); for(int i=0; i<document.getPages().getCount(); i++){ BufferedImage bim = pdfRenderer.renderImage(i, 1.0f, ImageType.RGB); //Get bufferedImage for page "i" with scale 1 ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(bim, "jpg", os); InputStream is = new ByteArrayInputStream(os.toByteArray()); //Do whatever you need with the inputstream } document.close()
PDDocument pdDocument = PDDocument.load(resource); PDPage page = pdDocument.getPage(12-1); page.setCropBox(new PDRectangle(40f, 680f, 510f, 100f)); PDFRenderer renderer = new PDFRenderer(pdDocument); BufferedImage img = renderer.renderImage(12 - 1, 4f); ImageIOUtil.writeImage(img, new File(RESULT_FOLDER, "ENG-US_NMATSCJ-1.103-0330-page12cropped.jpg").getAbsolutePath(), 300); pdDocument.close();