Top Description Inners Fields Constructors Methods
org.apache.pdfbox.pdmodel

public final Class PDPageContentStream

extends PDAbstractContentStream
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.Closeable, .IOException, .OutputStream, java.nio.charset.StandardCharsets, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.cos.COSArray, .COSBase, .COSName, org.apache.pdfbox.pdmodel.common.PDStream, org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream

Provides the ability to write to a page content stream.
Author
Ben Litchfield

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
PDPageContentStream.AppendMode

This is to choose what to do with the stream: overwrite, append or prepend.

Field Summary

Modifier and TypeField and Description
private static final Log
private boolean
Inherited from org.apache.pdfbox.pdmodel.PDAbstractContentStream:
documentfontStackinTextModenonStrokingColorSpaceStackoutputStreamresourcesstrokingColorSpaceStack

Constructor Summary

AccessConstructor and Description
public
PDPageContentStream(PDDocument
The document the page is part of.
document
,
PDPage
The page to write the contents to.
sourcePage
)

Create a new PDPage content stream.

public
PDPageContentStream(PDDocument
The document the page is part of.
document
,
PDPage
The page to write the contents to.
sourcePage
,
PDPageContentStream.AppendMode
Indicates whether content will be overwritten, appended or prepended.
appendContent
,
boolean
Tell if the content stream should compress the page contents.
compress
)

Create a new PDPage content stream.

public
PDPageContentStream(PDDocument
The document the page is part of.
document
,
PDPage
The page to write the contents to.
sourcePage
,
PDPageContentStream.AppendMode
Indicates whether content will be overwritten, appended or prepended.
appendContent
,
boolean
Tell if the content stream should compress the page contents.
compress
,
boolean
Tell if the graphic context should be reset. This is only relevant when the appendContent parameter is set to AppendMode#APPEND. You should use this when appending to an existing stream, because the existing stream may have changed graphic properties (e.g. scaling, rotation).
resetContext
)

Create a new PDPage content stream.

private
PDPageContentStream(PDDocument document, PDPage sourcePage, PDPageContentStream.AppendMode appendContent, boolean compress, boolean resetContext, PDStream stream, PDResources resources)

public
PDPageContentStream(PDDocument
The document the page is part of.
doc
,
PDAppearanceStream
The appearance stream to write to.
appearance
)

Create a new appearance stream.

public
PDPageContentStream(PDDocument
The document the appearance is part of.
doc
,
PDAppearanceStream
The appearance stream to add to.
appearance
,
OutputStream
The appearances output stream to write to.
outputStream
)

Create a new appearance stream.

Method Summary

Modifier and TypeMethod and Description
public void
appendRawCommands(String
The commands to append to the stream.
commands
)
Deprecated Usage of this method is discouraged.

This will append raw commands to the content stream.

public void
appendRawCommands(byte[]
The commands to append to the stream.
commands
)
Deprecated Usage of this method is discouraged.

This will append raw commands to the content stream.

public void
appendRawCommands(int
Append a raw byte to the stream.
data
)
Deprecated Usage of this method is discouraged.

This will append raw commands to the content stream.

public void
appendRawCommands(double
Append a formatted double value to the stream.
data
)
Deprecated Usage of this method is discouraged.

This will append raw commands to the content stream.

public void
appendRawCommands(float
Append a formatted float value to the stream.
data
)
Deprecated Usage of this method is discouraged.

This will append raw commands to the content stream.

Inherited from org.apache.pdfbox.pdmodel.PDAbstractContentStream:
addCommentaddRectbeginMarkedContentbeginMarkedContentbeginMarkedContentbeginTextclipclipEvenOddclosecloseAndFillAndStrokecloseAndFillAndStrokeEvenOddcloseAndStrokeclosePathcurveTocurveTo1curveTo2drawFormdrawImagedrawImagedrawImagedrawImagedrawImageendMarkedContentendTextfillfillAndStrokefillAndStrokeEvenOddfillEvenOddgetNameisOutside255IntervallineTomoveTonewLinenewLineAtOffsetrestoreGraphicsStatesaveGraphicsStatesetCharacterSpacingsetFontsetGraphicsStateParameterssetHorizontalScalingsetLeadingsetLineCapStylesetLineDashPatternsetLineJoinStylesetLineWidthsetMaximumFractionDigitssetMiterLimitsetNonStrokingColorsetNonStrokingColorsetNonStrokingColorsetNonStrokingColorsetNonStrokingColorsetNonStrokingColorSpaceStacksetRenderingModesetStrokingColorsetStrokingColorsetStrokingColorsetStrokingColorsetStrokingColorsetStrokingColorSpaceStacksetTextMatrixsetTextRisesetWordSpacingshadingFillshowTextshowTextInternalshowTextWithPositioningstroketransformwritewriteByteswriteLinewriteOperandwriteOperandwriteOperandwriteOperator

Field Detail

LOGback to summary
private static final Log LOG

Hides org.apache.pdfbox.pdmodel.PDAbstractContentStream.LOG.

sourcePageHadContentsback to summary
private boolean sourcePageHadContents

Constructor Detail

PDPageContentStreamback to summary
public PDPageContentStream(PDDocument document, PDPage sourcePage) throws IOException

Create a new PDPage content stream. This constructor overwrites all existing content streams of this page.

Parameters
document:PDDocument

The document the page is part of.

sourcePage:PDPage

The page to write the contents to.

Exceptions
IOException:
If there is an error writing to the page contents.
PDPageContentStreamback to summary
public PDPageContentStream(PDDocument document, PDPage sourcePage, PDPageContentStream.AppendMode appendContent, boolean compress) throws IOException

Create a new PDPage content stream. If the appendContent parameter is set to AppendMode#APPEND, you may want to use PDPageContentStream(PDDocument, PDPage, PDPageContentStream.AppendMode, boolean, boolean) instead, with the fifth parameter set to true.

Parameters
document:PDDocument

The document the page is part of.

sourcePage:PDPage

The page to write the contents to.

appendContent:PDPageContentStream.AppendMode

Indicates whether content will be overwritten, appended or prepended.

compress:boolean

Tell if the content stream should compress the page contents.

Exceptions
IOException:
If there is an error writing to the page contents.
PDPageContentStreamback to summary
public PDPageContentStream(PDDocument document, PDPage sourcePage, PDPageContentStream.AppendMode appendContent, boolean compress, boolean resetContext) throws IOException

Create a new PDPage content stream.

Parameters
document:PDDocument

The document the page is part of.

sourcePage:PDPage

The page to write the contents to.

appendContent:PDPageContentStream.AppendMode

Indicates whether content will be overwritten, appended or prepended.

compress:boolean

Tell if the content stream should compress the page contents.

resetContext:boolean

Tell if the graphic context should be reset. This is only relevant when the appendContent parameter is set to AppendMode#APPEND. You should use this when appending to an existing stream, because the existing stream may have changed graphic properties (e.g. scaling, rotation).

Exceptions
IOException:
If there is an error writing to the page contents.
PDPageContentStreamback to summary
private PDPageContentStream(PDDocument document, PDPage sourcePage, PDPageContentStream.AppendMode appendContent, boolean compress, boolean resetContext, PDStream stream, PDResources resources) throws IOException
PDPageContentStreamback to summary
public PDPageContentStream(PDDocument doc, PDAppearanceStream appearance) throws IOException

Create a new appearance stream. Note that this is not actually a "page" content stream.

Parameters
doc:PDDocument

The document the page is part of.

appearance:PDAppearanceStream

The appearance stream to write to.

Exceptions
IOException:
If there is an error writing to the page contents.
PDPageContentStreamback to summary
public PDPageContentStream(PDDocument doc, PDAppearanceStream appearance, OutputStream outputStream)

Create a new appearance stream. Note that this is not actually a "page" content stream.

Parameters
doc:PDDocument

The document the appearance is part of.

appearance:PDAppearanceStream

The appearance stream to add to.

outputStream:OutputStream

The appearances output stream to write to.

Method Detail

appendRawCommandsback to summary
public void appendRawCommands(String commands) throws IOException

Deprecated

Usage of this method is discouraged.

This will append raw commands to the content stream.

Parameters
commands:String

The commands to append to the stream.

Annotations
@Deprecated
Exceptions
IOException:
If an error occurs while writing to the stream.
appendRawCommandsback to summary
public void appendRawCommands(byte[] commands) throws IOException

Deprecated

Usage of this method is discouraged.

This will append raw commands to the content stream.

Parameters
commands:byte[]

The commands to append to the stream.

Annotations
@Deprecated
Exceptions
IOException:
If an error occurs while writing to the stream.
appendRawCommandsback to summary
public void appendRawCommands(int data) throws IOException

Deprecated

Usage of this method is discouraged.

This will append raw commands to the content stream.

Parameters
data:int

Append a raw byte to the stream.

Annotations
@Deprecated
Exceptions
IOException:
If an error occurs while writing to the stream.
appendRawCommandsback to summary
public void appendRawCommands(double data) throws IOException

Deprecated

Usage of this method is discouraged.

This will append raw commands to the content stream.

Parameters
data:double

Append a formatted double value to the stream.

Annotations
@Deprecated
Exceptions
IOException:
If an error occurs while writing to the stream.
appendRawCommandsback to summary
public void appendRawCommands(float data) throws IOException

Deprecated

Usage of this method is discouraged.

This will append raw commands to the content stream.

Parameters
data:float

Append a formatted float value to the stream.

Annotations
@Deprecated
Exceptions
IOException:
If an error occurs while writing to the stream.
org.apache.pdfbox.pdmodel back to summary

public final Enum PDPageContentStream.AppendMode

extends Enum<PDPageContentStream.AppendMode>
Class Inheritance

This is to choose what to do with the stream: overwrite, append or prepend.

Field Summary

Modifier and TypeField and Description
public static final PDPageContentStream.AppendMode
APPEND

Append the content stream after all existing page content streams.

public static final PDPageContentStream.AppendMode
OVERWRITE

Overwrite the existing page content streams.

public static final PDPageContentStream.AppendMode
PREPEND

Insert before all other page content streams.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
public boolean
public static PDPageContentStream.AppendMode
public static PDPageContentStream.AppendMode[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

APPENDback to summary
public static final PDPageContentStream.AppendMode APPEND

Append the content stream after all existing page content streams.

OVERWRITEback to summary
public static final PDPageContentStream.AppendMode OVERWRITE

Overwrite the existing page content streams.

PREPENDback to summary
public static final PDPageContentStream.AppendMode PREPEND

Insert before all other page content streams.

Constructor Detail

AppendModeback to summary
private AppendMode()

Method Detail

isOverwriteback to summary
public boolean isOverwrite()
isPrependback to summary
public boolean isPrepend()
valueOfback to summary
public static PDPageContentStream.AppendMode valueOf(String name)
valuesback to summary
public static PDPageContentStream.AppendMode[] values()