Namespace SoftZenPdf.Optimizer

Classes

BitmapCompressor

Compresses bitmap images losslessly: every pixel decodes to exactly the colour it had before. RGB images whose pixels are all grey are stored as greyscale, images with few colours are stored as a palette (1, 2, 4 or 8 bits per pixel), sample values that fit a smaller bit depth exactly are stored with fewer bits, and the result is Deflate-compressed with PNG predictors when that is smaller. Images whose /Decode array or colour-key mask gives their sample values a meaning of their own are only recompressed, and images whose soft mask has a /Matte colour (given in the image's own colour space) keep their colour space.

BitmapToJpegConverter

Converts photographic bitmap images to JPEG. Only 8-bit greyscale, RGB and CMYK images with more than 256 colours are converted; soft masks, palette images, images with colour-key masks and images with few colours (logos, diagrams, screenshots, which JPEG would blur) are handed to OtherImages instead. A photograph is also kept lossless when that is smaller than the JPEG.

ColorSpaceConverter

Converts CMYK images to RGB, which takes three samples per pixel instead of four and lets JPEGs use YCbCr with subsampled colour. Colours are converted with a device formula (see Formula), after the image's /Decode array, without colour management, so they can shift from how a colour-managed viewer shows CMYK. JPEGs are saved again as JPEG at their original quality, other images losslessly, and palette images only have their palette converted. Run it before an ImageQualityOptimizer so the converted images are compressed too.

CompressionOptimizer

Recompresses every stream that is not image-codec data (page content, fonts, forms, ICC profiles, uncompressed images and so on) with Deflate at the strongest setting, and strips encoding filters such as ASCII85 that sit in front of JPEG, CCITT, JBIG2 or JPEG 2000 data. A stream is only replaced when the result is smaller. Metadata streams are left as they are so they stay readable by tools that scan files for XMP. With UseObjectStreams, every other object is packed into compressed object streams as well.

DuplicateResourceOptimizer

Keeps one copy of any resource that is stored more than once: images, form XObjects, fonts, ICC profiles, colour spaces, graphics states, shadings, functions and the like, for example a logo embedded separately on every page. Streams are compared by their decoded data where it can be decoded. Pages, annotations, form fields, bookmarks and structure elements are never merged, even when identical.

FontDuplicationOptimizer

Keeps one copy of fonts that are embedded more than once, as happens when documents are merged or a font is embedded per page. Font dictionaries, descriptors, font programs, ToUnicode CMaps and width arrays are merged when they are identical; font programs are compared by their decoded bytes, so the same font compressed differently still counts as a duplicate. Different subsets of the same font are not merged.

HandlerResult

What one OptimizationHandler changed.

ImageProcessor

Processes one kind of image for an ImageQualityOptimizer, for example JpegCompressor or BitmapCompressor.

ImageQualityOptimizer

Optimizes the images in a document with the processor set for each kind of image. Each image is replaced only when the processed version is smaller; what happened to every image is reported in Images.

ImageResolutionOptimizer

Reduces images that have more pixels than the size they are drawn at needs, like Acrobat's "downsample to 150 ppi for images above 225 ppi". How large each image is drawn is measured from the page content; an image drawn more than once is sized for its largest use, and one also used somewhere that cannot be measured (an annotation, pattern or glyph) is left alone. Reduced JPEGs are re-encoded as JPEG at their original quality; other images stay lossless. 1, 2, 4 and 16-bit images, palette images, stencil masks and images with colour-key masks are not resized, since averaging would invent sample values they cannot hold.

ImageResult

What an image processor did with one image, and its size before and after.

JpegCompressor

Recompresses JPEG images at a chosen quality. Colours are kept exactly as the PDF defines them: grey and RGB images are stored as JFIF (RGB as YCbCr), CMYK images as stored, keeping an Adobe marker if the original had one, and the image's colour space, /Decode array and masks are left unchanged.

OptimizationHandler

One kind of optimization. Add handlers to a PdfOptimizer with AddOptimizationHandler(OptimizationHandler); they run in the order they were added.

OptimizationResult

What Optimize(string, string, string?) did, and how much it saved.

PdfOptimizer

Makes PDFs smaller. Add the optimizations you want with AddOptimizationHandler(OptimizationHandler), then call Optimize. The output is a complete new file: unused objects and earlier revisions are dropped, and the input's encryption, passwords and permissions are kept.

Enums

CmykToRgbFormula

How ColorSpaceConverter turns CMYK into RGB, without colour management.

ImageOutcome

What happened to one image.