VintaSoft Imaging .NET SDK 14.0: Documentation for .NET developer
Vintasoft.Imaging.Pdf.Processing Namespace / PdfDocumentCompressorCommand Class / PackDocument Property
Syntax Example Requirements SeeAlso
In This Topic
    PackDocument Property (PdfDocumentCompressorCommand)
    In This Topic
    Gets or sets a value indicating whether the command must pack PDF document after compress.
    Syntax
    'Declaration
    
    <DescriptionAttribute("A value indicating whether the command must pack PDF document after compress.")>
    <CategoryAttribute("Pack")>
    <DefaultValueAttribute(False)>
    Public Property PackDocument As Boolean
    
    
    [Description("A value indicating whether the command must pack PDF document after compress.")]
    [Category("Pack")]
    [DefaultValue(False)]
    public bool PackDocument { get; set; }
    
    
    [Description("A value indicating whether the command must pack PDF document after compress.")]
    [Category("Pack")]
    [DefaultValue(False)]
    public: __property bool get_PackDocument();
    public: __property void set_PackDocument(
    bool value
    );
    [Description("A value indicating whether the command must pack PDF document after compress.")]
    [Category("Pack")]
    [DefaultValue(False)]
    public:
    property bool PackDocument { bool get(); void set(bool value); }

    Property Value

    True - command must pack PDF document after compress; false - command must NOT pack PDF document after compress.
    Default value is false.
    Example

    Here is an example that shows how to compress PDF-resources using Flate-compression and pack the PDF document:

    
    ''' <summary>
    ''' Packs the PDF document.
    ''' </summary>
    ''' <param name="inPdfFilename">The input PDF filename.</param>
    ''' <param name="outPdfFilename">The output PDF filename.</param>
    Public Shared Sub PackDocument(inPdfFilename As String, outPdfFilename As String)
        ' create compressor with empty compression settings
        Dim compressor As Vintasoft.Imaging.Pdf.Processing.PdfDocumentCompressorCommand = Vintasoft.Imaging.Pdf.Processing.PdfDocumentCompressorCommand.CreateEmptyCompressor()
    
        ' specify that compressor must use maximum Flate compression level (best compression)
        compressor.FlateCompressionLevel = 9
        ' specify that compressor must recompress all resource that uses None, LZW, Flate compression using Flate compression
        compressor.RecompressFlateCompression = True
        compressor.UseFlateInsteadLzwCompression = True
        compressor.UseFlateInsteadNoneCompression = True
    
        ' specify that compressor must remove incremental update info and unused objects
        compressor.PackDocument = True
    
        ' if version of PDF document is lower than 1.7
        If GetPdfDocumentVersion(inPdfFilename) < 17 Then
            ' set output format to PDF 1.7
            compressor.DocumentPackFormat = Vintasoft.Imaging.Pdf.PdfFormat.Pdf_17
        End If
    
        ' compress PDF document
        compressor.Compress(inPdfFilename, outPdfFilename)
    End Sub
    
    ''' <summary>
    ''' Returns the PDF document version.
    ''' </summary>
    ''' <param name="pdfFilename">The PDF filename.</param>
    ''' <returns>The version number in dual-digit format (10,11,12,13,14,15,16,17,20,...).</returns>
    Private Shared Function GetPdfDocumentVersion(pdfFilename As String) As Integer
        Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
            Return document.Format.VersionNumber
        End Using
    End Function
    
    
    
    /// <summary>
    /// Packs the PDF document.
    /// </summary>
    /// <param name="inPdfFilename">The input PDF filename.</param>
    /// <param name="outPdfFilename">The output PDF filename.</param>
    public static void PackDocument(string inPdfFilename, string outPdfFilename)
    {
        // create compressor with empty compression settings
        Vintasoft.Imaging.Pdf.Processing.PdfDocumentCompressorCommand compressor =
            Vintasoft.Imaging.Pdf.Processing.PdfDocumentCompressorCommand.CreateEmptyCompressor();
    
        // specify that compressor must use maximum Flate compression level (best compression)
        compressor.FlateCompressionLevel = 9;
        // specify that compressor must recompress all resource that uses None, LZW, Flate compression using Flate compression
        compressor.RecompressFlateCompression = true;
        compressor.UseFlateInsteadLzwCompression = true;
        compressor.UseFlateInsteadNoneCompression = true;
    
        // specify that compressor must remove incremental update info and unused objects
        compressor.PackDocument = true;
    
        // if version of PDF document is lower than 1.7
        if (GetPdfDocumentVersion(inPdfFilename) < 17)
        {
            // set output format to PDF 1.7
            compressor.DocumentPackFormat = Vintasoft.Imaging.Pdf.PdfFormat.Pdf_17;
        }
    
        // compress PDF document
        compressor.Compress(inPdfFilename, outPdfFilename);
    }
    
    /// <summary>
    /// Returns the PDF document version.
    /// </summary>
    /// <param name="pdfFilename">The PDF filename.</param>
    /// <returns>The version number in dual-digit format (10,11,12,13,14,15,16,17,20,...).</returns>
    private static int GetPdfDocumentVersion(string pdfFilename)
    {
        using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
            return document.Format.VersionNumber;
    }
    
    

    Requirements

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

    See Also