Package org.jpedal.examples
Class DocumentToPDFConverter
java.lang.Object
org.jpedal.examples.DocumentToPDFConverter
Helper class for converting Office documents to PDF using LibreOffice.
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
Uses LibreOffice to convert an office document to PDF using the provided LibreOffice executable path.static int
Uses LibreOffice to convert an office document to PDF using the provided LibreOffice executable path.static boolean
hasConvertibleFileType
(File file) Returns whether the provided file has a convertible file type
-
Method Details
-
convert
public static int convert(File document, String libreOfficeExecutablePath, boolean allowOverwrite) throws IOException, InterruptedException Uses LibreOffice to convert an office document to PDF using the provided LibreOffice executable path.Creates a file with the same name (with .pdf extension) in the same directory as the source file.
If the output file already exists, it will not be overwritten and an IOException will be thrown.
- Parameters:
document
- Office document to convert to PDFlibreOfficeExecutablePath
- Absolute path for the LibreOffice executable to use to convert the documentallowOverwrite
- Boolean flag on whether the output file can be overwritten- Returns:
- The exit code of the LibreOffice process (usually 0 regardless of success or failure)
- Throws:
IOException
- If the LibreOffice executable was not found, the document does not exist, the document does not have a valid file extension, or the output file already exists (and allowOverwrite is set to false)InterruptedException
- If the conversion process gets interrupted
-
convert
public static int convert(File document, String libreOfficeExecutablePath) throws IOException, InterruptedException Uses LibreOffice to convert an office document to PDF using the provided LibreOffice executable path.Creates a file with the same name (with .pdf extension) in the same directory as the source file.
If the output file already exists, it will not be overwritten and an IOException will be thrown.
- Parameters:
document
- Office document to convert to PDFlibreOfficeExecutablePath
- Absolute path for the LibreOffice executable to use to convert the document- Returns:
- The exit code of the LibreOffice process (usually 0 regardless of success or failure)
- Throws:
IOException
- If the LibreOffice executable was not found, the document does not exist, the document does not have a valid file extension, or the output file already exists (will not overwrite)InterruptedException
- If the conversion process gets interrupted
-
hasConvertibleFileType
Returns whether the provided file has a convertible file type- Parameters:
file
- file to check- Returns:
- whether provided file is convertible
-