Table of Contents

Class DocxToPdfConverter

Namespace
DocToolkit
Assembly
DocToolkit.dll

Renders a Word (.docx) package to PDF. Pure managed - no browser, no LibreOffice.

public static class DocxToPdfConverter
Inheritance
DocxToPdfConverter
Inherited Members

Methods

Convert(byte[])

Renders the .docx in docx and returns PDF bytes.

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

Parameters

docx byte[]

Returns

byte[]

Examples

byte[] pdf = DocxToPdfConverter.Convert(docx);

Convert(byte[], PdfFontOptions?)

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

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

Parameters

docx byte[]

The document to render.

fonts PdfFontOptions

Fonts to fall back to, or null for none.

Returns

byte[]

Remarks

Whether a document containing non-Latin text renders otherwise depends on the machine. The renderer falls back to whatever fonts the host happens to have, and a Windows box offers ones that do not cover Cyrillic - so the same document converts on one machine and is refused on another. Supplying the font removes the machine from the answer.

See PdfFontOptions for the one side effect worth knowing about.

Exceptions

ArgumentNullException

docx is null.

ArgumentException

docx is empty.

DocumentConversionException

The document could not be rendered.

ConvertAsync(Stream, Stream, PdfFontOptions?, CancellationToken)

Reads a .docx 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 .docx 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

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 document could not be rendered.

ConvertAsync(Stream, Stream, CancellationToken)

Reads a .docx 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. Neither has to be seekable.

The PDF is rendered whole and then written, so a failure leaves destination UNTOUCHED rather than carrying a truncated document. Until 2026-08-20 it was written straight through as the renderer produced it; that prevented the repair-and-retry the array overloads apply, and measurably diverged from them - see HtmlToPdfConverter's private EmitAsync for the numbers.

No network access, and safe in an air-gapped environment, as for Convert(byte[]).

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

Parameters

source Stream

The stream the .docx 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 DOCX 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
outputPath string