intarsys PDF library API

de.intarsys.pdf.content
Class CSContent

java.lang.Object
  extended by de.intarsys.pdf.content.CSContent

public class CSContent
extends Object

Represents the tokenized content of a PDF rendering program which is called a "content stream".

A PDF rendering program is a sequence of operations, each build by a list of operands followed by the operator.

Any visual appearance in a PDF document is build on a content stream. For example a PDPage hosts a content stream (or a list of content streams) to define its appearance.

A content stream has no access to indirect objects, this means object references are not valid operands for operations. Complex objects are used within a content stream via an indirection defined in a resource dictionary.

The CSContent itself is decoupled from its source of creation, this means after manipulating the content stream you have to apply it where you want to (for example adding it to a page).

You can work on the content stream directly, adding and removing operations. A more elegant way to manipulate this is using a CSCreator, providing high level methods for the different content stream operations.


Method Summary
 void addMarkedContent(COSName mark, byte[] content)
          Add "content" at the end of the "marked content" portion in the content stream of this.
 void addOperation(CSOperation op)
          Add another operation to the rendering program.
 void addOperation(int index, CSOperation op)
          Add another operation to the rendering program.
static CSContent createFromBytes(byte[] data)
          Create CSContent from a byte array containing a PDF content stream.
static CSContent createFromCos(COSArray streams)
          Create CSContent from an array of COSStream, together defining a PDF content stream.
static CSContent createFromCos(COSStream stream)
          Create CSContent from a COSStream containing a PDF content stream.
static CSContent createNew()
          Create a new CSContent.
 COSStream createStream()
           
 CSOperation getLastOperation()
          remove last operation from the rendering program.
 CSOperation getOperation(int index)
           
 CSOperation[] getOperations()
           
 void removeLastOperation()
          remove last operation from the rendering program.
 void removeOperation(int index)
           
 void setMarkedContent(COSName mark, byte[] content)
          Set the "marked content" portion in the content stream of this.
 int size()
          The number of operations in the content stream.
 byte[] toByteArray()
          Create the byte representation from the list of operations.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

createFromBytes

public static CSContent createFromBytes(byte[] data)
Create CSContent from a byte array containing a PDF content stream.

Parameters:
data - The bytes defining the PDF content stream.
Returns:
The new CSContent

createFromCos

public static CSContent createFromCos(COSStream stream)
Create CSContent from a COSStream containing a PDF content stream.

Parameters:
stream - The stream defining containing the PDF content stream.
Returns:
The new CSContent

createFromCos

public static CSContent createFromCos(COSArray streams)
Create CSContent from an array of COSStream, together defining a PDF content stream.

Parameters:
streams - An array of COSStream objects containing each a chunk of the content stream.
Returns:
The new CSContent.

createNew

public static CSContent createNew()
Create a new CSContent.

Returns:
The new CSContent.

getLastOperation

public CSOperation getLastOperation()
remove last operation from the rendering program.

Returns:
the last operation, or null of no operations left

setMarkedContent

public void setMarkedContent(COSName mark,
                             byte[] content)
Set the "marked content" portion in the content stream of this. Marked content is enclosed between "BMC" and "EMC", the begin operation has an operand identifying the type of marked content.

The portion between the marks is replaced with content.If no marks are found, the new content is appended as a marked content section.

Parameters:
mark - The type of marked content we search
content - The content we want to use.

addMarkedContent

public void addMarkedContent(COSName mark,
                             byte[] content)
Add "content" at the end of the "marked content" portion in the content stream of this.

Parameters:
mark - The type of marked content we search
content - The content we want to use.

addOperation

public void addOperation(CSOperation op)
Add another operation to the rendering program.

Parameters:
op - The new operation to append.

addOperation

public void addOperation(int index,
                         CSOperation op)
Add another operation to the rendering program.

Parameters:
op - The new operation to append.

removeOperation

public void removeOperation(int index)

getOperations

public CSOperation[] getOperations()

getOperation

public CSOperation getOperation(int index)

createStream

public COSStream createStream()

removeLastOperation

public void removeLastOperation()
remove last operation from the rendering program.


size

public int size()
The number of operations in the content stream.

Returns:
The number of operations in the content stream.

toByteArray

public byte[] toByteArray()
Create the byte representation from the list of operations.

Returns:
The byte representation from the list of operations.

toString

public String toString()
Overrides:
toString in class Object

intarsys PDF library API

Copyright © 2006 intarsys consulting GmbH. All Rights Reserved.