org.pdfbox.util

Class PDFStreamEngine

Known Direct Subclasses:
PageDrawer, PDFTextStripper, PrintImageLocations, Type3StreamParser

public class PDFStreamEngine
extends java.lang.Object

This class will run through a PDF content stream and execute certain operations and provide a callback interface for clients that want to do things with the stream. See the PDFTextStripper class for an example of how to use this class.
Version:
$Revision: 1.35 $
Author:
Ben Litchfield

Constructor Summary

PDFStreamEngine()
Constructor.
PDFStreamEngine(Properties properties)
Constructor with engine properties.

Method Summary

Map
getColorSpaces()
PDPage
getCurrentPage()
Get the current page that is being processed.
Map
getFonts()
Stack
getGraphicsStack()
PDGraphicsState
getGraphicsState()
Map
getGraphicsStates()
PDResources
getResources()
Matrix
getTextLineMatrix()
Matrix
getTextMatrix()
Map
getXObjects()
void
processOperator(String operation, List arguments)
This is used to handle an operation.
protected void
processOperator(PDFOperator operator, List arguments)
This is used to handle an operation.
void
processStream(PDPage aPage, PDResources resources, COSStream cosStream)
This will process the contents of the stream.
void
processSubStream(PDPage aPage, PDResources resources, COSStream cosStream)
Process a sub stream of the current stream.
void
registerOperatorProcessor(String operator, OperatorProcessor op)
Register a custom operator processor with the engine.
void
resetEngine()
This method must be called between processing documents.
void
setColorSpaces(Map value)
void
setFonts(Map value)
void
setGraphicsStack(Stack value)
void
setGraphicsState(PDGraphicsState value)
void
setGraphicsStates(Map value)
void
setTextLineMatrix(Matrix value)
void
setTextMatrix(Matrix value)
protected void
showCharacter(TextPosition text)
A method provided as an event interface to allow a subclass to perform some specific functionality when a character needs to be displayed.
void
showString(byte[] string)
You should override this method if you want to perform an action when a string is being shown.

Constructor Details

PDFStreamEngine

public PDFStreamEngine()
Constructor.

PDFStreamEngine

public PDFStreamEngine(Properties properties)
            throws IOException
Constructor with engine properties. The property keys are all PDF operators, the values are class names used to execute those operators.
Parameters:
properties - The engine properties.

Method Details

getColorSpaces

public Map getColorSpaces()
Returns:
Returns the colorSpaces.

getCurrentPage

public PDPage getCurrentPage()
Get the current page that is being processed.
Returns:
The page being processed.

getFonts

public Map getFonts()
Returns:
Returns the fonts.

getGraphicsStack

public Stack getGraphicsStack()
Returns:
Returns the graphicsStack.

getGraphicsState

public PDGraphicsState getGraphicsState()
Returns:
Returns the graphicsState.

getGraphicsStates

public Map getGraphicsStates()
Returns:
Returns the graphicsStates.

getResources

public PDResources getResources()
Returns:
Returns the resources.

getTextLineMatrix

public Matrix getTextLineMatrix()
Returns:
Returns the textLineMatrix.

getTextMatrix

public Matrix getTextMatrix()
Returns:
Returns the textMatrix.

getXObjects

public Map getXObjects()
Returns:
Returns the colorSpaces.

processOperator

public void processOperator(String operation,
                            List arguments)
            throws IOException
This is used to handle an operation.
Parameters:
operation - The operation to perform.
arguments - The list of arguments.

processOperator

protected void processOperator(PDFOperator operator,
                               List arguments)
            throws IOException
This is used to handle an operation.
Parameters:
operator - The operation to perform.
arguments - The list of arguments.

processStream

public void processStream(PDPage aPage,
                          PDResources resources,
                          COSStream cosStream)
            throws IOException
This will process the contents of the stream.
Parameters:
aPage - The page.
resources - The location to retrieve resources.
cosStream - the Stream to execute.

processSubStream

public void processSubStream(PDPage aPage,
                             PDResources resources,
                             COSStream cosStream)
            throws IOException
Process a sub stream of the current stream.
Parameters:
aPage - The page used for drawing.
resources - The resources used when processing the stream.
cosStream - The stream to process.

registerOperatorProcessor

public void registerOperatorProcessor(String operator,
                                      OperatorProcessor op)
Register a custom operator processor with the engine.
Parameters:
operator - The operator as a string.
op - Processor instance.

resetEngine

public void resetEngine()
This method must be called between processing documents. The PDFStreamEngine caches information for the document between pages and this will release the cached information. This only needs to be called if processing a new document.

setColorSpaces

public void setColorSpaces(Map value)
Parameters:
value - The colorSpaces to set.

setFonts

public void setFonts(Map value)
Parameters:
value - The fonts to set.

setGraphicsStack

public void setGraphicsStack(Stack value)
Parameters:
value - The graphicsStack to set.

setGraphicsState

public void setGraphicsState(PDGraphicsState value)
Parameters:
value - The graphicsState to set.

setGraphicsStates

public void setGraphicsStates(Map value)
Parameters:
value - The graphicsStates to set.

setTextLineMatrix

public void setTextLineMatrix(Matrix value)
Parameters:
value - The textLineMatrix to set.

setTextMatrix

public void setTextMatrix(Matrix value)
Parameters:
value - The textMatrix to set.

showCharacter

protected void showCharacter(TextPosition text)
A method provided as an event interface to allow a subclass to perform some specific functionality when a character needs to be displayed.
Parameters:
text - The character to be displayed.

showString

public void showString(byte[] string)
            throws IOException
You should override this method if you want to perform an action when a string is being shown.
Parameters:
string - The string to display.