Esempio n. 1
0
  public static BufferedImage PdfToImage(byte[] pdfFile) throws Exception {
    PdfDecoder decode_pdf = new PdfDecoder(true);
    /** set mappings for non-embedded fonts to use */
    // FontMappings.setFontReplacements();

    /** open the PDF file - can also be a URL or a byte array */
    try {
      decode_pdf.openPdfArray(pdfFile);

      decode_pdf.setExtractionMode(PdfDecoder.FINALIMAGES); // do not save images
      /** get page 1 as an image */
      BufferedImage img = decode_pdf.getPageAsImage(1);

      /** close the pdf file */
      decode_pdf.closePdfFile();
      return img;
    } catch (PdfException e) {
      throw new Exception(e.getMessage(), e);
    }
  }