@pptx-editor. dev/ pptx-to-pdf
v0.3.1 · 1 published subpath with full TypeScript signatures and JSDoc.
Package root
@pptx-editor.dev/pptx-to-pdf: PPTX to PDF on Node.js through the PPTX Editor engine.
The names follow DOCX Editor's @docx-editor.dev/docx-to-pdf where the concept is the same.
Functions (3)
exportPdffunctionSource ↗
Convert PPTX bytes to a PDF, one page per slide, on Node.js. Disposes its session after success or failure.
The default fidelityPolicy is strict: if a slide has content the PDF cannot reproduce, the conversion throws PdfFidelityError with every diagnostic. Pass fidelityPolicy: 'best-effort' to get the PDF and read diagnostics instead.
declare function exportPdf(source: Uint8Array, options?: PdfExportOptions): Promise<PdfExportResult>;exportPdfFromfunctionSource ↗
Encode a caller-owned session from openDocumentForExport without reopening the deck. Each slide is laid out once per session, so a second export reuses the layout. Does not dispose the session: the caller disposes it after all exports. Cancellation stops this export only; the session's own signal controls the session.
declare function exportPdfFrom(session: PdfExportSession, options?: PdfProjectionOptions): Promise<PdfExportResult>;openDocumentForExportfunctionSource ↗
Open a reusable PDF session over immutable PPTX bytes. Pass the session to exportPdfFrom as many times as you need: each slide is laid out once. The caller must dispose the session. Its signal controls the entire session lifetime.
declare function openDocumentForExport(source: Uint8Array, options?: OpenPdfDocumentForExportOptions): Promise<OpenPdfDocumentForExportResult>;Classes (7)
ExportResourceErrorclassSource ↗
A caller-owned export session cannot serve an export: it was disposed, or the signal given to openDocumentForExport aborted (which also disposes it). For aborted, cause is the signal's reason. DOCX Editor throws the same name from its Core.
declare class ExportResourceError extends Error| Member | Type | Summary |
|---|---|---|
| (constructor) | | Constructs a new instance of the `ExportResourceError` class |
| code | 'disposed' | 'aborted' | Stable error code: the session was disposed, or its signal aborted. |
PdfDocumentOpenErrorclassSource ↗
Core refused the input package.
declare class PdfDocumentOpenError extends Error| Member | Type | Summary |
|---|---|---|
| (constructor) | | Constructs a new instance of the `PdfDocumentOpenError` class |
| code | | Stable error code. |
| detail? | string | More detail, when core gives it. |
| reason | OpenError['reason'] | Why core refused the package, as `openPresentation` reports it. |
PdfEncodingErrorclassSource ↗
PDF encoding failed after a document was opened.
declare class PdfEncodingError extends Error| Member | Type | Summary |
|---|---|---|
| (constructor) | | Constructs a new instance of the `PdfEncodingError` class |
| code | 'encodingFailed' | 'outputTooLarge' | Stable error code: `outputTooLarge` on the [PdfOutputLimitError](PdfOutputLimitError) subclass. |
PdfFidelityErrorclassSource ↗
Requested content could not be represented faithfully.
declare class PdfFidelityError extends Error| Member | Type | Summary |
|---|---|---|
| (constructor) | | Constructs a new instance of the `PdfFidelityError` class |
| code | | Stable error code. |
| diagnostics | readonly PdfDiagnostic[] | Every diagnostic of the conversion; the blocking ones name the slide and feature. |
PdfOutputLimitErrorclassSource ↗
Encoded output exceeds the configured byte limit.
declare class PdfOutputLimitError extends PdfEncodingError| Member | Type | Summary |
|---|---|---|
| (constructor) | | Constructs a new instance of the `PdfOutputLimitError` class |
| actual | number | The encoded size in bytes. |
| code | | Stable error code. |
| limit | number | The `maxOutputBytes` option. |
PdfPageLimitErrorclassSource ↗
The deck exceeds the configured page limit.
declare class PdfPageLimitError extends RangeError| Member | Type | Summary |
|---|---|---|
| (constructor) | | Constructs a new instance of the `PdfPageLimitError` class |
| actual | number | The number of pages the deck would export. |
| code | | Stable error code. |
| limit | number | The `maxPages` option. |
PdfWorkLimitErrorclassSource ↗
The conversion passed its deadline, was cancelled, or ran past its paint budget. For aborted, cause is the signal's reason.
declare class PdfWorkLimitError extends Error| Member | Type | Summary |
|---|---|---|
| (constructor) | | Constructs a new instance of the `PdfWorkLimitError` class |
| code | 'timeout' | 'aborted' | 'operations' | Stable error code: past `timeoutMs`, cancelled through `signal`, or past the paint budget (paint operations or PDF content bytes). |
Interfaces (6)
PdfDiagnosticinterfaceSource ↗
A bounded explanation of content the PDF cannot reproduce.
interface PdfDiagnostic| Member | Type | Summary |
|---|---|---|
| code | string | Machine-readable diagnostic identifier, from a fixed set. Handle unknown codes by severity. |
| message | string | Human-readable explanation. Do not use this text for program control. |
| pageIndex? | number | Zero-based PDF page index. Omitted when the slide produced no page. |
| pageNumber? | number | One-based PDF page number for display. |
| severity | 'unsupported' | 'approximation' | 'information' | Strict export permits only information diagnostics. |
| slideIndex? | number | Zero-based slide index in the deck, hidden slides included. Omitted for document-wide diagnostics. |
| slideNumber? | number | One-based slide number in the deck, hidden slides included. |
PdfExportOptionsinterfaceSource ↗
Node conversion controls.
interface PdfExportOptions| Member | Type | Summary |
|---|---|---|
| fidelityPolicy? | 'strict' | 'best-effort' | Reject unsupported or approximate content. Defaults to `strict`. |
| fonts? | PdfFontsSource | Font faces tried before embedded and substitute fonts. |
| maxOutputBytes? | number | Maximum encoded bytes, from 1 to 67108864. Defaults to 67108864. |
| maxPages? | number | Maximum output pages, from 1 to 10000. Defaults to 10000. |
| signal? | AbortSignal | Cancels the conversion. Its `reason` is the `cause` of the thrown `PdfWorkLimitError`. |
| substitutes? | boolean | Load the metric-compatible substitutes from `@docx-editor.dev/fonts`. Defaults to true. DOCX Editor configures this through its font sources instead. |
| timeoutMs? | number | Cooperative conversion deadline. Defaults to 60000 milliseconds. |
PdfExportResultinterfaceSource ↗
Result owns its bytes.
interface PdfExportResult| Member | Type | Summary |
|---|---|---|
| bytes | Uint8Array | Owned, mutable PDF bytes. Use application/pdf when serving them. |
| diagnostics | readonly PdfDiagnostic[] | Immutable output limitations and informational notices. |
| fontResolution | PdfFontResolution | Selected faces and substitutions. |
| pageCount | number | Physical PDF page count: one page per exported slide. |
| slideNumbers | readonly number[] | The one-based deck slide number of each page, in page order. Hidden slides (unless `includeHiddenSlides` is true) and slides that could not be laid out have no page, so page `i` shows slide `slideNumbers[i]`. |
| timings | PdfExportTimings | Wall-clock milliseconds spent opening, laying out, painting, and saving. |
PdfExportSessioninterfaceSource ↗
An open deck with its fonts and slide layouts, for exportPdfFrom. Each slide is laid out once and reused by every export. The caller owns the session and must call dispose().
interface PdfExportSession| Member | Type | Summary |
|---|---|---|
| dispose | | Release the session. Later exports reject with `ExportResourceError` (`disposed`). |
| fontResolution | PdfFontResolution | The faces the session measures with, and the families it substituted. |
PdfExportTimingsinterfaceSource ↗
Elapsed milliseconds for each conversion phase.
interface PdfExportTimings| Member | Type | Summary |
|---|---|---|
| layoutMs | number | Laying out every exported slide. |
| openMs | number | Reading and opening the deck. |
| paintMs | number | Painting every page into the PDF. |
| saveMs | number | Encoding the PDF bytes. |
PdfFontResolutioninterfaceSource ↗
The faces the conversion drew with, and the families it substituted.
interface PdfFontResolution| Member | Type | Summary |
|---|---|---|
| faces | readonly {
readonly family: string;
readonly origin: string;
}[] | Each face drawn with: its family, and its origin (for example `embedded`, `provided`, or `substitute`). |
| refusedEmbedded | readonly string[] | Embedded faces the deck carries that may not be used, with the reason. |
| substituteFailures | readonly SubstituteFontFailure[] | Packaged substitute faces that failed to load, each with its family, file, and reason. |
| substitutions | readonly FontSubstitution[] | Families the deck asked for that no face covered, with the family used instead. |
Type aliases (4)
OpenPdfDocumentForExportOptionstypeSource ↗
Font controls for a reusable session over immutable PPTX bytes.
type OpenPdfDocumentForExportOptions = Omit<PdfExportOptions, 'fidelityPolicy' | 'includeHiddenSlides' | 'timeoutMs' | 'maxOutputBytes' | 'maxPages' | 'signal'> & {
readonly signal?: AbortSignal;
};OpenPdfDocumentForExportResulttypeSource ↗
Open result, with DOCX Editor's success and refusal shape.
type OpenPdfDocumentForExportResult = {
readonly ok: true;
readonly session: PdfExportSession;
} | {
readonly ok: false;
readonly reason: OpenError['reason'] | 'aborted';
readonly detail?: string;
};PdfFontsSourcetypeSource ↗
One font face or several. Earlier faces win.
type PdfFontsSource = FontSource | readonly FontSource[];PdfProjectionOptionstypeSource ↗
Output controls for a caller-owned PDF session.
type PdfProjectionOptions = Pick<PdfExportOptions, 'fidelityPolicy' | 'includeHiddenSlides' | 'timeoutMs' | 'maxOutputBytes' | 'maxPages' | 'signal'>;