VintaSoft Imaging .NET SDK 12.4: Documentation for .NET developer
Vintasoft.Imaging.Pdf Namespace / PdfDocument Class / Optimize Methods / Optimize(PdfFormat,PdfOptimizeSettings) Method
Syntax Remarks Example Requirements SeeAlso
In This Topic
    Optimize(PdfFormat,PdfOptimizeSettings) Method (PdfDocument)
    In This Topic
    Optimizes the PDF document and converts PDF document to the specified format.
    Syntax
    'Declaration
    
    Public Overloads Sub Optimize( _
    ByVal format
    Format to optimize.
    As PdfFormat, _
    ByVal optimizeSettings
    Optimize settings.
    As PdfOptimizeSettings _
    )

    Parameters

    format
    Format to optimize.
    optimizeSettings
    Optimize settings.
    Remarks

    This methods repacks images and data of PDF document using specified optimize settings.

    Example

    Here is an example that shows how to pack PDF file (optimize=false) or how to pack PDF file and convert all color images to JPEG (optimize=true):

    
    Public Shared Sub PackPdf(pdfFileName As String, optimize As Boolean)
        ' open PDF document to Read/Write
        Dim pdfDocument As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFileName)
        ' create PdfFormat - 1.6 format, with compressed cross-reference table
        Dim format As New Vintasoft.Imaging.Pdf.PdfFormat("1.6", True, True)
        If optimize Then
            ' set JPEG Quality to 80
            Vintasoft.Imaging.Pdf.PdfCompressionSettings.DefaultSettings.JpegQuality = 80
            ' create optimize settings
            'compression for Color images - JPEG
            'compression for B/W images - not changed
            Dim optimizeSettings As New Vintasoft.Imaging.Pdf.PdfOptimizeSettings(Vintasoft.Imaging.Pdf.PdfCompression.Jpeg, Vintasoft.Imaging.Pdf.PdfCompression.Undefined, Vintasoft.Imaging.Pdf.PdfCompression.Undefined)
            'compression for Data - not changed
            ' optimize and Pack document
            pdfDocument.Optimize(format, optimizeSettings)
        Else
            ' pack document
            pdfDocument.Pack(format)
        End If
        ' free resources
        pdfDocument.Dispose()
    End Sub
    
    
    
    public static void PackPdf(string pdfFileName, bool optimize)
    {
        // open PDF document to Read/Write
        Vintasoft.Imaging.Pdf.PdfDocument pdfDocument = 
            new Vintasoft.Imaging.Pdf.PdfDocument(pdfFileName);
        // create PdfFormat - 1.6 format, with compressed cross-reference table
        Vintasoft.Imaging.Pdf.PdfFormat format = 
            new Vintasoft.Imaging.Pdf.PdfFormat("1.6", true, true);
        if (optimize)
        {
            // set JPEG Quality to 80
            Vintasoft.Imaging.Pdf.PdfCompressionSettings.DefaultSettings.JpegQuality = 80;
            // create optimize settings
            Vintasoft.Imaging.Pdf.PdfOptimizeSettings optimizeSettings = 
                new Vintasoft.Imaging.Pdf.PdfOptimizeSettings(
                    Vintasoft.Imaging.Pdf.PdfCompression.Jpeg,       //compression for Color images - JPEG
                    Vintasoft.Imaging.Pdf.PdfCompression.Undefined,  //compression for B/W images - not changed
                    Vintasoft.Imaging.Pdf.PdfCompression.Undefined); //compression for Data - not changed
            // optimize and Pack document
            pdfDocument.Optimize(format, optimizeSettings);
        }
        else
        {
            // pack document
            pdfDocument.Pack(format);
        }
        // free resources
        pdfDocument.Dispose();
    }
    
    

    Requirements

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

    See Also