Package com.itextpdf.pdfoptimizer
Class PdfOptimizer
java.lang.Object
com.itextpdf.pdfoptimizer.PdfOptimizer
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 Summary
ConstructorDescriptionCreates a new instance of PdfOptimizer, the main entry point of the optimization process. -
Method Summary
Modifier and TypeMethodDescriptionAppends provided instance ofAbstractOptimizationHandler
to the current handler chain.ReadsPdfDocument
from providedPdfReader
and writes its optimized version in the new file.optimize
(com.itextpdf.kernel.pdf.PdfReader reader, OutputStream outputStream) ReadsPdfDocument
from providedPdfReader
and writes its optimized version in the providedOutputStream
.ReadsPdfDocument
from providedFile
and writes its optimized version in the new file.optimize
(File inputFile, OutputStream outputStream) optimize
(InputStream inputStream, File outputFile) ReadsPdfDocument
from providedInputStream
and writes its optimized version in the new file.optimize
(InputStream inputStream, OutputStream outputStream) ReadsPdfDocument
from providedInputStream
and writes its optimized version in the providedOutputStream
.void
setReportBuilder
(DefaultReportBuilder reportBuilder) Sets a custom instance ofDefaultReportBuilder
.
-
Constructor Details
-
PdfOptimizer
public PdfOptimizer()Creates a new instance of PdfOptimizer, the main entry point of the optimization process.
-
-
Method Details
-
addOptimizationHandler
Appends provided instance ofAbstractOptimizationHandler
to the current handler chain.- Parameters:
-
handler
- is an optimization handler - Returns:
- this instance
-
setReportBuilder
Sets a custom instance ofDefaultReportBuilder
.- Parameters:
-
reportBuilder
- is a report builder
-
optimize
ReadsPdfDocument
from providedFile
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
- 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
ReadsPdfDocument
from providedInputStream
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 ReadsPdfDocument
from providedInputStream
and writes its optimized version in the providedOutputStream
.- 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 ReadsPdfDocument
from providedPdfReader
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 ReadsPdfDocument
from providedPdfReader
and writes its optimized version in the providedOutputStream
.- 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
-