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.

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.

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.