Click or drag to resize

ExcelToPdfMergePDFFileArrayToPDFFile Method

Merges different PDF files into single PDF file

Namespace: SautinSoft
Assembly: SautinSoft.ExcelToPdf (in SautinSoft.ExcelToPdf.dll) Version: 5.6.11.14
Syntax
public void MergePDFFileArrayToPDFFile(
	string[] Files,
	string DestFile
)

Parameters

Files  String
Array with paths to PDF documents
DestFile  String
Path to a new single PDF, it will be created by the component or overwritten in case of PDF is already exist

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
Example
Merge two PDF files using C#
using System;
using System.IO;
using SautinSoft;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            // Merge two PDF files.
            // 1. Let's get a PDF from .xlsx.
            // 2. Let's merge this PDF with itself.
            ExcelToPdf x = new ExcelToPdf();
            x.PageStyle.PageSize.Letter();
            x.PageStyle.PageMarginTop.mm(5);

            // Set PDF as output format.
            x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf;

            // Let's convert only 3rd page.
            x.Sheets.Custom(new int[]{3});

            string excelFile = Path.GetFullPath(@"..\..\test.xlsx");
            FileInfo pdfFile = new FileInfo(Path.ChangeExtension(excelFile, ".pdf"));
            string singlePdf = Path.Combine(pdfFile.Directory.FullName, "Single.pdf");

            try
            {
                // 1. Convert Excel to PDF.
                x.ConvertFile(excelFile, pdfFile.FullName);

                // 2. Merge the PDF file with itself.
                x.MergePDFFileArrayToPDFFile(new string[] { pdfFile.FullName, pdfFile.FullName },
                    singlePdf);

                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(singlePdf) { UseShellExecute = true });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }
    }
}
Merge two PDF files using VB.Net
Imports System
Imports System.IO
Imports SautinSoft

Module Sample

    Sub Main()
        ' Merge two PDF files.
        ' 1. Let's get a PDF from .xlsx.
        ' 2. Let's merge this PDF with itself.
        Dim x As New ExcelToPdf()
        x.PageStyle.PageSize.Letter()
        x.PageStyle.PageMarginTop.mm(5)

        ' Set PDF as output format.
        x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf

        ' Let's convert only 3rd page.
        x.Sheets.Custom(New Integer() {3})

        Dim excelFile As String = Path.GetFullPath("..\test.xlsx")
        Dim pdfFile As New FileInfo(Path.ChangeExtension(excelFile, ".pdf"))
        Dim singlePdf As String = Path.Combine(pdfFile.Directory.FullName, "Single.pdf")

        Try
            ' 1. Convert Excel to PDF.
            x.ConvertFile(excelFile, pdfFile.FullName)

            ' 2. Merge the PDF file with itself.
            x.MergePDFFileArrayToPDFFile(New String() {pdfFile.FullName, pdfFile.FullName}, singlePdf)

            System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(singlePdf) With {.UseShellExecute = True})
        Catch ex As Exception
            Console.WriteLine(ex.Message)
            Console.ReadLine()
        End Try
    End Sub
End Module
See Also