Class Importer

  • Direct Known Subclasses:
    ImageImporter, PDFImporter

    public abstract class Importer
    extends ViewerFeature

    A type of ViewerFeature which takes care of loading a PDF file into a PDFViewer. Subclasses of this feature are supplied that can load PDF documents directly (PDFImporter) and by converting bitmap images (ImageImporter), and further custom loaders can be written.

    Here's an example of how to load a PDF into the viewer from a file

     PDFImporter importer = new PDFImporter();
     Importer.ImporterTask task = importer.getImporter(viewer, file);
     task.start(viewer, "Loading");
    The start method will start a background thread and return immediately.
    The following initialization parameters can be specified to configure this feature.
    modalIf set to not null, the loading wil open a modal dialog, preventing any other actions on the viewer while loading. The default is false.
    mostrecentIf set to not false, files loaded with this Importer will not be added to the "most recent" list. The default is "true".

    This code is copyright the Big Faceless Organization. You're welcome to use, modify and distribute it in any form in your own projects, provided those projects continue to make use of the Big Faceless PDF library.

    • Constructor Detail

      • Importer

        protected Importer​(String name)
        Create a new Importer
        name - the name of this feature
    • Method Detail

      • isAddToMostRecent

        public boolean isAddToMostRecent()
        Indicates whether import tasks from this importer will add the associated file to the most recently used list.
      • setAddToMostRecent

        public void setAddToMostRecent​(boolean addToMRU)
        Sets whether import tasks from this importer will add the associated file to the most recently used list.
        addToMRU - if true, add to the list
      • isPDFImporter

        protected boolean isPDFImporter()
        Indicates whether this importer loads from a PDF document.
      • getFileFilter

        public abstract FileFilter getFileFilter()
        Get a FileFilter that can be used to choose files acceptable to this Importer.
      • matches

        public abstract boolean matches​(File file)
                                 throws IOException
        Return true if this Importer can load the specified file.
        file - the File to be checked.
        true if this file can be loaded by this Importer, false otherwise
      • canLoad

        public boolean canLoad​(String mimeType)
        Returns true if this importer can load a file or stream of the specified MIME Content-Type.
        mimeType - the MIME content type
      • getImporter

        public abstract Importer.ImporterTask getImporter​(PDFViewer viewer,
                                                          InputStream in,
                                                          String title,
                                                          File savefile)
        Return an Importer.ImporterTask that will load a PDF into the viewer from the specifed InputStream.
        viewer - the PDFViewer
        in - the InputStream to load the PDF from
        title - the title to give that PDF - may be null
        savefile - if the PDF is later saved, the file to initialize the path to - may be null.
        an Importer.ImporterTask to load the PDF
      • processPDF

        protected void processPDF​(PDF pdf)
        Perform any processing on the PDF after it has been loaded but before it's handed off to the viewer. By default this method is a no-op, but custom subclasses may want to override it.
      • getParser

        protected PDFParser getParser​(PDF pdf)
        Create a PDFParser for the specified PDF. By default this method simply returns new PDFParser(pdf) - if necessary this can be overridden to return a custom subclass of PDFParser.
        pdf - the PDF
        a PDFParser to parse the specified PDF