Reduce PDF size

PDFKit5 includes support for non-desctructive PDF compresssion. Invoking the compression tool is as simple as follows:

using (FileStream input = new FileStream(inputPath, FileMode.Open, FileAccess.Read))
{
   using (FileStream output = new FileStream(outputPath, FileMode.Create, FileAccess.Write))
   {
      Document.Rewrite(input, output, ReduceOptions.All);
   }
}				

The compression algorithm can be fine tuned using the ReduceOptions enum by enabling any of the following optional steps:

  • RemoveIdenticalObjects: a generic algorithm that replaces identical PDF objects with references to a single instance
  • RewriteContentStreams: try to rewrite content streams to optimize size
  • RecompressContentStreams: recompress content streams using options that result in maximal compression ratio
  • CompressDocument : compresses object and cross reference streams