Package 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 aPDFViewer
. 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");
Thestart
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 Description class
Importer.ImporterTask
This class is aLongRunningTask
that can be run to load a PDF into the viewer.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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 aFileFilter
that can be used to choose files acceptable to this Importer.abstract Importer.ImporterTask
getImporter(PDFViewer viewer, File file)
Return anImporter.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 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.protected PDFParser
getParser(PDF pdf)
Create aPDFParser
for the specified PDF.void
initialize(PDFViewer viewer)
Called when the feature is first added to a viewerboolean
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
-
-
-
-
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 classViewerFeature
-
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 aFileFilter
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 anImporter.ImporterTask
that will load a PDF into the viewer from the specifed File.- Parameters:
viewer
- the PDFViewerfile
- 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 anImporter.ImporterTask
that will load a PDF into the viewer from the specifed InputStream.- Parameters:
viewer
- the PDFViewerin
- the InputStream to load the PDF fromtitle
- the title to give that PDF - may be nullsavefile
- 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 anImporter.ImporterTask
that will load a PDF into the viewer from the specified URL.- Parameters:
viewer
- the PDFViewerurl
- 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 aPDFParser
for the specified PDF. By default this method simply returnsnew 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
-
-