Merge several PDF files into a single PDF file

Namespace:  SautinSoft
Assembly:  PdfMetamorphosis (in PdfMetamorphosis.dll) Version: 6.7.12.19

Syntax

      
 C#  Visual Basic 
public int MergePDFFileArrayToPDFFile(
	string[] Files,
	string DestFile
)
Public Function MergePDFFileArrayToPDFFile ( _
	Files As String(), _
	DestFile As String _
) As Integer

Parameters

Files
array< String >[]()[]
Array of paths to PDF documents
DestFile
String
Path to resulting PDF, it will be created by the component or overwritten if the PDF document already exists

Return Value

0 - merged successfully
1 - error, can't merge PDF documents
2 - error, can't create output file, probably it used by another application
3 - merging failed
4 - merged successfully, but some files were not merged

Remarks

Examples

CopyHow to split and merge PDF documents using C#
using System;
using System.IO;
using System.Collections;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
            string rtfPath = @"..\..\..\..\..\test.rtf";
            string pdfPath = @"..\..\..\..\..\test.pdf";

            // Let's create a PDF file from RTF file
            p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape;
            //Specify page numbers: {1 of N}, font: Verdana, 18
            p.PageSettings.Numbering.Text = "{page} of {numpages}";
            p.PageSettings.Numbering.FontFace = "Verdana";
            p.PageSettings.Numbering.FontSize = 18;

            p.RtfToPdfConvertFile(rtfPath, pdfPath);

            #region split PDF file
            //Split PDF by pages: 1st, 2nd and 3rd
            p.SplitPDFFileToPDFFolder(pdfPath, Path.GetDirectoryName(pdfPath));
            #endregion

            #region merge PDF files
            //Merge only 1st and 3rd pages
            string[] pdfFiles = { @"..\..\..\..\..\test-00001.pdf", @"..\..\..\..\..\test-00003.pdf" };
            p.MergePDFFileArrayToPDFFile(pdfFiles, @"..\..\..\..\..\test_Split_and_Merge_1and3page.pdf");
            #endregion

            //Show merged PDF (it doesn't have 2nd page)
            System.Diagnostics.Process.Start(@"..\..\..\..\..\test_Split_and_Merge_1and3page.pdf");
        }
    }
}
CopyHow to split and merge PDF documents using VB.Net
Imports System
Imports System.IO
Imports System.Text

Module sample

    Sub Main()
        Dim p As New SautinSoft.PdfMetamorphosis()
        'After purchasing the license, please insert your serial number here to activate the component
        'p.Serial = "XXXXXXXXXXX";


        'specify some options
        p.PageSettings.Size.A4()
        p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Auto
        p.PageSettings.Numbering.Text = "Page {page} of {numpages}"

        If p IsNot Nothing Then
            Dim inputFile As String = "..\..\..\..\..\test.htm"
            Dim outputFile As String = "..\..\..\..\..\test.pdf"

            Dim result As Integer = p.HtmlToPdfConvertFile(inputFile, outputFile)

            If result = 0 Then
                System.Console.WriteLine("Converted successfully!")
                System.Diagnostics.Process.Start(outputFile)
            Else
                System.Console.WriteLine("Converting Error!")
            End If
        End If
    End Sub
End Module

See Also