Class PDPageContentStream

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

public final class PDPageContentStream extends PDAbstractContentStream implements Closeable
Provides the ability to write to a page content stream.
  • Field Details

    • LOG

      private static final org.apache.commons.logging.Log LOG
    • sourcePageHadContents

      private boolean sourcePageHadContents
  • Constructor Details

    • PDPageContentStream

      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 - 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, PDPageContentStream.AppendMode appendContent, boolean compress) throws IOException
      Create a new PDPage content stream. If the appendContent parameter is set to PDPageContentStream.AppendMode.APPEND, you may want to use PDPageContentStream(PDDocument, PDPage, PDPageContentStream.AppendMode, boolean, boolean) instead, with the fifth parameter set to true.
      Parameters:
      document - The document the page is part of.
      sourcePage - The page to write the contents to.
      appendContent - Indicates whether content will be overwritten, appended or prepended.
      compress - Tell if the content stream should compress the page contents.
      Throws:
      IOException - If there is an error writing to the page contents.
    • PDPageContentStream

      public PDPageContentStream(PDDocument document, PDPage sourcePage, PDPageContentStream.AppendMode appendContent, boolean compress, boolean resetContext) 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, appended or prepended.
      compress - Tell if the content stream should compress the page contents.
      resetContext - Tell if the graphic context should be reset. This is only relevant when the appendContent parameter is set to PDPageContentStream.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).
      Throws:
      IOException - If there is an error writing to the page contents.
    • PDPageContentStream

      private PDPageContentStream(PDDocument document, PDPage sourcePage, PDPageContentStream.AppendMode appendContent, boolean compress, boolean resetContext, PDStream stream, PDResources resources) throws IOException
      Throws:
      IOException
    • PDPageContentStream

      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 - The document the page is part of.
      appearance - The appearance stream to write to.
      Throws:
      IOException - If there is an error writing to the page contents.
    • PDPageContentStream

      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 - The document the appearance is part of.
      appearance - The appearance stream to add to.
      outputStream - The appearances output stream to write to.
  • Method Details

    • appendRawCommands

      @Deprecated 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 - The commands to append to the stream.
      Throws:
      IOException - If an error occurs while writing to the stream.
    • appendRawCommands

      @Deprecated 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 - The commands to append to the stream.
      Throws:
      IOException - If an error occurs while writing to the stream.
    • appendRawCommands

      @Deprecated 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 - Append a raw byte to the stream.
      Throws:
      IOException - If an error occurs while writing to the stream.
    • appendRawCommands

      @Deprecated 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 - Append a formatted double value to the stream.
      Throws:
      IOException - If an error occurs while writing to the stream.
    • appendRawCommands

      @Deprecated 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 - Append a formatted float value to the stream.
      Throws:
      IOException - If an error occurs while writing to the stream.