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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Convert the given document file to PNG images, one image per page.Get the list of mime types the convertor can convertwriteImages
(PDDocument document, File folder, String imageFormat, String outputPrefix) Converts a given page range of a PDF document to bitmap images.writeImages
(PDDocument document, File folder, String imageFormat, String outputPrefix, int resolution) Converts a given page range of a PDF document to bitmap images.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) Converts a given page range of a PDF document to bitmap images.protected void
writePreview
(File folder, String outputPrefix) Generate the preview imageMethods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Constructor Details
-
PdfboxConvertor
public PdfboxConvertor()
-
-
Method Details
-
convert
Description copied from interface:Document2ImagesConvertorPolicy
Convert the given document file to PNG images, one image per page.- Specified by:
convert
in interfaceDocument2ImagesConvertorPolicy
- 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 documentfolder
- the folder where to writeimageFormat
- 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 occursFlipbookException
- 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 documentfolder
- the folder where to writeimageFormat
- the target format (ex. "png")outputPrefix
- used to construct the filename for the individual imagesresolution
- 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 occursFlipbookException
- 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 documentfolder
- the folder where to writeimageFormat
- 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 imagesimageType
- the image type (seeBufferedImage
.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 occursFlipbookException
- 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 interfaceDocument2ImagesConvertorPolicy
- Returns:
- The list of supported mime-types
-
writePreview
Generate the preview image- Parameters:
folder
- The folder with the PDF imagesoutputPrefix
- The prefix of PDF images- Throws:
IOException
- if an I/O error occurs
-