In This Topic
Programming / PDF Optimization & MRC / Optimizing PDF documents by enabling MRC compression

Optimizing PDF documents by enabling MRC compression

In This Topic

The tool we are most proud of is our MRC compression engine based on MRC compression techniques (Hyper Compression). It can reduce the size of images together with improving the rendering quality. This approach uses image segmentation to compress areas with the optimum algorithm based on their characteristics. The method produces optimal results with document mixing text, graphics, and images.

For example, we can deliver the compression ratio from 686 KB to 69 KB using MRC. For proof please refer to this handy article as well as to our blog.

The usage of GdPicturePDFReducer class for this purpose is straightforward. With the help of PDFReducerConfiguration class, you can select options for benefiting from MRC compression as it is demonstrated in this example.

Copy Code
Dim gdpicturePDFReducer As GdPicturePDFReducer = New GdPicturePDFReducer()

'PDFReducerConfiguration class provides different properties and options for the compression.
gdpicturePDFReducer.PDFReducerConfiguration.Author = "GdPicture.NET PDF Reducer SDK"
gdpicturePDFReducer.PDFReducerConfiguration.Producer = "GdPicture.NET 14"
gdpicturePDFReducer.PDFReducerConfiguration.ProducerName = "Orpalis"
gdpicturePDFReducer.PDFReducerConfiguration.Title = "MRC Compression"

'When compressing your PDF files, you have the possibility to decide which version of PDF to use.
gdpicturePDFReducer.PDFReducerConfiguration.OutputFormat = PDFReducerPDFVersion.PdfVersionRetainExisting

'By selecting required options through the PDFReducerConfiguration class you enable or disable the features you want to accent.

gdpicturePDFReducer.PDFReducerConfiguration.RecompressImages = True

'MRC compression.
gdpicturePDFReducer.PDFReducerConfiguration.EnableMRC = True
gdpicturePDFReducer.PDFReducerConfiguration.DownscaleResolutionMRC = 200
gdpicturePDFReducer.PDFReducerConfiguration.PreserveSmoothing = True

Dim inputSize As Long = New System.IO.FileInfo("input.pdf").Length

'Processing the specified document.
Dim status As GdPictureStatus = gdpicturePDFReducer.ProcessDocument("input.pdf", "output.pdf")
If status = GdPictureStatus.OK Then
    Dim outputSize As Long = New System.IO.FileInfo("output.pdf").Length
    Dim ratio As Integer = 100 - CInt((outputSize * 100 / inputSize))
    MessageBox.Show("The compression ratio is " + ratio + "%." + vbCrLf + inputSize / 100 + "KB -> " + outputSize / 100 + "KB", "Optimizing PDF documents", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
    MessageBox.Show("The compression failed. Error: " + gdpicturePDFReducer.GetReducerStat(), "Optimizing PDF documents", MessageBoxButtons.OK, MessageBoxIcon.Error)
    'You can also check reported warnings or the page number when an error has been reported.
End If
Copy Code
GdPicturePDFReducer gdpicturePDFReducer = new GdPicturePDFReducer();

//PDFReducerConfiguration class provides different properties and options for the compression.
gdpicturePDFReducer.PDFReducerConfiguration.Author = "GdPicture.NET PDF Reducer SDK";
gdpicturePDFReducer.PDFReducerConfiguration.Producer = "GdPicture.NET 14";
gdpicturePDFReducer.PDFReducerConfiguration.ProducerName = "Orpalis";
gdpicturePDFReducer.PDFReducerConfiguration.Title = "MRC Compression";

//When compressing your PDF files, you have the possibility to decide which version of PDF to use.
gdpicturePDFReducer.PDFReducerConfiguration.OutputFormat = PDFReducerPDFVersion.PdfVersionRetainExisting;

//By selecting required options through the PDFReducerConfiguration class you enable or disable the features you want to accent.

gdpicturePDFReducer.PDFReducerConfiguration.RecompressImages = true;

//MRC compression.
gdpicturePDFReducer.PDFReducerConfiguration.EnableMRC = true;
gdpicturePDFReducer.PDFReducerConfiguration.DownscaleResolutionMRC = 200;
gdpicturePDFReducer.PDFReducerConfiguration.PreserveSmoothing = true;

long inputSize = new System.IO.FileInfo("input.pdf").Length;

//Processing the specified document.
GdPictureStatus status = gdpicturePDFReducer.ProcessDocument("input.pdf", "output.pdf");
if (status == GdPictureStatus.OK)
{
    long outputSize = new System.IO.FileInfo("output.pdf").Length;
    int ratio = 100 - (int)(outputSize * 100 / inputSize);
    MessageBox.Show("The compression ratio is " + ratio + "%.\n" + inputSize / 100 + "KB -> " + outputSize / 100 + "KB", "Optimizing PDF documents", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
    MessageBox.Show("The compression failed. Error: " + gdpicturePDFReducer.GetReducerStat(), "Optimizing PDF documents", MessageBoxButtons.OK, MessageBoxIcon.Error);
    //You can also check reported warnings or the page number when an error has been reported.
}