Class ImageQualityOptimizer

java.lang.Object
com.itextpdf.pdfoptimizer.AbstractOptimizationHandler
com.itextpdf.pdfoptimizer.handlers.ImageQualityOptimizer

public class ImageQualityOptimizer extends AbstractOptimizationHandler
Looks for image streams and performs theirs optimization.
  • Constructor Details

    • ImageQualityOptimizer

      public ImageQualityOptimizer()
      Creates an empty image quality optimizer.
    • ImageQualityOptimizer

      public ImageQualityOptimizer (MapIImageProcessor> processors)
      Creates a new image quality optimizer with custom configuration of image processors. Note that type of the image is identifying based on PdfImageXObject.identifyImageType() call.
      Parameters:
      processors - is a map where image types are associated with processors for them
      See Also:
      • PdfImageXObject.identifyImageType()
  • Method Details

    • setJpegProcessor

      public ImageQualityOptimizer setJpegProcessor (IImageProcessor processor)
      Sets a processor for ImageType.JPEG images. Note that type of the image is identifying based on PdfImageXObject.identifyImageType() call.
      Parameters:
      processor - is an image processor to set
      Returns:
      this instance
      See Also:
      • PdfImageXObject.identifyImageType()
    • setJpeg2000Processor

      public ImageQualityOptimizer setJpeg2000Processor (IImageProcessor processor)
      Sets a processor for ImageType.JPEG2000 images. Note that type of the image is identifying based on PdfImageXObject.identifyImageType() call.
      Parameters:
      processor - is an image processor to set
      Returns:
      this instance
      See Also:
      • PdfImageXObject.identifyImageType()
    • setJBig2Processor

      public ImageQualityOptimizer setJBig2Processor (IImageProcessor processor)
      Sets a processor for ImageType.JBIG2 images. Note that type of the image is identifying based on PdfImageXObject.identifyImageType() call.
      Parameters:
      processor - is an image processor to set
      Returns:
      this instance
      See Also:
      • PdfImageXObject.identifyImageType()
    • setTiffProcessor

      public ImageQualityOptimizer setTiffProcessor (IImageProcessor processor)
      Sets a processor for ImageType.TIFF images. Note that type of the image is identifying based on PdfImageXObject.identifyImageType() call.
      Parameters:
      processor - is an image processor to set
      Returns:
      this instance
      See Also:
      • PdfImageXObject.identifyImageType()
    • setPngProcessor

      public ImageQualityOptimizer setPngProcessor (IImageProcessor processor)
      Sets a processor for ImageType.PNG images. Note that type of the image is identifying based on PdfImageXObject.identifyImageType() call.
      Parameters:
      processor - is an image processor to set
      Returns:
      this instance
      See Also:
      • PdfImageXObject.identifyImageType()
    • setPredicate

      public ImageQualityOptimizer setPredicate (PdfImageXObjectPredicate predicate)
      Sets a search predicate. Allows to provide custom implementation of PdfImageXObjectPredicate with overridden method PdfImageXObjectPredicate.customCondition(PdfObject) to skip some types of images during optimization process.
      Parameters:
      predicate - is a predicate to set
      Returns:
      this instance
    • getPredicate

      public PdfImageXObjectPredicate getPredicate()
      Gets current search predicate. If it was not set return default implementation.
      Returns:
      search predicate.
    • getImageProcessors

      public MapIImageProcessor> getImageProcessors()
      Gets a copy of current configuration of the image processor.
      Returns:
      a map where ImageType keys are associated with actual IImageProcessor
    • optimizePdf

      protected void optimizePdf (com.itextpdf.kernel.pdf.PdfDocument document, OptimizationSession session)
      The method searches across all the document and for each found PdfImageXObject performs an optimization according to its type.
      Specified by:
      optimizePdf in class AbstractOptimizationHandler
      Parameters:
      document - is the PDF document to optimize. Invocation of the method can change the state of the object
      session - is an auxiliary object used to support share data between stages of optimization process