Class PptxToPdfConverter
- Namespace
- DocToolkit
- Assembly
- DocToolkit.dll
Renders a PowerPoint (.pptx) presentation to PDF, one page per slide. Pure managed — no browser, no LibreOffice, no PowerPoint.
The same three members as DocxToPdfConverter and XlsxToPdfConverter, deliberately: a consumer who has used one has used all three.
No page-setup parameter. A presentation's page size is its p:sldSz — slide
geometry, not paper. PresentationEditor writes 16:9, which renders as a 960 × 540
pt PDF page. Accepting a PageSetup here would invite a caller to letterbox their
own slides onto a paper size that means nothing to a deck.
Fidelity is bounded, and features the renderer cannot represent are dropped rather than reported — see README's Known limitations.
public static class PptxToPdfConverter
- Inheritance
-
PptxToPdfConverter
- Inherited Members
Methods
Convert(byte[])
Renders the .pptx in pptx and returns PDF bytes, one page per slide.
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[] pptx)
Parameters
pptxbyte[]The presentation to render.
Returns
- byte[]
Examples
// One page per slide, at the deck's own 16:9 slide geometry rather than a paper size.
byte[] pdf = PptxToPdfConverter.Convert(pptx);
Exceptions
- ArgumentNullException
pptxis null.- ArgumentException
pptxis empty.- DocumentConversionException
The presentation could not be rendered.
ConvertAsync(Stream, Stream, CancellationToken)
Reads a .pptx from source and writes the rendered PDF to
destination, one page per slide.
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
sourceStreamThe stream the .pptx 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 presentation could not be rendered.
ConvertFile(string, string)
Renders inputPath to a PDF at outputPath.
public static void ConvertFile(string inputPath, string outputPath)
Parameters
inputPathstringThe .pptx to read.
outputPathstringWhere to write the PDF. Overwritten if it exists.
Exceptions
- ArgumentException
Either path is blank.
- DocumentConversionException
The presentation could not be rendered.