Class ExistingPagesSizePredictor

java.lang.Object
org.sejda.sambox.output.PDFBodyWriter
org.sejda.sambox.output.ExistingPagesSizePredictor
All Implemented Interfaces:
Closeable, AutoCloseable, COSVisitor

public class ExistingPagesSizePredictor extends PDFBodyWriter
Component that tries to predict the size of a resulting document if PDPages and COSObjectables are added to it. The component does its best to return exact predicted values and it does that by simulating an actual write, despite that, the predicted values should be considered rough estimations and not a byte precision ones.
  • Field Details

    • LOG

      private static final org.slf4j.Logger LOG
    • STREAM_WRAPPING_SIZE

      private static final int STREAM_WRAPPING_SIZE
      See Also:
    • channel

      private final org.sejda.io.CountingWritableByteChannel channel
    • writer

      private final IndirectObjectsWriter writer
    • pages

      private long pages
  • Constructor Details

  • Method Details

    • addPage

      public void addPage(PDPage page) throws IOException
      Adds a PDPage to the predicted size. This component simulates the page write to a DevNullWritableByteChannel and does not release the page objects once written.
      Parameters:
      page -
      Throws:
      IOException
    • addIndirectReferenceFor

      public void addIndirectReferenceFor(COSObjectable value) throws IOException
      Adds the COSObjectable to the predicted size. The object is added as an indirect reference and is processed, specifically, in case of COSDictionary or COSArray, indirect reference might be created for their values.
      Parameters:
      value -
      Throws:
      IOException
    • predictedPagesSize

      public long predictedPagesSize() throws IOException
      Returns:
      the current predicted page size
      Throws:
      IOException
    • predictedXrefTableSize

      public long predictedXrefTableSize()
      Returns:
      the current predicted xref size
      Throws:
      IOException
    • hasPages

      public boolean hasPages()
      Returns:
      true if some page has been written
    • pages

      public long pages()
      Returns:
      the current number of written pages
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class PDFBodyWriter
      Throws:
      IOException
    • instance

      public static ExistingPagesSizePredictor instance(WriteOption... opts)
      Factory method for an ExistingPagesSizePredictor
      Parameters:
      opts -
      Returns: