Class PdfboxConvertor
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.plugins.flipbook.pdfbox.PdfboxConvertor
-
- All Implemented Interfaces:
Document2ImagesConvertorPolicy
,LogEnabled
public class PdfboxConvertor extends AbstractLogEnabled implements Document2ImagesConvertorPolicy
PDF to PNG convertor which makes use of the pdfbox library. Based on pdfbox'sPDFRenderer
utility class, adding the possibility to specify the file name pattern.
-
-
Constructor Summary
Constructors Constructor Description PdfboxConvertor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static BufferedImage
_resizeImage(BufferedImage src, int maxHeight, int maxWidth)
void
convert(File pdfFile, File folder)
Convert the given document file to PNG images, one image per page.List<String>
getSupportedMimeTypes()
Get the list of mime types the convertor can convertprotected List<String>
writeImages(PDDocument document, File folder, String imageFormat, String outputPrefix)
Converts a given page range of a PDF document to bitmap images.protected List<String>
writeImages(PDDocument document, File folder, String imageFormat, String outputPrefix, int resolution)
Converts a given page range of a PDF document to bitmap images.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)
Converts a given page range of a PDF document to bitmap images.protected void
writePreview(File folder, String outputPrefix)
Generate the preview image-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Constructor Detail
-
PdfboxConvertor
public PdfboxConvertor()
-
-
Method Detail
-
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 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
public List<String> 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
protected void writePreview(File folder, String outputPrefix) throws IOException
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
-
_resizeImage
private static BufferedImage _resizeImage(BufferedImage src, int maxHeight, int maxWidth)
-
-