VintaSoft Imaging .NET SDK 12.4: Documentation for .NET developer
Vintasoft.Imaging.Pdf Namespace / PdfDocument Class / Pack Methods / Pack(String) Method
Syntax Remarks Example Requirements SeeAlso
In This Topic
    Pack(String) Method (PdfDocument)
    In This Topic
    Packs and saves PDF document to specified file and switches to the specified file.
    Syntax
    'Declaration
    
    Public Overloads Sub Pack( _
    ByVal filename
    File name to pack PDF document.
    As System.String _
    )
    public void Pack(
    System.String filename
    )
    public: void Pack(
    System.String filename
    )
    public:
    void Pack(
    System.String filename
    )

    Parameters

    filename
    File name to pack PDF document.
    Remarks

    This methods copies content of this PDF document to specified file, removes unused objects from the specified file and switches to specified file.
    Source PDF document is not affected. All further changes will affect the specified file only.

    Example

    Here is an example that shows how to load an existing PDF document from file, delete a page from document, pack and save the changed document to a new file:

    
    ''' <summary>
    ''' Loads PDF document from a file,
    ''' removes the first page of PDF docuemnt and
    ''' packs PDF document to the new file.
    ''' </summary>
    ''' <param name="sourcePdfFilename">The filename of source PDF document.</param>
    ''' <param name="destPdfFilename">The filename of destination PDF document.</param>
    Public Shared Sub RemovePageFromPdfDocumentAndPackPdfDocument(sourcePdfFilename As String, destPdfFilename As String)
        ' open PDF document
        Using document As New Vintasoft.Imaging.Pdf.PdfDocument(sourcePdfFilename)
            ' remove the first page from PDF document
            document.Pages.RemoveAt(0)
    
            ' pack PDF document to the new file
            document.Pack(destPdfFilename)
        End Using
    End Sub
    
    
    
    /// <summary>
    /// Loads PDF document from a file,
    /// removes the first page of PDF docuemnt and
    /// packs PDF document to the new file.
    /// </summary>
    /// <param name="sourcePdfFilename">The filename of source PDF document.</param>
    /// <param name="destPdfFilename">The filename of destination PDF document.</param>
    public static void RemovePageFromPdfDocumentAndPackPdfDocument(
        string sourcePdfFilename,
        string destPdfFilename)
    {
        // open PDF document
        using (Vintasoft.Imaging.Pdf.PdfDocument document = 
            new Vintasoft.Imaging.Pdf.PdfDocument(sourcePdfFilename))
        {
            // remove the first page from PDF document
            document.Pages.RemoveAt(0);
    
            // pack PDF document to the new file
            document.Pack(destPdfFilename);
        }
    }
    
    

    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