PDFBox: Render first page in a document


/ Published in: Java
Save to your folder(s)

Opens a PDF Document and renders the first page as an image, which is then saved to file.


Copy this code and paste it in your HTML
  1. /**
  2.  * @param args the command line arguments
  3.  * @throws java.io.IOException
  4.  */
  5. public static void main(String[] args) throws IOException {
  6. File file = new File("");
  7.  
  8. PDDocument doc = PDDocument.load(file);
  9. PDFRenderer pdfRenderer = new PDFRenderer(doc);
  10. BufferedImage image = pdfRenderer.renderImageWithDPI(0, 300);
  11.  
  12. ImageIOUtil.writeImage(image,"", 300);
  13. doc.close();
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.