Class PdfboxConvertor

java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.ametys.plugins.flipbook.pdfbox.PdfboxConvertor
All Implemented Interfaces:
Document2ImagesConvertorPolicy, LogEnabled

PDF to PNG convertor which makes use of the pdfbox library. Based on pdfbox's PDFRenderer utility class, adding the possibility to specify the file name pattern.
  • Constructor Details

  • Method Details

    • convert

      public void convert(File pdfFile, File folder) throws IOException, FlipbookException
      Description copied from interface: Document2ImagesConvertorPolicy
      Convert the given document file to PNG images, one image per page.
      Specified by:
      convert in interface Document2ImagesConvertorPolicy
      Parameters:
      pdfFile - the document file to convert.
      folder - the destination folder.
      Throws:
      IOException - if an I/O error occurs.
      FlipbookException - if a document error occurs.
    • writeImages

      protected List<String> writeImages(PDDocument document, File folder, String imageFormat, String outputPrefix) throws IOException, FlipbookException
      Converts a given page range of a PDF document to bitmap images.
      Parameters:
      document - the PDF document
      folder - the folder where to write
      imageFormat - the target format (ex. "png")
      outputPrefix - used to construct the filename for the individual images
      Returns:
      true if the images were produced, false if there was an error
      Throws:
      IOException - if an I/O error occurs
      FlipbookException - if an error occurs when manipulating the flipbook
    • writeImages

      protected List<String> writeImages(PDDocument document, File folder, String imageFormat, String outputPrefix, int resolution) throws IOException, FlipbookException
      Converts a given page range of a PDF document to bitmap images.
      Parameters:
      document - the PDF document
      folder - the folder where to write
      imageFormat - the target format (ex. "png")
      outputPrefix - used to construct the filename for the individual images
      resolution - the resolution in dpi (dots per inch)
      Returns:
      true if the images were produced, false if there was an error
      Throws:
      IOException - if an I/O error occurs
      FlipbookException - if an error occurs when manipulating the flipbook
    • writeImages

      protected List<String> writeImages(PDDocument document, File folder, String imageFormat, String password, int startPage, int endPage, String outputPrefix, org.apache.pdfbox.rendering.ImageType imageType, int resolution, float quality) throws IOException, FlipbookException
      Converts a given page range of a PDF document to bitmap images.
      Parameters:
      document - the PDF document
      folder - the folder where to write
      imageFormat - the target format (ex. "png")
      password - the password (needed if the PDF is encrypted)
      startPage - the start page (1 is the first page)
      endPage - the end page (set to Integer.MAX_VALUE for all pages)
      outputPrefix - used to construct the filename for the individual images
      imageType - the image type (see BufferedImage.TYPE_*)
      resolution - the resolution in dpi (dots per inch)
      quality - the image compression quality (0 < quality < 1.0f).
      Returns:
      true if the images were produced, false if there was an error
      Throws:
      IOException - if an I/O error occurs
      FlipbookException - if an error occurs when manipulating the flipbook
    • getSupportedMimeTypes

      Description copied from interface: Document2ImagesConvertorPolicy
      Get the list of mime types the convertor can convert
      Specified by:
      getSupportedMimeTypes in interface Document2ImagesConvertorPolicy
      Returns:
      The list of supported mime-types
    • writePreview

      protected void writePreview(File folder, String outputPrefix) throws IOException
      Generate the preview image
      Parameters:
      folder - The folder with the PDF images
      outputPrefix - The prefix of PDF images
      Throws:
      IOException - if an I/O error occurs