VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
Vintasoft.Imaging.Pdf.Processing Namespace / PdfDocumentCompressorCommand Class / CreateLossyCompressor Methods / CreateLossyCompressor(Double,Boolean,Boolean,Boolean) Method
Syntax Example Requirements SeeAlso
In This Topic
CreateLossyCompressor(Double,Boolean,Boolean,Boolean) Method (PdfDocumentCompressorCommand)
In This Topic
Creates the lossy PDF compressor.
Syntax
'Declaration

Public Overloads Shared Function CreateLossyCompressor( _
ByVal viewResolution
The resolution, in DPI, to view compressed document in applications.
As Double, _
ByVal useJbig2
A value indicating whether the compressor must use JBIG2 lossless compression instead of CcittFax compression for bitonal images.
As Boolean, _
ByVal useJpeg2000
A value indicating whether the compressor must use JPEG2000 lossless compression instead of Flate(ZIP) for color and grayscale images.
As Boolean, _
ByVal subsetFonts
A value indicating whether the compressor must subset fonts.
As Boolean _
) As PdfDocumentCompressorCommand

Parameters

viewResolution
The resolution, in DPI, to view compressed document in applications.
useJbig2
A value indicating whether the compressor must use JBIG2 lossless compression instead of CcittFax compression for bitonal images.
useJpeg2000
A value indicating whether the compressor must use JPEG2000 lossless compression instead of Flate(ZIP) for color and grayscale images.
subsetFonts
A value indicating whether the compressor must subset fonts.

Return Value

A new instance of PdfDocumentCompressorCommand class.
Example

Here is an example that shows how to detect "read color depth" of PDF image resources and compress the PDF document with intent to view in 150DPI:


''' <summary>
''' Detects "read color depth" of PDF image resources and compress PDF document with intent to view in 150DPI.
''' </summary>
''' <param name="inPdfFilename">The input PDF filename.</param>
''' <param name="outPdfFilename">The output PDF filename.</param>
Public Shared Sub CompressToViewIn150DPI(inPdfFilename As String, outPdfFilename As String)
    ' create compressor that will compress PDF document using lossy compression algorithms
    Dim compressor As Vintasoft.Imaging.Pdf.Processing.PdfDocumentCompressorCommand = Vintasoft.Imaging.Pdf.Processing.PdfDocumentCompressorCommand.CreateLossyCompressor(150, False, False, False)

    ' specify that compressor must use JPEG compression for color images
    compressor.ColorImagesCompression = Vintasoft.Imaging.Pdf.PdfCompression.Jpeg
    ' specify that compressor must set JPEG quality to 70
    compressor.ColorImagesCompressionSettings.JpegQuality = 70

    ' specify that compressor must detect if image is bitonal image and use optimal compression for bitonal image
    compressor.DetectBitonalImageResources = True
    ' specify that compressor must detect if image is black-white image and use optimal compression for black-white image
    compressor.DetectBlackWhiteImageResources = True
    ' specify that compressor must detect if image is grayscale image and use optimal compression for grayscale image
    compressor.DetectGrayscaleImageResources = True

    ' compress PDF document
    compressor.Compress(inPdfFilename, outPdfFilename)
End Sub


/// <summary>
/// Detects "read color depth" of PDF image resources and compress PDF document with intent to view in 150DPI.
/// </summary>
/// <param name="inPdfFilename">The input PDF filename.</param>
/// <param name="outPdfFilename">The output PDF filename.</param>
public static void CompressToViewIn150DPI(string inPdfFilename, string outPdfFilename)
{
    // create compressor that will compress PDF document using lossy compression algorithms
    Vintasoft.Imaging.Pdf.Processing.PdfDocumentCompressorCommand compressor =
       Vintasoft.Imaging.Pdf.Processing.PdfDocumentCompressorCommand.CreateLossyCompressor(150, false, false, false);

    // specify that compressor must use JPEG compression for color images
    compressor.ColorImagesCompression = Vintasoft.Imaging.Pdf.PdfCompression.Jpeg;
    // specify that compressor must set JPEG quality to 70
    compressor.ColorImagesCompressionSettings.JpegQuality = 70;

    // specify that compressor must detect if image is bitonal image and use optimal compression for bitonal image
    compressor.DetectBitonalImageResources = true;
    // specify that compressor must detect if image is black-white image and use optimal compression for black-white image
    compressor.DetectBlackWhiteImageResources = true;
    // specify that compressor must detect if image is grayscale image and use optimal compression for grayscale image
    compressor.DetectGrayscaleImageResources = true;

    // compress PDF document
    compressor.Compress(inPdfFilename, outPdfFilename);
}

Requirements

Target Platforms: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

See Also