Click or drag to resize
Pdf Library for .NET

PdfCompressor Class

This class can be used to compress an existing PDF document.
Inheritance Hierarchy
SystemObject
  SelectPdf.ExtrasPdfManager
    SelectPdf.CompressorPdfCompressor

Namespace: SelectPdf.Compressor
Assembly: Select.Pdf.Extras (in Select.Pdf.Extras.dll) Version: 26.2
Syntax
public class PdfCompressor : PdfManager

The PdfCompressor type exposes the following members.

Constructors
 NameDescription
Public methodPdfCompressor Instantiates the PdfCompressor object.
Top
Properties
 NameDescription
Public propertyDocumentInformation PDF document information. Most of this property info is populated after Load. Some info is populated after Save.
(Inherited from PdfManager)
Public propertyImagesCompressionEnabled Gets or sets a flag indicating if the images compression is enabled or not for the images in the pdf document.
Public propertyImagesCompressionLevel Gets or sets the compression level of images in the generated pdf document. This is a value between 0 - no compression, 100 - best compression.
Public propertyRemoveDuplicateFonts Gets or sets a flag indicating if the duplicated fonts are removed or not from the pdf document.
Public propertyRemoveUnusedFontGlyphs Gets or sets a flag indicating if the unused font glyphs are removed or not from the pdf document.
Public propertyStreamsCompressionLevel This property controls the compression level of the pdf document.
Public propertyStructureCompressionEnabled Gets or sets a flag indicating if the full compression is enabled or not for the pdf document.
Top
Methods
 NameDescription
Public methodClose Closes the opened pdf document.
(Inherited from PdfManager)
Public methodLoad(Byte) Loads a pdf document from a byte array.
(Inherited from PdfManager)
Public methodLoad(Stream) Loads a pdf document from the specified stream.
(Inherited from PdfManager)
Public methodLoad(String) Loads a pdf document from an existing pdf file.
(Inherited from PdfManager)
Public methodLoad(Byte, String) Loads a password protected pdf document from a byte array.
(Inherited from PdfManager)
Public methodLoad(Stream, String) Loads a pdf document from a stream containing a password protected pdf document.
(Inherited from PdfManager)
Public methodLoad(String, String) Loads a pdf document from an existing password protected pdf file.
(Inherited from PdfManager)
Public methodSave Saves the pdf document as byte array.
(Inherited from PdfManager)
Public methodSave(Stream) Saves the pdf document to the specified stream.
(Inherited from PdfManager)
Public methodSave(String) Saves the pdf document to the specified file.
(Inherited from PdfManager)
Top
Example
The following sample code shows how to use PdfCompressor class to compress an existing PDF document.
// existing PDF document
string file = @"C:\path\to\document.pdf";

// load existing file
SelectPdf.Compressor.PdfCompressor compressor = new SelectPdf.Compressor.PdfCompressor();
compressor.Load(file);

// set compression options
compressor.StreamsCompressionLevel = SelectPdf.Compressor.PdfCompressionLevel.BestCompression;
compressor.StructureCompressionEnabled = true;
compressor.RemoveDuplicateFonts = true;
compressor.RemoveUnusedFontGlyphs = true;
compressor.ImagesCompressionEnabled = true;
compressor.ImagesCompressionLevel = 20;

// save compressed document
compressor.Save(file + "-compressed.pdf");
See Also