@docx-editor.dev/docx-to-pdf
v2.36.0 · 1 published subpath with full TypeScript signatures and JSDoc.
Package root
Functions (5)
createFontSourcefunctionSource ↗
Turn font bytes you ALREADY hold into a FontSource — a file input, IndexedDB, a bundler import. loadFonts covers URLs; this covers everything else, so no caller has to hand-assemble the record or reach for a hashing helper.
Returns a typed failure instead of throwing when the descriptor or the bytes are unusable, matching loadFonts: one bad face degrades itself, never its neighbours.
declare function createFontSource(bytes: Uint8Array, request: FontFaceRequest & {
readonly faceIndex?: number;
}, options?: {
readonly id?: string;
readonly maxFontBytes?: number;
}): {
readonly source: FontSource;
} | {
readonly failure: FontLoadFailure;
};defineFontResolverfunctionSource ↗
Mark a function as an on-demand [FontResolver](FontResolver).
Wrap every resolver you put in a fonts list — useFonts(...), useDocxSource's fonts option, composeFontOrigins. The fonts PROP needs no marking, because a function there is always a resolver; a list also accepts the older zero-argument loader form ({ fonts: defaultFonts }), and this is what keeps the two apart.
Returns the same function object, mutated, so the mark survives being passed around and a marked resolver stays === to itself. It does NOT survive .bind() or being wrapped: both make a new function object. Re-mark the result.
ts
const brandFonts = defineFontResolver(async ({ families }) => ({
sources: await loadMine(families),
}));
Throws a TypeError on a frozen or sealed function, which cannot take the mark. That is deliberate: returning it unmarked would compile — the return TYPE says marked — and then lose every font at runtime.
declare function defineFontResolver<T extends FontResolver>(resolve: T): MarkedFontResolver<T>;exportPdffunctionSource ↗
Convert DOCX bytes. Disposes its session after success or failure.
declare function exportPdf(source: Uint8Array, options?: PdfExportOptions): Promise<PdfExportResult>;exportPdfFromfunctionSource ↗
Encode a caller-owned font-backed session without reopening the document. Does not dispose the session. The caller must dispose it after all exports. Cancellation stops this export; the session's signal controls shared resource work.
declare function exportPdfFrom(session: PdfExportSession, options?: PdfProjectionOptions): Promise<PdfExportResult>;openDocumentForExportfunctionSource ↗
Open a reusable PDF session over immutable DOCX bytes. Pass the session to exportPdfFrom or Markdown's exportMarkdownFrom. 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 ↗
Bounded failure from a headless export session.
declare class ExportResourceError extends Error| Member | Type | Summary |
|---|---|---|
| (constructor) | | Constructs a new instance of the `ExportResourceError` class |
| code | 'aborted' | 'timedOut' | 'nonConvergent' | 'disposed' | 'layoutInvariant' | 'layoutFailed' |
PdfDocumentOpenErrorclassSource ↗
Core refused the input package.
declare class PdfDocumentOpenError extends Error| Member | Type | Summary |
|---|---|---|
| (constructor) | | Constructs a new instance of the `PdfDocumentOpenError` class |
| code | | |
| detail? | string | undefined | |
| reason | HeadlessDocumentRejection | 'aborted' |
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' |
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 | | |
| diagnostics | readonly PdfDiagnostic[] |
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 | |
| code | | |
| limit | number |
PdfPageLimitErrorclassSource ↗
Layout exceeds the configured page limit.
declare class PdfPageLimitError extends RangeError| Member | Type | Summary |
|---|---|---|
| (constructor) | | Constructs a new instance of the `PdfPageLimitError` class |
| actual | number | |
| code | | |
| limit | number |
PdfWorkLimitErrorclassSource ↗
Content exceeds a processing budget.
declare class PdfWorkLimitError extends Error| Member | Type | Summary |
|---|---|---|
| (constructor) | | Constructs a new instance of the `PdfWorkLimitError` class |
| code | |
Interfaces (15)
ExportDroppedEmbeddedFontinterface
One document-embedded face the export mapper refused before composition.
interface ExportDroppedEmbeddedFont| Member | Type | Summary |
|---|---|---|
| partName | string | |
| reason | 'overLimit' | 'malformed' | |
| request | FontRequest |
ExportFontFaceResolutioninterface
One paintable face in an export font-resolution report.
interface ExportFontFaceResolution| Member | Type | Summary |
|---|---|---|
| faceIndex? | number | |
| hash? | string | |
| id? | string | |
| identity? | string | Admitted face identity (`hash#faceIndex`); remains after session disposal. |
| sourceFamily | string | |
| style | 'normal' | 'italic' | |
| substitution? | FontSubstitution | null | Full substitution evidence; `null` when the admitted face answers the request directly. |
| via | 'direct' | 'substitution' | |
| weight | 400 | 700 |
ExportFontFamilyResolutioninterface
Coverage of one family Core layout may request.
interface ExportFontFamilyResolution| Member | Type | Summary |
|---|---|---|
| coverage | 'complete' | 'partial' | 'none' | |
| faces | readonly ExportFontFaceResolution[] | |
| family | string |
ExportFontResolutionReportinterface
Exporter-neutral evidence for the font policy behind one layout session.
interface ExportFontResolutionReport| Member | Type | Summary |
|---|---|---|
| defaultFamily | string | |
| droppedEmbeddedFonts? | readonly ExportDroppedEmbeddedFont[] | Bounded drop evidence from the document-embedded font origin; omitted on legacy mocks. |
| families | readonly ExportFontFamilyResolution[] | |
| originFailures | readonly FontOriginFailure[] | |
| requestedFamilies | readonly string[] |
FontOriginFailureinterface
A failed font origin or a partial failure in an otherwise usable fragment.
interface FontOriginFailure| Member | Type | Summary |
|---|---|---|
| cause | unknown | |
| originIndex | number | Zero-based position in the first-wins origin list. |
| originName? | string | Resolver function name when one is safely available. |
FontRequestinterface
A face, as something asks for it: family plus the two axes this engine admits.
Only static weights and slants. Variable-font axes are deliberately outside this vocabulary — the shaper refuses variation axes, and a variable file admitted here would render bold at regular weight.
interface FontRequest| Member | Type | Summary |
|---|---|---|
| family | string | |
| style | 'normal' | 'italic' | |
| weight | number |
FontShapingOptionsinterface
Host-selected execution limits, separate from font admission limits.
interface FontShapingOptions| Member | Type | Summary |
|---|---|---|
| maxFontBytes? | number | Per-face shaping byte ceiling. Defaults to 16 MiB; the hard ceiling is 64 MiB. |
FontSubstitutioninterface
A request that was answered by a DIFFERENT face than the one asked for.
Recorded rather than silently applied, because a substitution changes measurement: it is part of the shaping fingerprint, so a cached run shaped against a substitute is never reused for the real face.
interface FontSubstitution| Member | Type | Summary |
|---|---|---|
| lineMetrics? | {
readonly heightEm: number;
readonly baselineEm: number;
} | |
| requested | FontRequest | |
| resolved | FontRequest |
PdfDiagnosticinterfaceSource ↗
A bounded explanation of content the PDF cannot reproduce.
interface PdfDiagnostic| Member | Type | Summary |
|---|---|---|
| code | string | Machine-readable diagnostic identifier. Handle unknown codes by severity. |
| message | string | Human-readable explanation. Do not use this text for program control. |
| originIndex? | number | Failed font source index, when this diagnostic describes a source failure. |
| originName? | string | Failed font source name, when the source provided one. |
| pageIndex? | number | Zero-based page index. Omitted for document-wide diagnostics. |
| pageNumber? | number | One-based page number for display, consistent with Markdown warnings. |
| severity | 'unsupported' | 'approximation' | 'information' | Strict export permits only information diagnostics. |
PdfExportOptionsinterfaceSource ↗
Node conversion controls. Font substitution follows Core's independent fontPolicy.
interface PdfExportOptions extends Omit<OpenFontBackedDocumentForExportOptions, 'fonts' | 'measurer' | 'producer' | 'reuseAcrossRevisions' | 'fontShaping'>| Member | Type | Summary |
|---|---|---|
| comments? | boolean | Include native PDF comment annotations. Defaults to true. |
| displayMode? | ReviewDisplayMode | Revision display mode. Defaults to all-markup, which shows insertions and deletions. |
| documentLigatures? | boolean | Apply optional document ligatures during measurement and output. Defaults to true. |
| fallbackFonts? | PdfFontsSource | Font sources after packaged fonts and before embedded fonts. |
| fidelityPolicy? | 'strict' | 'best-effort' | Reject unsupported or approximate content by default. |
| fonts? | PdfFontsSource | Font sources before installed and packaged fonts. |
| fontShaping? | FontShapingOptions | Text shaping limits. The per-face byte ceiling defaults to 40 MiB, so installed CJK collections such as SimSun are not replaced. The hard maximum is 64 MiB. |
| lastResortFonts? | PdfFontsSource | Sources after embedded fonts and before the built-in generic substitutes. |
| maxOutputBytes? | number | Maximum encoded bytes, from 1 to 67108864. Defaults to 67108864. |
| maxPages? | number | Maximum output pages, from 1 to 10000. Checked after layout. Defaults to 10000. |
| timeoutMs? | number | Cooperative conversion deadline. Defaults to 60000 milliseconds. |
| useSystemFonts? | boolean | Use fonts installed on the system before packaged substitutes. Any family that the document names can resolve to an installed font, so output depends on the machine's fonts. Set to false for the same output on every machine. Defaults to true. |
PdfExportResultinterfaceSource ↗
Result owns its bytes; mutating them does not affect a session or subsequent export.
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. |
| displayMode | ReviewDisplayMode | Revision display mode applied to the document. |
| fontResolution | ExportFontResolutionReport | Selected faces, substitutions, and failed font sources. |
| layoutRevision | number | Layout revision for this conversion; not a persistent document identifier. |
| pageCount | number | Physical PDF page count. |
| timings | PdfExportTimings | Wall-clock milliseconds spent opening and resolving fonts, laying out, painting, and saving. |
PdfExportTimingsinterfaceSource ↗
Elapsed milliseconds for each conversion phase.
interface PdfExportTimings| Member | Type | Summary |
|---|---|---|
| layoutMs | number | |
| openMs | number | |
| paintMs | number | |
| saveMs | number |
ResolvedRevisionMarkupinterface
Fully resolved, immutable viewer preferences.
interface ResolvedRevisionMarkup| Member | Type | Summary |
|---|---|---|
| cells | {
readonly inserted: RevisionMarkupNamedColor | 'byAuthor' | 'none';
readonly deleted: RevisionMarkupNamedColor | 'byAuthor' | 'none';
readonly merged: RevisionMarkupNamedColor | 'byAuthor' | 'none';
readonly split: RevisionMarkupNamedColor | 'byAuthor' | 'none';
} | |
| changedLines | RevisionMarkupStyle<RevisionChangedLinesMark> | |
| deletions | RevisionMarkupTextStyle<RevisionDeletionMark> | |
| formatting | RevisionMarkupTextStyle | |
| insertions | RevisionMarkupTextStyle | |
| movedFrom | RevisionMarkupTextStyle<RevisionDeletionMark> | |
| movedTo | RevisionMarkupTextStyle | |
| trackFormatting | boolean | |
| trackMoves | boolean |
RevisionMarkupStyleinterface
interface RevisionMarkupStyle<Mark extends string = RevisionMarkupMark>| Member | Type | Summary |
|---|---|---|
| color | RevisionMarkupColor | |
| mark | Mark |
RevisionMarkupTextStyleinterface
Viewer-only text styling. Document highlighting remains unchanged.
interface RevisionMarkupTextStyle<Mark extends string = RevisionMarkupMark> extends RevisionMarkupStyle<Mark>| Member | Type | Summary |
|---|---|---|
| background | RevisionMarkupNamedColor | 'byAuthor' | 'none' | Background color behind revision text. Defaults to `none`. |
Type aliases (15)
HeadlessDocumentRejectiontype
A bad package is data, not an exceptional control path.
type HeadlessDocumentRejection = OoxmlPackageRejection | 'no-main-document-tree';OpenPdfDocumentForExportOptionstypeSource ↗
Font and layout controls for a reusable immutable-byte session.
type OpenPdfDocumentForExportOptions = Omit<PdfExportOptions, 'comments' | 'fidelityPolicy' | 'timeoutMs' | 'maxOutputBytes' | 'maxPages'>;OpenPdfDocumentForExportResulttypeSource ↗
Open result with the same success/refusal shape as Markdown sessions.
type OpenPdfDocumentForExportResult = OpenFontBackedDocumentForExportResult;PdfExportSessiontypeSource ↗
Session that retains the admitted fonts and glyph capabilities needed by PDF output.
type PdfExportSession = FontBackedExportCapabilities;PdfFontOrigintypeSource ↗
A font configuration or document-aware resolver.
type PdfFontOrigin = FontOrigin;PdfFontsSourcetypeSource ↗
Ordered font configurations or resolvers. Earlier sources take priority.
type PdfFontsSource = PdfFontOrigin | readonly PdfFontOrigin[];PdfProjectionOptionstypeSource ↗
Output controls for a caller-owned PDF session.
type PdfProjectionOptions = Pick<PdfExportOptions, 'comments' | 'fidelityPolicy' | 'timeoutMs' | 'maxOutputBytes' | 'maxPages' | 'signal' | 'displayMode'>;ReviewDisplayModetype
The views the review chrome offers, in Word's terms: the three layout projections plus Simple Markup, which reads as the proposed result with a red change bar beside every line a change touched — the document as accepting everything would leave it, and where.
type ReviewDisplayMode = RevisionDisplayMode | 'simple-markup';RevisionChangedLinesMarktype
type RevisionChangedLinesMark = 'none' | 'leftBorder' | 'rightBorder' | 'outsideBorder';RevisionDeletionMarktype
type RevisionDeletionMark = RevisionMarkupMark | 'hidden' | 'caret' | 'pound';RevisionDisplayModetype
Which revisions layout resolves before producing pages.
- all-markup shows both halves of every change. - proposed shows what the document becomes if every change is accepted. - original shows what it was before any of them.
The last two are specified as equal to accept-all and reject-all OUTPUT, which is what makes them testable, without either applying an op.
type RevisionDisplayMode = 'all-markup' | 'proposed' | 'original';RevisionMarkupColortype
type RevisionMarkupColor = RevisionMarkupNamedColor | 'byAuthor' | 'auto';RevisionMarkupMarktype
type RevisionMarkupMark = 'none' | 'colorOnly' | 'bold' | 'italic' | 'underline' | 'doubleUnderline' | 'strikethrough' | 'doubleStrikethrough';RevisionMarkupNamedColortype
type RevisionMarkupNamedColor = (typeof REVISION_MARKUP_COLORS)[number];RevisionMarkupOptionstype
Partial viewer preferences. Omitted values keep the previous value.
type RevisionMarkupOptions = {
readonly [K in keyof ResolvedRevisionMarkup]?: ResolvedRevisionMarkup[K] extends boolean ? boolean : Partial<ResolvedRevisionMarkup[K]>;
};Variables (1)
REVISION_MARKUP_COLORSconstSource ↗
Named revision colors. Identifiers are stable and never contain CSS.
REVISION_MARKUP_COLORS: readonly ['black', 'blue', 'turquoise', 'green', 'pink', 'red', 'yellow', 'white', 'darkBlue', 'teal', 'darkGreen', 'violet', 'darkRed', 'darkYellow', 'gray50', 'gray25', 'lightBlue', 'lightYellow', 'lightOrange', 'lightPurple', 'lightGreen', 'gray']