Class PDAppearanceContentStream

java.lang.Object
org.apache.pdfbox.pdmodel.PDAbstractContentStream
org.apache.pdfbox.pdmodel.PDAppearanceContentStream
All Implemented Interfaces:
Closeable, AutoCloseable

public final class PDAppearanceContentStream extends PDAbstractContentStream implements Closeable
Provides the ability to write to an appearance content stream.
  • Constructor Details

    • PDAppearanceContentStream

      public PDAppearanceContentStream(PDAppearanceStream appearance) throws IOException
      Create a new appearance stream.
      Parameters:
      appearance - The appearance stream to write to.
      Throws:
      IOException - If there is an error writing to the content stream.
    • PDAppearanceContentStream

      public PDAppearanceContentStream(PDAppearanceStream appearance, boolean compress) throws IOException
      Create a new appearance stream.
      Parameters:
      appearance - The appearance stream to write to.
      compress - whether the content stream is to be compressed. Set this to true when creating long content streams.
      Throws:
      IOException - If there is an error writing to the content stream.
    • PDAppearanceContentStream

      public PDAppearanceContentStream(PDAppearanceStream appearance, OutputStream outputStream)
      Create a new appearance stream.
      Parameters:
      appearance - The appearance stream to add to.
      outputStream - The appearances output stream to write to.
  • Method Details

    • setStrokingColorOnDemand

      public boolean setStrokingColorOnDemand(PDColor color) throws IOException
      Set the stroking color.

      The command is only emitted if the color is not null and the number of components is > 0.

      Parameters:
      color - The colorspace to write.
      Throws:
      IOException - If there is an error writing to the content stream.
      See Also:
    • setStrokingColor

      public void setStrokingColor(float[] components) throws IOException
      Set the stroking color.
      Parameters:
      components - the color components dependent on the color space being used.
      Throws:
      IOException - If there is an error writing to the content stream.
      See Also:
    • setNonStrokingColorOnDemand

      public boolean setNonStrokingColorOnDemand(PDColor color) throws IOException
      Set the non stroking color.

      The command is only emitted if the color is not null and the number of components is > 0.

      Parameters:
      color - The colorspace to write.
      Throws:
      IOException - If there is an error writing to the content stream.
      See Also:
    • setNonStrokingColor

      public void setNonStrokingColor(float[] components) throws IOException
      Set the non stroking color.
      Parameters:
      components - the color components dependent on the color space being used.
      Throws:
      IOException - If there is an error writing to the content stream.
      See Also:
    • setBorderLine

      public void setBorderLine(float lineWidth, PDBorderStyleDictionary bs, COSArray border) throws IOException
      Convenience method for annotations: sets the line with and dash style.
      Parameters:
      lineWidth - The line width.
      bs - The border style, may be null.
      border - The border array, must have at least three entries. This is only used if the border style is null.
      Throws:
      IOException - If there is an error writing to the content stream.
    • setLineWidthOnDemand

      public void setLineWidthOnDemand(float lineWidth) throws IOException
      Sets the line width. The command is only emitted if the lineWidth is different to 1.
      Parameters:
      lineWidth - the line width of the path.
      Throws:
      IOException - If there is an error writing to the content stream.
      See Also:
    • drawShape

      public void drawShape(float lineWidth, boolean hasStroke, boolean hasFill) throws IOException
      Draw a shape.

      Dependent on the lineWidth and whether or not there is a background to be generated there are different commands to be used for draw a shape.

      Parameters:
      lineWidth - the line width of the path.
      hasStroke - shall there be a stroking color.
      hasFill - shall there be a fill color.
      Throws:
      IOException - If there is an error writing to the content stream.