VintaSoft Imaging .NET SDK v8.7
In This Topic
    PDF: How to merge PDF documents?
    In This Topic

    Here is an example that demonstrates how to merge several PDF documents into one:

    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging.Pdf
    
    Public Shared Sub CombinePDFDocuments(sourceDocuments As String(), resultDocument As String)
        ' create new PDF document version 1.6 with compressed cross-reference table
        Dim document As New Vintasoft.Imaging.Pdf.PdfDocument(resultDocument, System.IO.FileMode.Create, New Vintasoft.Imaging.Pdf.PdfFormat("1.6", True, True))
    
        ' for each source document
        For i As Integer = 0 To sourceDocuments.Length - 1
            ' open the source document in read-only mode
            Dim sourceDocument As New Vintasoft.Imaging.Pdf.PdfDocument(sourceDocuments(i), True)
            ' add pages from source document to result document
            document.Pages.AddRange(sourceDocument.Pages.ToArray())
            ' close the source document
            sourceDocument.Dispose()
            ' save changes to a file
            document.SaveChanges()
        Next
    
        ' close result document
        document.Dispose()
    End Sub
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging.Pdf
    
    public static void CombinePDFDocuments(string[] sourceDocuments, string resultDocument)
    {
        // create new PDF document version 1.6 with compressed cross-reference table
        Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument(
            resultDocument,
            System.IO.FileMode.Create,
            new Vintasoft.Imaging.Pdf.PdfFormat("1.6", true, true));
    
        // for each source document
        for (int i = 0; i < sourceDocuments.Length; i++)
        {
            // open the source document in read-only mode
            Vintasoft.Imaging.Pdf.PdfDocument sourceDocument = 
                new Vintasoft.Imaging.Pdf.PdfDocument(sourceDocuments[i], true);
            // add pages from source document to result document
            document.Pages.AddRange(sourceDocument.Pages.ToArray());
            // close the source document
            sourceDocument.Dispose();
            // save changes to a file
            document.SaveChanges();
        }
    
        // close result document
        document.Dispose();
    }