VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
Vintasoft.Imaging.Pdf.Tree Namespace / PdfImageResource Class / Compress Methods / Compress(PdfCompression,PdfCompressionSettings) Method
Syntax Example Requirements SeeAlso
In This Topic
Compress(PdfCompression,PdfCompressionSettings) Method (PdfImageResource)
In This Topic
Compress the image-resource.
Syntax

Parameters

compression
Compression that should be applied to the image-resource.
compressionSettings
Compression settings.

Return Value

True if compression is applied to the image-resource; otherwise, false.
Example

Here is an example that shows how to change the compression algorithm of all black-white PDF image resources:


''' <summary>
''' Changes compression of all black-white image-resources of PDF document.
''' </summary>
''' <param name="pdfFilename">The filename of PDF document.</param>
Public Shared Sub ChangeCompressionBlackWhiteImages(pdfFilename As String)
    ' open PDF document
    Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
        ' get collection of image-resources
        Dim images As Vintasoft.Imaging.Pdf.Tree.PdfImageResource() = document.GetImages()

        ' create compression settings
        Dim compressionSettings As New Vintasoft.Imaging.Pdf.PdfCompressionSettings()

        ' for each image-resource
        For Each image As Vintasoft.Imaging.Pdf.Tree.PdfImageResource In images
            '  if image is black-white
            If image.PixelFormat = Vintasoft.Imaging.PixelFormat.BlackWhite Then
                ' change compression of image-resource
                image.Compress(Vintasoft.Imaging.Pdf.PdfCompression.CcittFax, compressionSettings)
            End If
        Next

        ' save changes to a file
        document.SaveChanges()
    End Using
End Sub 


/// <summary>
/// Changes compression of all black-white image-resources of PDF document.
/// </summary>
/// <param name="pdfFilename">The filename of PDF document.</param>
public static void ChangeCompressionBlackWhiteImages(string pdfFilename)
{
    // open PDF document
    using (Vintasoft.Imaging.Pdf.PdfDocument document = 
        new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
    {
        // get collection of image-resources
        Vintasoft.Imaging.Pdf.Tree.PdfImageResource[] images = document.GetImages();

        // create compression settings
        Vintasoft.Imaging.Pdf.PdfCompressionSettings compressionSettings = 
            new Vintasoft.Imaging.Pdf.PdfCompressionSettings();
        
        // for each image-resource
        foreach (Vintasoft.Imaging.Pdf.Tree.PdfImageResource image in images)
        {
            //  if image is black-white
            if (image.PixelFormat == Vintasoft.Imaging.PixelFormat.BlackWhite)
                // change compression of image-resource
                image.Compress(Vintasoft.Imaging.Pdf.PdfCompression.CcittFax, compressionSettings);
        }

        // save changes to a file
        document.SaveChanges();
    }
} 

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