org.pdfbox.pdmodel.edit
Class PDPageContentStream

java.lang.Object
  extended byorg.pdfbox.pdmodel.edit.PDPageContentStream

public class PDPageContentStream
extends Object

This class will is a convenience for creating page content streams. You MUST call close() when you are finished with this object.

Version:
$Revision: 1.18 $
Author:
Ben Litchfield

Constructor Summary
PDPageContentStream(PDDocument document, PDPage sourcePage)
          Create a new PDPage content stream.
PDPageContentStream(PDDocument document, PDPage sourcePage, boolean appendContent, boolean compress)
          Create a new PDPage content stream.
 
Method Summary
 void appendRawCommands(byte[] commands)
          This will append raw commands to the content stream.
 void appendRawCommands(int data)
          This will append raw commands to the content stream.
 void appendRawCommands(String commands)
          This will append raw commands to the content stream.
 void beginText()
          Begin some text operations.
 void close()
          Close the content stream.
 void drawImage(PDXObjectImage image, float x, float y)
          Draw an image at the x,y coordinates, with the default size of the image.
 void drawImage(PDXObjectImage image, float x, float y, float width, float height)
          Draw an image at the x,y coordinates and a certain width and height.
 void drawString(String text)
          This will draw a string at the current location on the screen.
 void endText()
          End some text operations.
 void fillRect(float x, float y, float width, float height)
          Draw a rectangle on the page using the current non stroking color.
 void moveTextPositionByAmount(float x, float y)
          The Td operator.
 void setFont(PDFont font, float fontSize)
          Set the font to draw text with.
 void setNonStrokingColor(Color color)
          Set the non stroking color, specified as RGB.
 void setNonStrokingColor(double g)
          Set the non stroking color, specified as Grayscale 0.0-1.0.
 void setNonStrokingColor(double c, double m, double y, double k)
          Set the non stroking color, specified as CMYK, 0.0-1.0.
 void setNonStrokingColor(float[] components)
          Set the color components of current non stroking colorspace.
 void setNonStrokingColor(int g)
          Set the non stroking color, specified as grayscale, 0-255.
 void setNonStrokingColor(int r, int g, int b)
          Set the non stroking color, specified as RGB, 0-255.
 void setNonStrokingColor(int c, int m, int y, int k)
          Set the non stroking color, specified as CMYK, 0-255.
 void setNonStrokingColorSpace(PDColorSpace colorSpace)
          Set the stroking color space.
 void setStrokingColor(Color color)
          Set the stroking color, specified as RGB.
 void setStrokingColor(double g)
          Set the stroking color, specified as Grayscale 0.0-1.0.
 void setStrokingColor(double c, double m, double y, double k)
          Set the stroking color, specified as CMYK, 0.0-1.0.
 void setStrokingColor(float[] components)
          Set the color components of current stroking colorspace.
 void setStrokingColor(int g)
          Set the stroking color, specified as grayscale, 0-255.
 void setStrokingColor(int r, int g, int b)
          Set the stroking color, specified as RGB, 0-255.
 void setStrokingColor(int c, int m, int y, int k)
          Set the stroking color, specified as CMYK, 0-255.
 void setStrokingColorSpace(PDColorSpace colorSpace)
          Set the stroking color space.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PDPageContentStream

public PDPageContentStream(PDDocument document,
                           PDPage sourcePage)
                    throws IOException
Create a new PDPage content stream.

Parameters:
document - The document the page is part of.
sourcePage - The page to write the contents to.
Throws:
IOException - If there is an error writing to the page contents.

PDPageContentStream

public PDPageContentStream(PDDocument document,
                           PDPage sourcePage,
                           boolean appendContent,
                           boolean compress)
                    throws IOException
Create a new PDPage content stream.

Parameters:
document - The document the page is part of.
sourcePage - The page to write the contents to.
appendContent - Indicates whether content will be overwritten. If false all previous content is deleted.
compress - Tell if the content stream should compress the page contents.
Throws:
IOException - If there is an error writing to the page contents.
Method Detail

beginText

public void beginText()
               throws IOException
Begin some text operations.

Throws:
IOException - If there is an error writing to the stream or if you attempt to nest beginText calls.

endText

public void endText()
             throws IOException
End some text operations.

Throws:
IOException - If there is an error writing to the stream or if you attempt to nest endText calls.

setFont

public void setFont(PDFont font,
                    float fontSize)
             throws IOException
Set the font to draw text with.

Parameters:
font - The font to use.
fontSize - The font size to draw the text.
Throws:
IOException - If there is an error writing the font information.

drawImage

public void drawImage(PDXObjectImage image,
                      float x,
                      float y)
               throws IOException
Draw an image at the x,y coordinates, with the default size of the image.

Parameters:
image - The image to draw.
x - The x-coordinate to draw the image.
y - The y-coordinate to draw the image.
Throws:
IOException - If there is an error writing to the stream.

drawImage

public void drawImage(PDXObjectImage image,
                      float x,
                      float y,
                      float width,
                      float height)
               throws IOException
Draw an image at the x,y coordinates and a certain width and height.

Parameters:
image - The image to draw.
x - The x-coordinate to draw the image.
y - The y-coordinate to draw the image.
width - The width of the image to draw.
height - The height of the image to draw.
Throws:
IOException - If there is an error writing to the stream.

moveTextPositionByAmount

public void moveTextPositionByAmount(float x,
                                     float y)
                              throws IOException
The Td operator.

Parameters:
x - The x coordinate.
y - The y coordinate.
Throws:
IOException - If there is an error writing to the stream.

drawString

public void drawString(String text)
                throws IOException
This will draw a string at the current location on the screen.

Parameters:
text - The text to draw.
Throws:
IOException - If an io exception occurs.

setStrokingColorSpace

public void setStrokingColorSpace(PDColorSpace colorSpace)
                           throws IOException
Set the stroking color space. This will add the colorspace to the PDResources if necessary.

Parameters:
colorSpace - The colorspace to write.
Throws:
IOException - If there is an error writing the colorspace.

setNonStrokingColorSpace

public void setNonStrokingColorSpace(PDColorSpace colorSpace)
                              throws IOException
Set the stroking color space. This will add the colorspace to the PDResources if necessary.

Parameters:
colorSpace - The colorspace to write.
Throws:
IOException - If there is an error writing the colorspace.

setStrokingColor

public void setStrokingColor(float[] components)
                      throws IOException
Set the color components of current stroking colorspace.

Parameters:
components - The components to set for the current color.
Throws:
IOException - If there is an error while writing to the stream.

setStrokingColor

public void setStrokingColor(Color color)
                      throws IOException
Set the stroking color, specified as RGB.

Parameters:
color - The color to set.
Throws:
IOException - If an IO error occurs while writing to the stream.

setNonStrokingColor

public void setNonStrokingColor(Color color)
                         throws IOException
Set the non stroking color, specified as RGB.

Parameters:
color - The color to set.
Throws:
IOException - If an IO error occurs while writing to the stream.

setStrokingColor

public void setStrokingColor(int r,
                             int g,
                             int b)
                      throws IOException
Set the stroking color, specified as RGB, 0-255.

Parameters:
r - The red value.
g - The green value.
b - The blue value.
Throws:
IOException - If an IO error occurs while writing to the stream.

setStrokingColor

public void setStrokingColor(int c,
                             int m,
                             int y,
                             int k)
                      throws IOException
Set the stroking color, specified as CMYK, 0-255.

Parameters:
c - The cyan value.
m - The magenta value.
y - The yellow value.
k - The black value.
Throws:
IOException - If an IO error occurs while writing to the stream.

setStrokingColor

public void setStrokingColor(double c,
                             double m,
                             double y,
                             double k)
                      throws IOException
Set the stroking color, specified as CMYK, 0.0-1.0.

Parameters:
c - The cyan value.
m - The magenta value.
y - The yellow value.
k - The black value.
Throws:
IOException - If an IO error occurs while writing to the stream.

setStrokingColor

public void setStrokingColor(int g)
                      throws IOException
Set the stroking color, specified as grayscale, 0-255.

Parameters:
g - The gray value.
Throws:
IOException - If an IO error occurs while writing to the stream.

setStrokingColor

public void setStrokingColor(double g)
                      throws IOException
Set the stroking color, specified as Grayscale 0.0-1.0.

Parameters:
g - The gray value.
Throws:
IOException - If an IO error occurs while writing to the stream.

setNonStrokingColor

public void setNonStrokingColor(float[] components)
                         throws IOException
Set the color components of current non stroking colorspace.

Parameters:
components - The components to set for the current color.
Throws:
IOException - If there is an error while writing to the stream.

setNonStrokingColor

public void setNonStrokingColor(int r,
                                int g,
                                int b)
                         throws IOException
Set the non stroking color, specified as RGB, 0-255.

Parameters:
r - The red value.
g - The green value.
b - The blue value.
Throws:
IOException - If an IO error occurs while writing to the stream.

setNonStrokingColor

public void setNonStrokingColor(int c,
                                int m,
                                int y,
                                int k)
                         throws IOException
Set the non stroking color, specified as CMYK, 0-255.

Parameters:
c - The cyan value.
m - The magenta value.
y - The yellow value.
k - The black value.
Throws:
IOException - If an IO error occurs while writing to the stream.

setNonStrokingColor

public void setNonStrokingColor(double c,
                                double m,
                                double y,
                                double k)
                         throws IOException
Set the non stroking color, specified as CMYK, 0.0-1.0.

Parameters:
c - The cyan value.
m - The magenta value.
y - The yellow value.
k - The black value.
Throws:
IOException - If an IO error occurs while writing to the stream.

setNonStrokingColor

public void setNonStrokingColor(int g)
                         throws IOException
Set the non stroking color, specified as grayscale, 0-255.

Parameters:
g - The gray value.
Throws:
IOException - If an IO error occurs while writing to the stream.

setNonStrokingColor

public void setNonStrokingColor(double g)
                         throws IOException
Set the non stroking color, specified as Grayscale 0.0-1.0.

Parameters:
g - The gray value.
Throws:
IOException - If an IO error occurs while writing to the stream.

fillRect

public void fillRect(float x,
                     float y,
                     float width,
                     float height)
              throws IOException
Draw a rectangle on the page using the current non stroking color.

Parameters:
x - The lower left x coordinate.
y - The lower left y coordinate.
width - The width of the rectangle.
height - The height of the rectangle.
Throws:
IOException - If there is an error while drawing on the screen.

appendRawCommands

public void appendRawCommands(String commands)
                       throws IOException
This will append raw commands to the content stream.

Parameters:
commands - The commands to append to the stream.
Throws:
IOException - If an error occurs while writing to the stream.

appendRawCommands

public void appendRawCommands(byte[] commands)
                       throws IOException
This will append raw commands to the content stream.

Parameters:
commands - The commands to append to the stream.
Throws:
IOException - If an error occurs while writing to the stream.

appendRawCommands

public void appendRawCommands(int data)
                       throws IOException
This will append raw commands to the content stream.

Parameters:
data - Append a raw byte to the stream.
Throws:
IOException - If an error occurs while writing to the stream.

close

public void close()
           throws IOException
Close the content stream. This must be called when you are done with this object.

Throws:
IOException - If the underlying stream has a problem being written to.