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 (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.
    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.

    Since:
    2.10.2
    • 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
        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