PDF API

Reference PDF export functions, options, results, diagnostic severity, and errors.

Import these functions and types from @pptx-editor.dev/pptx-to-pdf.

Functions

FunctionResult
exportPdf(source, options?)Promise of PdfExportResult from PPTX bytes
openDocumentForExport(source, options?)Promise of a success session or an open refusal
exportPdfFrom(session, options?)Promise of PdfExportResult from an existing session
session.dispose()Releases the session

Sources are Uint8Array values. Node.js Buffer values also work. An open result has either { ok: true, session } or { ok: false, reason, detail? }.

Options

OptionDefaultApplies to
fontsNo additional facesexportPdf, openDocumentForExport
substitutestrueexportPdf, openDocumentForExport
fidelityPolicystrictexportPdf, exportPdfFrom
includeHiddenSlidesfalseexportPdf, exportPdfFrom
timeoutMs60000exportPdf, exportPdfFrom
maxPages10000exportPdf, exportPdfFrom
maxOutputBytes67108864exportPdf, exportPdfFrom
signalNoneAll three functions

maxPages accepts integers from 1 to 10000. maxOutputBytes accepts integers from 1 to 67108864. timeoutMs accepts integers from 1 to 2147483647 and provides a cooperative deadline. Internal paint and image limits also apply; increasing output limits does not disable them.

A session signal ends the whole session. An export signal cancels only that export. exportPdfFrom() rejects unknown option names. Keep font options on the open call and output options on the export call.

Results

FieldMeaning
bytesOwned PDF bytes; serve as application/pdf
pageCountNumber of output pages
slideNumbersOne-based source slide numbers in page order
diagnosticsOutput limitations and information notices
fontResolutionUsed faces, substitutions, and font refusals
timingsopenMs, layoutMs, paintMs, and saveMs

exportPdfFrom() reports openMs: 0 because it reuses an open session. A diagnostic can have slideIndex, slideNumber, pageIndex, and pageNumber. Document-wide diagnostics omit location fields.

Diagnostic severity

SeverityStrict policyBest-effort policy
informationExport continuesExport continues
approximationExport failsPDF includes approximate content
unsupportedExport failsPDF can omit content

Branch on code, not message. Handle an unknown diagnostic code by its severity. For example, frame.chart identifies an unsupported chart, while effect.glow identifies an approximate effect. Hyperlinks, speaker notes, and a PDF outline are not written.

Errors

ClassStable codeRecovery
PdfDocumentOpenErrordocumentOpenFailedInspect reason; obtain valid presentation bytes
PdfFidelityErrorfidelityUnsupportedInspect diagnostics; choose best-effort only if acceptable
PdfPageLimitErrorpageLimitExceededReduce pages or increase the configured limit within its cap
PdfOutputLimitErroroutputTooLargeReduce output size or increase the configured limit within its cap
PdfEncodingErrorencodingFailedInspect the cause and report the failure
PdfWorkLimitErrortimeout, aborted, operationsDistinguish cancellation from work limits
ExportResourceErrordisposed, abortedOpen another session
TypeError, RangeErrorNoneCorrect invalid arguments

PdfOutputLimitError extends PdfEncodingError; catch it first when handling them separately. PdfPageLimitError extends RangeError. Both PdfWorkLimitError and ExportResourceError can use aborted, so check the class before the code.

See also