PDFsharp & MigraDoc Foundation

Using the PDFsharp/MigraDoc PDF compression options
Page 1 of 1

Author:  TH-Soft [ Sun Mar 25, 2018 11:33 am ]
Post subject:  Using the PDFsharp/MigraDoc PDF compression options

PDFsharp has some options you can use to control compression.
You can activate some options to generate smaller PDF files – at the price of longer creation times.

To create small PDF files, I recommend these settings:
document.Options.FlateEncodeMode = PdfFlateEncodeMode.BestCompression;
document.Options.UseFlateDecoderForJpegImages = PdfUseFlateDecoderForJpegImages.Automatic;
document.Options.NoCompression = false;
// Defaults to false in debug build, so we set it to true.
document.Options.CompressContentStreams = true;

And how to do it with MigraDoc?
The "PdfDocumentRenderer" class creates the "PdfDocument" object when needed. Just create the PdfDocument object yourself before doing anything with the renderer.
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);
pdfRenderer.PdfDocument = new PdfDocument();
pdfRenderer.PdfDocument.Options.FlateEncodeMode = PdfFlateEncodeMode.BestCompression;

This post applies to PDFsharp 1.50. Older versions may not have the settings described here, newer versions may have more or different options.

See the full blog post here:
http://developer.th-soft.com/developer/ ... s/#more-94

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group