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);

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 written straight through to destination as the renderer produces it rather than being assembled into an array first, so a large document is delivered without ever existing in full in memory. The consequence of streaming is that a failure part-way through leaves whatever had already been produced on destination.

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