org.faceless.pdf2.viewer2

## Class Importer

- java.lang.Object
- - org.faceless.pdf2.viewer2.ViewerFeature
  - - org.faceless.pdf2.viewer2.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.

  modal | If set to not null, the loading wil open a modal dialog, preventing any other actions on the viewer while loading. The default is false.
  mostrecent | If 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.

  Since:
    2.10.2

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `Importer.ImporterTask` This class is a `LongRunningTask` that can be run to load a PDF into the viewer.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `Importer(String name)` Create a new Importer

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `canLoad(String mimeType)` Returns true if this importer can load a file or stream of the specified MIME Content-Type.
    `abstract FileFilter` | `getFileFilter()` Get a `FileFilter` that can be used to choose files acceptable to this Importer.
    `abstract Importer.ImporterTask` | `getImporter(PDFViewer viewer, File file)` Return an `Importer.ImporterTask` that will load a PDF into the viewer from the specifed File.
    `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.
    `Importer.ImporterTask` | `getImporter(PDFViewer viewer, URL url)` Return an `Importer.ImporterTask` that will load a PDF into the viewer from the specified URL.
    `protected PDFParser` | `getParser(PDF pdf)` Create a `PDFParser` for the specified PDF.
    `void` | `initialize(PDFViewer viewer)` Called when the feature is first added to a viewer
    `boolean` | `isAddToMostRecent()` Indicates whether import tasks from this importer will add the associated file to the most recently used list.
    `protected boolean` | `isPDFImporter()` Indicates whether this importer loads from a PDF document.
    `abstract boolean` | `matches(File file)` Return true if this Importer can load the specified file.
    `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.
    `void` | `setAddToMostRecent(boolean addToMRU)` Sets whether import tasks from this importer will add the associated file to the most recently used list.

    - ### Methods inherited from class org.faceless.pdf2.viewer2.ViewerFeature

      `getAllEnabledFeatures, getAllFeatures, getCustomJavaScript, getFeatureProperty, getFeatureURLProperty, getName, isEnabledByDefault, setFeatureName, teardown, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Importer

          protected Importer(String name)

      Create a new Importer
      Parameters:
        `name` - the name of this feature

  - ### Method Detail

    - #### initialize

          public void initialize(PDFViewer viewer)

      Description copied from class: `ViewerFeature`
      Called when the feature is first added to a viewer
      Overrides:
        `initialize` in class `ViewerFeature`

    - #### 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.
      Parameters:
        `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.
      Parameters:
        `file` - the File to be checked.
      Returns:
        true if this file can be loaded by this Importer, false otherwise
      Throws:
        `IOException`

    - #### canLoad

          public boolean canLoad(String mimeType)

      Returns true if this importer can load a file or stream of the specified MIME Content-Type.
      Parameters:
        `mimeType` - the MIME content type
      Since:
        2.18

    - #### getImporter

          public abstract Importer.ImporterTask getImporter(PDFViewer viewer,
                                                            File file)

      Return an `Importer.ImporterTask` that will load a PDF into the viewer from the specifed File.
      Parameters:
        `viewer` - the PDFViewer
        `file` - the FILE to load the PDF from
      Returns:
        an `Importer.ImporterTask` to load the PDF

    - #### 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.
      Parameters:
        `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.
      Returns:
        an `Importer.ImporterTask` to load the PDF

    - #### getImporter

          public Importer.ImporterTask getImporter(PDFViewer viewer,
                                                   URL url)
                                            throws IOException

      Return an `Importer.ImporterTask` that will load a PDF into the viewer from the specified URL.
      Parameters:
        `viewer` - the PDFViewer
        `url` - the URL to load the PDF from
      Returns:
        an `Importer.ImporterTask` to load the PDF
      Throws:
        `IOException`

    - #### 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.
      Since:
        2.10.6

    - #### 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.
      Parameters:
        `pdf` - the PDF
      Returns:
        a PDFParser to parse the specified PDF
      Since:
        2.11.3

Copyright © 2001-2015 Big Faceless Organization