org.faceless.pdf2.viewer2
Class Importer

java.lang.Object
  extended by org.faceless.pdf2.viewer2.ViewerFeature
      extended by 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 a PDFViewer. 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");
 
The start method will start a background thread and return immediately.

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
 class Importer.ImporterTask
          This class is a LongRunningTask that can be run to load a PDF into the viewer.
 
Constructor Summary
protected Importer(String name)
          Create a new Importer
 
Method Summary
abstract  FileFilter getFileFilter()
          Get a FileFilter that can be used to choose files acceptable to this Importer.
abstract  Importer.ImporterTask getImporter(PDFViewer viewer, File file)
          Return an Importer.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 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.
protected  PDFParser getParser(PDF pdf)
          Create a PDFParser for the specified PDF.
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.
 
Methods inherited from class org.faceless.pdf2.viewer2.ViewerFeature
getAllEnabledFeatures, getAllFeatures, getCustomJavaScript, getFeatureProperty, getFeatureURLProperty, getName, initialize, isEnabledByDefault, setFeatureName, teardown, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Importer

protected Importer(String name)
Create a new Importer

Parameters:
name - the name of this feature
Method Detail

getFileFilter

public abstract FileFilter getFileFilter()
Get a FileFilter 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

getImporter

public abstract Importer.ImporterTask getImporter(PDFViewer viewer,
                                                  File file)
Return an Importer.ImporterTask that will load a PDF into the viewer from the specifed File.

Parameters:
viewer - the PDFViewer
file - 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 an Importer.ImporterTask that will load a PDF into the viewer from the specifed InputStream.

Parameters:
viewer - the PDFViewer
in - the InputStream to load the PDF from
title - the title to give that PDF - may be null
savefile - 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 an Importer.ImporterTask that will load a PDF into the viewer from the specified URL.

Parameters:
viewer - the PDFViewer
url - 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 a PDFParser for the specified PDF. By default this method simply returns new 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


Copyright © 2001-2013 Big Faceless Organization