Split and merge PDF using C# or VB.NET

Excel to PDF .Net

.Net assembly to convert Excel (.xls and .xlsx) workbooks to PDF, RTF, DOCX, Word in .Net and C#.
Split and merge PDF using C# or VB.NET

Excel to PDF .Net

Split and merge PDF using C# or VB.NET
Split and merge PDF using C# or VB.NET

Introduction

Now let's get to know another benefit of the library. Excel to PDF .Net offers great abilities to split and merge PDF documents. To show how Excel to PDF .Net really lessens the burden of coding, assume that you want convert .xlsx files to PDF and then merge them a one single PDF using C#:


Download

To see this functionality firsthand, download the freshest «Excel to PDF .Net» with code examples, 34.7 Mb.

Limitations

Excel to PDF .Net The limitations of the free version are: The trial notice "Created by unlicensed version of Excel to PDF .Net" and the random addition of the word "TRIAL".


Some examples to convert Excel to PDF and next split and merge PDF using C#

1. Let's convert only 3rd page of Excel file to PDF and then merge this PDF file with itself using C#.

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(@"d:\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(singlePdf);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        Console.ReadLine();
    }

}

2. Let's convert Excel file to PDF and next split the PDF document by pages using C#:

static void Main(string[] args)
{
    // Split PDF by pages.
    // 1. Let's get a PDF with 3 pages from .xlsx.
    // 2. Let's split it by 3 PDF files and show them.
    ExcelToPdf x = new ExcelToPdf();
    x.PageStyle.PageSize.Letter();
    x.PageStyle.PageMarginTop.mm(5);

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

    string excelFile = Path.GetFullPath(@"d:\test.xlsx");
    FileInfo pdfFile = new FileInfo(Path.ChangeExtension(excelFile, ".pdf"));

    try
    {
        // 1. Let's get a PDF with 3 pages from .xlsx.
        x.ConvertFile(excelFile, pdfFile.FullName);

        // 2. Let's split it by 3 PDF files and show them.
        // Create a directory for storing separate PDFs.
        DirectoryInfo pdfDir = pdfFile.Directory.CreateSubdirectory("My Pages");
        x.SplitPDFFileToPDFFolder(pdfFile.FullName, pdfDir.FullName);

        // Show result
        FileInfo[] pageFiles = pdfDir.GetFiles("*.pdf");
        Console.WriteLine("Resulting PDF files:\n");
        foreach (FileInfo pageFile in pageFiles)
        {
            Console.WriteLine(pageFile.Name);
        }

    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }

    Console.ReadLine();
}

Requirements and Technical Information

«Excel to PDF .Net» can be used on 32 and 64-bits platforms with .NET Framework 4.0, .NET Core 2.0 and higher. The component doesn't require Microsoft Excel or any other software. It's absolutely standalone and independent library.

Our product is compatible with all .NET languages and supports all Operating Systems where .NET Framework and .NET Core can be used. Note that «Excel to PDF .Net» is entirely written in managed C#.

.Net Framework 4.0 and higher and .Net Core 2.0 and higher

.NET Framework 4.5, 4.6.1 and higher.

.NET Core, .NET 5.0 and higher.


Multi-platform component, runs on:


Our component has proven itself on cloud platforms and services:

  • Microsoft Azure
  • Amazon Web Services (AWS)
  • Google Cloud Platform
  • SharePoint
  • Docker
  • Xamarin Forms
  • etc.