Class 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 EncryptionHandlers 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 ( instanceof PDFImporter) {
     // Next, create a new PDFImporter and set its EncryptionHandler
     PDFImporter importer = new PDFImporter();
     Set handlers = importer.getEncryptionHandlers();
     StandardEncryptionHandler pwhandler = new StandardEncryptionHandler();
     // Add that feature to the list and pass it into the PDFViewer
     PDFViewer viewer = new PDFViewer(features);
    The following initialization parameters can be specified to configure this feature.
    useInputStreamIf 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.

    • Constructor Detail

      • PDFImporter

        public PDFImporter()
        Create a new PDFImporter
    • Method Detail

      • 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
        file - the File to be checked.
        true if this file can be loaded by this Importer, false otherwise
      • canLoad

        public boolean canLoad​(String mimeType)
        This importer can load the "application/pdf" MIME type.
        canLoad in class Importer
        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.
        stream - whether to load PDF files from a FileInputStream (true) or a File (false)