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 thePDFViewer
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.The name of this feature is PDFImporteruseInputStream If set to 'true' the setUseInputStream(boolean)
method will be called with true as an argument.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 Description PDFImporter()
Create a new PDFImporter
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canLoad(String mimeType)
This importer can load the "application/pdf" MIME type.Set<EncryptionHandler>
getEncryptionHandlers()
Return the set ofEncryptionHandler
objects used to possibly decrypt PDF files loaded with this Importer.FileFilter
getFileFilter()
Get aFileFilter
that can be used to choose files acceptable to this Importer.Importer.ImporterTask
getImporter(PDFViewer viewer, File file)
Return anImporter.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 anImporter.ImporterTask
that will load a PDF into the viewer from the specifed InputStream.Importer.ImporterTask
getImporter(PDFViewer viewer, URL url)
Return anImporter.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 viewerboolean
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 theFile
constructor orInputStream
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
-
-
-
-
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 classImporter
-
getFileFilter
public FileFilter getFileFilter()
Description copied from class:Importer
Get aFileFilter
that can be used to choose files acceptable to this Importer.- Specified by:
getFileFilter
in classImporter
-
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 classImporter
- 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.
-
getEncryptionHandlers
public Set<EncryptionHandler> getEncryptionHandlers()
Return the set ofEncryptionHandler
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 theFile
constructor orInputStream
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 anImporter.ImporterTask
that will load a PDF into the viewer from the specifed File.- Specified by:
getImporter
in classImporter
- Parameters:
viewer
- the PDFViewerfile
- 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 anImporter.ImporterTask
that will load a PDF into the viewer from the specifed InputStream.- Specified by:
getImporter
in classImporter
- Parameters:
viewer
- the PDFViewerin
- the InputStream to load the PDF fromtitle
- the title to give that PDF - may be nullfile
- 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 anImporter.ImporterTask
that will load a PDF into the viewer from the specified URL.- Overrides:
getImporter
in classImporter
- Parameters:
viewer
- the PDFViewerurl
- the URL to load the PDF from- Returns:
- an
Importer.ImporterTask
to load the PDF - Throws:
IOException
-
-