CreateLossyCompressor(Double,Boolean,Boolean,Boolean) Method (PdfDocumentCompressorCommand)
Creates the lossy PDF compressor.
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);
}
Target Platforms: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5