Convert Excel file to PDF in C# and VB.NET

With GemBox.Spreadsheet you can easily convert Excel files from one format to another, using just C# or VB.NET code. You can load or read any supported input file format and save or write it as any supported output file format.

You can find the full list of formats on the Supported File Formats help page.

The following examples show some commonly required file format conversions.

Convert Excel files to PDF

For both reading and writing, you can either provide the file's path or a stream by using one of the ExcelFile.Load or ExcelFile.Save methods.

The following example shows how you can convert a Excel file to a PDF using the default LoadOptions and SaveOptions.

PDF converted from Excel file with GemBox.Spreadsheet
Screenshot of PDF converted from Excel file with GemBox.Spreadsheet
Upload your file (Drag file here)
using GemBox.Spreadsheet;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        var workbook = ExcelFile.Load("%InputFileName%");

        // In order to achieve the conversion of a loaded Excel file to PDF,
        // or to some other Excel format,
        // we just need to save an ExcelFile object to desired output file format.
        workbook.Save("Convert.%OutputFileType%");
    }
}
Imports GemBox.Spreadsheet

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")

        Dim workbook = ExcelFile.Load("%InputFileName%")

        ' In order to achieve the conversion of a loaded Excel file to PDF,
        ' or to some other Excel format,
        ' we just need to save an ExcelFile object to desired output file format.
        workbook.Save("Convert.%OutputFileType%")
    End Sub
End Module

Convert Excel files to PDF/A

Also, GemBox.Spreadsheet supports saving the Excel file to PDF/A, an ISO-standardized version of the Portable Document Format (PDF) specialized for use in the archiving and long-term preservation of electronic documents.

The following example shows how you can convert a Excel file to PDF/A using PdfConformanceLevel to specify conformance level and version.

PDF/A converted from Excel file with GemBox.Spreadsheet
Screenshot of PDF/A converted from Excel file with GemBox.Spreadsheet
Upload your file (Drag file here)
using GemBox.Spreadsheet;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        PdfConformanceLevel conformanceLevel = %PdfConformanceLevel%;

        // Load Excel file.
        var workbook = ExcelFile.Load("%InputFileName%");

        // Create PDF save options.
        var options = new PdfSaveOptions()
        {
            ConformanceLevel = conformanceLevel
        };

        // Save to PDF file.
        workbook.Save("Output.pdf", options);
    }
}
Imports GemBox.Spreadsheet

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")

        Dim conformanceLevel As PdfConformanceLevel = %PdfConformanceLevel%

        ' Load Excel file.
        Dim workbook = ExcelFile.Load("%InputFileName%")

        ' Create PDF save options.
        Dim options As New PdfSaveOptions() With
        {
            .conformanceLevel = conformanceLevel
        }

        ' Save to PDF file.
        workbook.Save("Output.pdf", options)

    End Sub
End Module

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Spreadsheet yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.