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
docxbyte[]
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
sourceStreamThe stream the .docx package is read from.
destinationStreamThe stream the PDF is written to.
ctCancellationTokenCancels the read, the render and the write.
Returns
Exceptions
- ArgumentNullException
Either stream is null.
- ArgumentException
sourceis not readable or held no bytes, ordestinationis not writable.- OperationCanceledException
ctwas 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)