Package adams.core.io

Class PDFBox


  • public class PDFBox
    extends Object
    Helper class for PDFBox library.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    • Constructor Summary

      Constructors 
      Constructor Description
      PDFBox()  
    • Constructor Detail

      • PDFBox

        public PDFBox()
    • Method Detail

      • load

        public static org.apache.pdfbox.pdmodel.PDDocument load​(String filename)
        Loads the PDF file.
        Parameters:
        filename - the filename of the PDF
        Returns:
        the PDF document, null if failed to load
      • load

        public static org.apache.pdfbox.pdmodel.PDDocument load​(File file)
        Loads the PDF file.
        Parameters:
        file - the PDF file
        Returns:
        the PDF document, null if failed to load
      • close

        public static void close​(org.apache.pdfbox.pdmodel.PDDocument document)
        Closes the document again.
        Parameters:
        document - the document to close, can be null
      • save

        public static boolean save​(org.apache.pdfbox.pdmodel.PDDocument doc,
                                   String file)
        Saves the PDF document under the specified filename.
        Parameters:
        doc - the document to save
        file - the file to save the document to
        Returns:
        true if successfully saved
      • save

        public static boolean save​(org.apache.pdfbox.pdmodel.PDDocument doc,
                                   File file)
        Saves the PDF document under the specified filename.
        Parameters:
        doc - the document to save
        file - the file to save the document to
        Returns:
        true if successfully saved
      • print

        public static boolean print​(String filename)
        Prints the PDF document.
        Parameters:
        filename - the filename of the PDF to print
        Returns:
        true if successfully printed
      • print

        public static boolean print​(File file)
        Prints the PDF document.
        Parameters:
        file - the PDF file print
        Returns:
        true if successfully printed
      • print

        public static boolean print​(org.apache.pdfbox.pdmodel.PDDocument document)
        Prints the PDF document.
        Parameters:
        document - the PDF document to print
        Returns:
        true if successfully printed
      • printWithDialog

        public static boolean printWithDialog​(File file)
        Prints the PDF document, bringing up a dialog.
        Parameters:
        file - the PDF file print
        Returns:
        true if successfully printed
      • printWithDialog

        public static boolean printWithDialog​(org.apache.pdfbox.pdmodel.PDDocument document)
        Prints the PDF document, bringing up a dialog.
        Parameters:
        document - the PDF document to print
        Returns:
        true if successfully printed
      • getPageCount

        public static int getPageCount​(File file)
        Returns the number of pages in the PDF document.
        Parameters:
        file - the PDF file to get the page count for
        Returns:
        the page count, -1 if failed to determine
      • extractText

        public static String extractText​(File file)
        Extracts the text from the PDF.
        Parameters:
        file - the PDF to get the text from
        Returns:
        the text, null if failed to extract
      • extractImagesFromResources

        public static List<RenderedImage> extractImagesFromResources​(org.apache.pdfbox.pdmodel.PDResources resources)
                                                              throws IOException
        Extracts images from PDF resources.
        Parameters:
        resources - the resources to extract the images from
        Returns:
        the list of extracted images
        Throws:
        IOException - if extraction fails
      • extractImages

        public static List<BufferedImage> extractImages​(org.apache.pdfbox.pdmodel.PDDocument document)
                                                 throws IOException
        Extracts images from a PDF document.
        Parameters:
        document - the document to extract the images from
        Returns:
        the list of extracted images
        Throws:
        IOException - if extraction fails
      • extractImages

        public static List<BufferedImage> extractImages​(File file)
                                                 throws IOException
        Extracts images from a PDF document.
        Parameters:
        file - the file to extract the images from
        Returns:
        the list of extracted images
        Throws:
        IOException - if extraction fails