Class PdfOptimizer

java.lang.Object
com.itextpdf.pdfoptimizer.PdfOptimizer

public class PdfOptimizer extends Object
Entry point for Pdf Optimization process. Each Pdf Optimizer can be configured with required set of AbstractOptimizationHandler instances. Optimizer requires fully populated instance of PdfDocument to perform valid optimization. Processing of raw PdfDocument without all the calculations done may lead to unexpected and incorrect behaviour. That is why it is only allowed to pass the source of Pdf file instead of PdfDocument instance itself.
  • Constructor Details

    • PdfOptimizer

      public PdfOptimizer()
      Creates a new instance of PdfOptimizer, the main entry point of the optimization process.
  • Method Details

    • addOptimizationHandler

      public PdfOptimizer addOptimizationHandler (AbstractOptimizationHandler handler)
      Appends provided instance of AbstractOptimizationHandler to the current handler chain.
      Parameters:
      handler - is an optimization handler
      Returns:
      this instance
    • setReportBuilder

      public void setReportBuilder (DefaultReportBuilder reportBuilder)
      Sets a custom instance of DefaultReportBuilder.
      Parameters:
      reportBuilder - is a report builder
    • optimize

      public OptimizationResult optimize (File inputFile, File outputFile) throws IOException
      Reads PdfDocument from provided File and writes its optimized version in the new file.
      Parameters:
      inputFile - is a source of the PDF document
      outputFile - is a file where optimized document will be stored
      Returns:
      optimization process report as OptimizationResult
      Throws:
      IOException - if any input/output issue occurs
    • optimize

      public OptimizationResult optimize (File inputFile, OutputStream outputStream) throws IOException
      Reads PdfDocument from provided File and writes its optimized version in the provided OutputStream.
      Parameters:
      inputFile - is a source of the PDF document
      outputStream - is an output stream for optimized document
      Returns:
      optimization process report as OptimizationResult
      Throws:
      IOException - if any input/output issue occurs
    • optimize

      public OptimizationResult optimize (InputStream inputStream, File outputFile) throws IOException
      Reads PdfDocument from provided InputStream and writes its optimized version in the new file.
      Parameters:
      inputStream - is a source of the PDF document
      outputFile - is a file where optimized document will be stored
      Returns:
      optimization process report as OptimizationResult
      Throws:
      IOException - if any input/output issue occurs
    • optimize

      public OptimizationResult optimize (InputStream inputStream, OutputStream outputStream) throws IOException
      Reads PdfDocument from provided InputStream and writes its optimized version in the provided OutputStream.
      Parameters:
      inputStream - is a source of the PDF document
      outputStream - is an output stream for optimized document
      Returns:
      optimization process report as OptimizationResult
      Throws:
      IOException - if any input/output issue occurs
    • optimize

      public OptimizationResult optimize (com.itextpdf.kernel.pdf.PdfReader reader, File outputFile) throws IOException
      Reads PdfDocument from provided PdfReader and writes its optimized version in the new file.
      Parameters:
      reader - is a source of the PDF document
      outputFile - is a file where optimized document will be stored
      Returns:
      optimization process report as OptimizationResult
      Throws:
      IOException - if any input/output issue occurs
    • optimize

      public OptimizationResult optimize (com.itextpdf.kernel.pdf.PdfReader reader, OutputStream outputStream) throws IOException
      Reads PdfDocument from provided PdfReader and writes its optimized version in the provided OutputStream.
      Parameters:
      reader - is a source of the PDF document
      outputStream - is an output stream for optimized document
      Returns:
      optimization process report as OptimizationResult
      Throws:
      IOException - if any input/output issue occurs