Table of Contents

Class XlsxToPdfConverter

Namespace
DocToolkit
Assembly
DocToolkit.dll

Renders an Excel (.xlsx) workbook to PDF. Pure managed — no browser, no LibreOffice, no Excel.

The same three members as DocxToPdfConverter and PptxToPdfConverter, deliberately: a consumer who has used one has used all three.

No page-setup parameter, for the same reason DocxToPdfConverter has none — the workbook already carries its own print setup, per worksheet, and the renderer honours it. Taking a PageSetup here would mean overriding something the caller's own document already states.

Fidelity is bounded, and features the renderer cannot represent are dropped rather than reported: this package has no warning channel, and adding one is a decision deferred until somebody needs it rather than made by accident here. See README's Known limitations.

Text is the exception: it is refused, not dropped. A cell holding characters the fonts this renderer can reach do not cover throws, naming the character - measured on Windows for Hebrew, Arabic, Persian and Cyrillic. Pass PdfFontOptions to Convert(byte[], PdfFontOptions?). Merged cells render; a sheet's right-to-left direction does not.

public static class XlsxToPdfConverter
Inheritance
XlsxToPdfConverter
Inherited Members

Methods

Convert(byte[])

Renders the .xlsx in xlsx and returns PDF bytes.

No network access, and safe in an air-gapped environment. The resource policy handed to the renderer refuses both remote resolution and local file access, set explicitly rather than inherited — see DocToolkit.PdfRenderPolicy.

public static byte[] Convert(byte[] xlsx)

Parameters

xlsx byte[]

The workbook to render.

Returns

byte[]

Examples

byte[] pdf = XlsxToPdfConverter.Convert(xlsx);

Exceptions

ArgumentNullException

xlsx is null.

ArgumentException

xlsx is empty.

DocumentConversionException

The workbook could not be rendered.

Convert(byte[], PdfFontOptions?)

Renders the .xlsx in xlsx, using fonts for characters the renderer cannot otherwise encode.

public static byte[] Convert(byte[] xlsx, PdfFontOptions? fonts)

Parameters

xlsx byte[]

The workbook to render.

fonts PdfFontOptions

Fonts to fall back to, or null for none.

Returns

byte[]

Remarks

Without fonts, whether non-Latin text renders depends on the host. Where the renderer cannot encode it, it is refused rather than rendered with gaps - measured 2026-11-02, Persian, Hebrew, Arabic and Cyrillic cells all fail on a Windows host with a DocumentConversionException naming the first character that could not be encoded. Supplying the font removes the machine from the answer, and also turns on Hebrew and Arabic shaping. See PdfFontOptions for what that does and does not cover.

Exceptions

ArgumentNullException

xlsx is null.

ArgumentException

xlsx is empty.

DocumentConversionException

The workbook could not be rendered.

ConvertAsync(Stream, Stream, PdfFontOptions?, CancellationToken)

Reads an .xlsx from source and writes the rendered PDF to destination, using fonts for characters the renderer cannot otherwise encode.

public static Task ConvertAsync(Stream source, Stream destination, PdfFontOptions? fonts, CancellationToken ct = default)

Parameters

source Stream

The stream the .xlsx package is read from.

destination Stream

The stream the PDF is written to.

fonts PdfFontOptions

Fonts to fall back to, or null for none.

ct CancellationToken

Cancels the read, the render and the write.

Returns

Task

Remarks

Exceptions

ArgumentNullException

Either stream is null.

ArgumentException

source is not readable or held no bytes, or destination is not writable.

OperationCanceledException

ct was cancelled.

DocumentConversionException

The workbook could not be rendered.

ConvertAsync(Stream, Stream, CancellationToken)

Reads an .xlsx from source and writes the rendered PDF to destination.

source is read to its end and destination is written; neither is disposed or closed, and destination is never sought or read back, so both may be sockets, files or HTTP message bodies.

As with ConvertAsync(Stream, Stream, CancellationToken), the PDF is written straight through as the renderer produces it rather than assembled into an array first — so a failure part-way leaves whatever had already been produced on destination.

public static Task ConvertAsync(Stream source, Stream destination, CancellationToken ct = default)

Parameters

source Stream

The stream the .xlsx package is read from.

destination Stream

The stream the PDF is written to.

ct CancellationToken

Cancels the read, the render and the write.

Returns

Task

Exceptions

ArgumentNullException

Either stream is null.

ArgumentException

source is not readable or held no bytes, or destination is not writable.

OperationCanceledException

ct was cancelled.

DocumentConversionException

The workbook could not be rendered.

ConvertFile(string, string)

Renders inputPath to a PDF at outputPath.

public static void ConvertFile(string inputPath, string outputPath)

Parameters

inputPath string

The .xlsx to read.

outputPath string

Where to write the PDF. Overwritten if it exists.

Exceptions

ArgumentException

Either path is blank.

DocumentConversionException

The workbook could not be rendered.