1. Home
  2. /
  3. GroupDocs.Conversion.LowCode
  4. /
  5. Developer Guide
  6. /
  7. Using XLSX to PDF Converter

Using XLSX to PDF Converter

This topic shows how to use the XlsxToPdfConverter with examples that demonstrate common use cases for converting XLSX files to PDF.

Prerequisites

Refer to the Developer Guide to learn how to set up your environment and run code examples in this section.

You can also check two related topics on Loading Source Documents and Saving Converted Documents to learn how to specify input and output documents.

Basic Example

The following example shows the most common use case for converting XLSX document to PDF. The source XLSX file is loaded from a current folder. The converted file is saved to the same folder.

using System;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply the license
License.Set(publicKey, privateKey);

// Create a converter for the XLSX file
var converter = new XlsxToPdfConverter("cost-analysis.xlsx");

// Convert XLSX to PDF
converter.Convert("cost-analysis.pdf");
Imports System
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply the license
        License.Set(publicKey, privateKey)

        ' Create a converter from file path
        Dim converter As New XlsxToPdfConverter("cost-analysis.xlsx")

        ' Convert XLSX to PDF
        converter.Convert("cost-analysis.pdf")
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply the license
    License.Set(publicKey, privateKey)

    // Create a converter from file path
    let converter = new XlsxToPdfConverter("cost-analysis.xlsx")

    // Convert XLSX to PDF
    converter.Convert("cost-analysis.pdf")
    0

Sample input file: Download cost-analysis.xlsx

Spreadsheet Load Options

This section covers only the main scenarios. You can also refer to the API references for the SpreadsheetLoadOptions for a complete list of options that you can specify.

Convert Protected XLSX to PDF

The following example shows how to convert protected XLSX file and save it to unprotected PDF file.

In case you do not specify password for protected document PasswordRequiredException is going to be thrown.

using System;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Provide password through load options
var converter = new XlsxToPdfConverter("protected.xlsx", options =>
{
    options.Password = "12345";
});

// Convert XLSX to PDF
converter.Convert("not-protected.pdf");
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Provide password through load options
        Dim converter As New XlsxToPdfConverter("protected.xlsx", Sub(options)
            options.Password = "12345"
        End Sub)

        ' Convert XLSX to PDF
        converter.Convert("not-protected.pdf")
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")
    
    // Apply license
    License.Set(publicKey, privateKey)

    // Provide password through load options
    let converter = new XlsxToPdfConverter("protected.xlsx", fun options ->
        options.Password <- "12345"
    )
    
    // Convert XLSX to PDF
    converter.Convert("not-protected.pdf")
    0

Sample input: Download protected.xlsx (Password: 12345)

Convert Specific Sheets from XLSX to PDF

The following example shows how to convert only specific sheets from an XLSX file to PDF using the SheetIndexes property.

using System;
using System.Collections.Generic;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Convert only specific sheets (first and third sheets)
var converter = new XlsxToPdfConverter("invoice-tracker.xlsx", options =>
{
    options.SheetIndexes = new List<int> { 0, 2 }; // 0-based indexing
});

// Convert XLSX to PDF
converter.Convert("specific-sheets.pdf");
Imports System
Imports System.Collections.Generic
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Convert only specific sheets (first and third sheets)
        Dim converter As New XlsxToPdfConverter("invoice-tracker.xlsx", Sub(options)
            options.SheetIndexes = New List(Of Integer) From {0, 2} ' 0-based indexing
        End Sub)

        ' Convert XLSX to PDF
        converter.Convert("specific-sheets.pdf")
    End Sub
End Module
open System
open System.Collections.Generic
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")
    
    // Apply license
    License.Set(publicKey, privateKey)

    // Convert only specific sheets (first and third sheets)
    let converter = new XlsxToPdfConverter("invoice-tracker.xlsx", fun options ->
        options.SheetIndexes <- List<int>([0; 2]) // 0-based indexing
    )
    
    // Convert XLSX to PDF
    converter.Convert("specific-sheets.pdf")
    0

Convert XLSX with Hidden Sheets to PDF

By default hidden sheets are not added to the output PDF.

The following example shows how to include hidden sheets when converting XLSX to PDF using the ShowHiddenSheets property.

using System;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Include hidden sheets in conversion
var converter = new XlsxToPdfConverter("hidden-worksheets.xlsx", options =>
{
    options.ShowHiddenSheets = true;
});

// Convert XLSX to PDF
converter.Convert("with-hidden-sheets.pdf");
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Include hidden sheets in conversion
        Dim converter As New XlsxToPdfConverter("hidden-worksheets.xlsx", Sub(options)
            options.ShowHiddenSheets = True
        End Sub)

        ' Convert XLSX to PDF
        converter.Convert("with-hidden-sheets.pdf")
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")
    
    // Apply license
    License.Set(publicKey, privateKey)

    // Include hidden sheets in conversion
    let converter = new XlsxToPdfConverter("hidden-worksheets.xlsx", fun options ->
        options.ShowHiddenSheets <- true
    )
    
    // Convert XLSX to PDF
    converter.Convert("with-hidden-sheets.pdf")
    0

Sample input: Download hidden-worksheets.xlsx (Contains hidden sheets)

PDF Convert Options

The examples in this section shows how you can adjust the output using PdfConvertOptions.

Convert XLSX to PDF with Specific PDF Format

You can specify the PDF format for the output file using the PdfFormat property in PdfOptions class. This allows you to create PDF files that conform to specific standards like PDF/A for archiving or PDF/X for print production.

The following example shows how to convert an XLSX file to PDF/A-1b format, which is commonly used for long-term archiving:

using System;
using GroupDocs.Conversion.LowCode;
using GroupDocs.Conversion.Options.Convert;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Create the converter
var converter = new XlsxToPdfConverter("cost-analysis.xlsx");

// Convert to PDF/A-1b format for archiving
converter.Convert("archived-cost-analysis.pdf", convertOptions =>
{
    convertOptions.PdfOptions.PdfFormat = PdfFormats.PdfA_1B;
});
Imports GroupDocs.Conversion.LowCode
Imports GroupDocs.Conversion.Options.Convert

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey As String = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey As String = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Create the converter
        Dim converter As New XlsxToPdfConverter("cost-analysis.xlsx")

        ' Convert to PDF/A-1b format for archiving
        converter.Convert("archived-cost-analysis.pdf", Sub(convertOptions)
            convertOptions.PdfOptions.PdfFormat = PdfFormats.PdfA_1B
        End Sub)
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode
open GroupDocs.Conversion.Options.Convert

[<EntryPoint>]
let main argv =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply license
    License.Set(publicKey, privateKey)

    // Create the converter
    let converter = new XlsxToPdfConverter("cost-analysis.xlsx")

    // Convert to PDF/A-1b format for archiving
    converter.Convert("archived-cost-analysis.pdf", fun convertOptions ->
        convertOptions.PdfOptions.PdfFormat <- PdfFormats.PdfA_1B
    )

    0 // return exit code

Expected output: Download archived-cost-analysis.pdf (PDF/A-1b format)

Convert XLSX to Password-Protected PDF

You can protect the output PDF with a password by setting the Password property in PdfConvertOptions class.

using System;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Create the converter
var converter = new XlsxToPdfConverter("cost-analysis.xlsx");

// Convert to password-protected PDF
converter.Convert("protected.pdf", convertOptions =>
{
    convertOptions.Password = "12345";
});
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Create the converter
        Dim converter As New XlsxToPdfConverter("cost-analysis.xlsx")

        ' Convert to password-protected PDF
        converter.Convert("protected.pdf", Sub(convertOptions)
            convertOptions.Password = "12345"
        End Sub)
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply license
    License.Set(publicKey, privateKey)

    // Create the converter
    let converter = new XlsxToPdfConverter("cost-analysis.xlsx")

    // Convert to password-protected PDF
    converter.Convert("protected.pdf", fun convertOptions ->
        convertOptions.Password <- "12345"
    )

    0

Expected output: Download protected.pdf (Password: 12345)