org.faceless.pdf2.viewer2.feature

## Class PDFImporter

- java.lang.Object
- - org.faceless.pdf2.viewer2.ViewerFeature
  - - org.faceless.pdf2.viewer2.Importer
    - - org.faceless.pdf2.viewer2.feature.PDFImporter

-     public class PDFImporter
      extends Importer

  A subclass of `Importer` that allows PDF files to be loaded into the viewer. This feature is essential for regular operation of the Viewer - if not included in the list of features passed into the `PDFViewer` constructor, it will be added automatically.

  To customize the list of `EncryptionHandler`s used when loading a PDF, this class can be altered. For example, to always use a specific password when loading a PDF you could do the following.

       // First, get rid of the default PDFImporter from the list
       Collection features = new ArrayList(ViewerFeature.getDefaultFeatures());
       for (Iterator i = features.iterator();i.hasNext();) {
           if (i.next() instanceof PDFImporter) {
               i.remove();
           }
       }

       // Next, create a new PDFImporter and set its EncryptionHandler
       PDFImporter importer = new PDFImporter();
       Set handlers = importer.getEncryptionHandlers();
       handlers.clear();
       StandardEncryptionHandler pwhandler = new StandardEncryptionHandler();
       pwhandler.setUserPassword("secret");
       handlers.add(pwhandler);

       // Add that feature to the list and pass it into the PDFViewer
       features.add(importer);
       PDFViewer viewer = new PDFViewer(features);

  The following initialization parameters can be specified to configure this feature.

  useInputStream | If set to 'true' the `setUseInputStream(boolean)` method will be called with true as an argument.

  The name of this feature is PDFImporter

  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/interfaces inherited from class org.faceless.pdf2.viewer2.Importer

      `Importer.ImporterTask`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PDFImporter()` Create a new PDFImporter

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `canLoad(String mimeType)` This importer can load the "application/pdf" MIME type.
    `Set<EncryptionHandler>` | `getEncryptionHandlers()` Return the set of `EncryptionHandler` objects used to possibly decrypt PDF files loaded with this Importer.
    `FileFilter` | `getFileFilter()` Get a `FileFilter` that can be used to choose files acceptable to this Importer.
    `Importer.ImporterTask` | `getImporter(PDFViewer viewer, File file)` Return an `Importer.ImporterTask` that will load a PDF into the viewer from the specifed File.
    `Importer.ImporterTask` | `getImporter(PDFViewer viewer, InputStream in, String title, File file)` 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.
    `void` | `initialize(PDFViewer viewer)` Called when the feature is first added to a viewer
    `boolean` | `matches(File file)` Return true if this Importer can load the specified file.
    `void` | `setUseInputStream(boolean stream)` When opening a PDF from a File, this flag determines whether to open the PDF using the `File` constructor or `InputStream` PDFReader constructor.

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

      `getParser, isAddToMostRecent, isPDFImporter, processPDF, setAddToMostRecent`

    - ### 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

    - #### PDFImporter

          public PDFImporter()

      Create a new PDFImporter

  - ### 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 `Importer`

    - #### getFileFilter

          public FileFilter getFileFilter()

      Description copied from class: `Importer`
      Get a `FileFilter` that can be used to choose files acceptable to this Importer.
      Specified by:
        `getFileFilter` in class `Importer`

    - #### matches

          public boolean matches(File file)
                          throws IOException

      Description copied from class: `Importer`
      Return true if this Importer can load the specified file.
      Specified by:
        `matches` in class `Importer`
      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)

      This importer can load the "application/pdf" MIME type.
      Overrides:
        `canLoad` in class `Importer`
      Parameters:
        `mimeType` - the MIME content type

    - #### getEncryptionHandlers

          public Set<EncryptionHandler> getEncryptionHandlers()

      Return the set of `EncryptionHandler` objects used to possibly decrypt PDF files loaded with this Importer. This set may be altered.

    - #### setUseInputStream

          public void setUseInputStream(boolean stream)

      When opening a PDF from a File, this flag determines whether to open the PDF using the `File` constructor or `InputStream` PDFReader constructor.
      Parameters:
        `stream` - whether to load PDF files from a FileInputStream (true) or a File (false)
      Since:
        2.11.3

    - #### getImporter

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

      Description copied from class: `Importer`
      Return an `Importer.ImporterTask` that will load a PDF into the viewer from the specifed File.
      Specified by:
        `getImporter` in class `Importer`
      Parameters:
        `viewer` - the PDFViewer
        `file` - the FILE to load the PDF from
      Returns:
        an `Importer.ImporterTask` to load the PDF

    - #### getImporter

          public Importer.ImporterTask getImporter(PDFViewer viewer,
                                                   InputStream in,
                                                   String title,
                                                   File file)

      Description copied from class: `Importer`
      Return an `Importer.ImporterTask` that will load a PDF into the viewer from the specifed InputStream.
      Specified by:
        `getImporter` in class `Importer`
      Parameters:
        `viewer` - the PDFViewer
        `in` - the InputStream to load the PDF from
        `title` - the title to give that PDF - may be null
        `file` - 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

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

Copyright © 2001-2015 Big Faceless Organization