Class DocumentToPDFConverter

java.lang.Object
org.jpedal.examples.DocumentToPDFConverter

public final class DocumentToPDFConverter extends Object
Helper class for converting Office documents to PDF using LibreOffice.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    convert(File document, String libreOfficeExecutablePath)
    Uses LibreOffice to convert an office document to PDF using the provided LibreOffice executable path.
    static int
    convert(File document, String libreOfficeExecutablePath, boolean allowOverwrite)
    Uses LibreOffice to convert an office document to PDF using the provided LibreOffice executable path.
    static boolean
    Returns whether the provided file has a convertible file type

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 PDF
      libreOfficeExecutablePath - Absolute path for the LibreOffice executable to use to convert the document
      allowOverwrite - 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 PDF
      libreOfficeExecutablePath - 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

      public static boolean hasConvertibleFileType(File file)
      Returns whether the provided file has a convertible file type
      Parameters:
      file - file to check
      Returns:
      whether provided file is convertible