@docx-editor.dev/docx-to-pdf 0.0.1 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,146 @@
1
+ /// <reference lib="dom" />
2
+ import { OpenFontBackedDocumentForExportOptions, OpenFontBackedDocumentForExportResult, ExportFontResolutionReport, FontBackedExportCapabilities } from '@docx-editor.dev/core/export';
3
+ export { ExportDroppedEmbeddedFont, ExportFontFaceResolution, ExportFontFamilyResolution, ExportFontResolutionReport, ExportResourceError, FontOriginFailure } from '@docx-editor.dev/core/export';
4
+ import { FontOrigin } from '@docx-editor.dev/core/editor';
5
+ export { createFontSource, defineFontResolver } from '@docx-editor.dev/core/editor';
6
+ import { HeadlessDocumentRejection } from '@docx-editor.dev/core/store';
7
+ export { HeadlessDocumentRejection } from '@docx-editor.dev/core/store';
8
+ import { RevisionDisplayMode } from '@docx-editor.dev/core/layout';
9
+ export { FontRequest, FontSubstitution, RevisionDisplayMode } from '@docx-editor.dev/core/layout';
10
+
11
+ /** A bounded explanation of content the PDF cannot reproduce. @public */
12
+ interface PdfDiagnostic {
13
+ /** Machine-readable diagnostic identifier. Handle unknown codes by severity. */
14
+ readonly code: string;
15
+ /** Human-readable explanation. Do not use this text for program control. */
16
+ readonly message: string;
17
+ /** Zero-based page index. Omitted for document-wide diagnostics. */
18
+ readonly pageIndex?: number;
19
+ /** One-based page number for display, consistent with Markdown warnings. */
20
+ readonly pageNumber?: number;
21
+ /** Failed font source index, when this diagnostic describes a source failure. */
22
+ readonly originIndex?: number;
23
+ /** Failed font source name, when the source provided one. */
24
+ readonly originName?: string;
25
+ /** Strict export permits only information diagnostics. */
26
+ readonly severity: 'unsupported' | 'approximation' | 'information';
27
+ }
28
+ /** A font configuration or document-aware resolver. @public */
29
+ type PdfFontOrigin = FontOrigin;
30
+ /** Ordered font configurations or resolvers. Earlier sources take priority. @public */
31
+ type PdfFontsSource = PdfFontOrigin | readonly PdfFontOrigin[];
32
+ /** Node conversion controls. Font substitution follows Core's independent fontPolicy. @public */
33
+ interface PdfExportOptions extends Omit<OpenFontBackedDocumentForExportOptions, 'fonts' | 'measurer' | 'producer' | 'reuseAcrossRevisions'> {
34
+ /** Revision display mode. Defaults to proposed. */
35
+ readonly displayMode?: RevisionDisplayMode;
36
+ /** Apply optional document ligatures during measurement and output. Defaults to true. */
37
+ readonly documentLigatures?: boolean;
38
+ /** Sources after embedded fonts and before the built-in generic substitutes. */
39
+ readonly lastResortFonts?: PdfFontsSource;
40
+ /** Use installed Word fonts before packaged substitutes. Defaults to true. */
41
+ readonly useSystemFonts?: boolean;
42
+ /** Font sources before installed and packaged fonts. */
43
+ readonly fonts?: PdfFontsSource;
44
+ /** Font sources after packaged fonts and before embedded fonts. */
45
+ readonly fallbackFonts?: PdfFontsSource;
46
+ /** Reject unsupported or approximate content by default. */
47
+ readonly fidelityPolicy?: 'strict' | 'best-effort';
48
+ /** Include native PDF comment annotations. Defaults to true. */
49
+ readonly comments?: boolean;
50
+ /** Cooperative conversion deadline. Defaults to 60000 milliseconds. */
51
+ readonly timeoutMs?: number;
52
+ /** Maximum encoded bytes, from 1 to 67108864. Defaults to 67108864. */
53
+ readonly maxOutputBytes?: number;
54
+ /** Maximum output pages, from 1 to 10000. Checked after layout. Defaults to 10000. */
55
+ readonly maxPages?: number;
56
+ }
57
+ /** Elapsed milliseconds for each conversion phase. @public */
58
+ interface PdfExportTimings {
59
+ readonly openMs: number;
60
+ readonly layoutMs: number;
61
+ readonly paintMs: number;
62
+ readonly saveMs: number;
63
+ }
64
+ /** Result owns its bytes; mutating them does not affect a session or subsequent export. @public */
65
+ interface PdfExportResult {
66
+ /** Owned, mutable PDF bytes. Use application/pdf when serving them. */
67
+ readonly bytes: Uint8Array;
68
+ /** Physical PDF page count. */
69
+ readonly pageCount: number;
70
+ /** Layout revision for this conversion; not a persistent document identifier. */
71
+ readonly layoutRevision: number;
72
+ /** Revision display mode applied to the document. */
73
+ readonly displayMode: RevisionDisplayMode;
74
+ /** Selected faces, substitutions, and failed font sources. */
75
+ readonly fontResolution: ExportFontResolutionReport;
76
+ /** Immutable output limitations and informational notices. */
77
+ readonly diagnostics: readonly PdfDiagnostic[];
78
+ /** Wall-clock milliseconds spent opening and resolving fonts, laying out, painting, and saving. */
79
+ readonly timings: PdfExportTimings;
80
+ }
81
+ /** Requested content could not be represented faithfully. @public */
82
+ declare class PdfFidelityError extends Error {
83
+ readonly diagnostics: readonly PdfDiagnostic[];
84
+ readonly code = "fidelityUnsupported";
85
+ constructor(diagnostics: readonly PdfDiagnostic[]);
86
+ }
87
+ /** Core refused the input package. @public */
88
+ declare class PdfDocumentOpenError extends Error {
89
+ readonly reason: HeadlessDocumentRejection | 'aborted';
90
+ readonly detail?: string | undefined;
91
+ readonly code = "documentOpenFailed";
92
+ constructor(reason: HeadlessDocumentRejection | 'aborted', detail?: string | undefined);
93
+ }
94
+ /** PDF encoding failed after a document was opened. @public */
95
+ declare class PdfEncodingError extends Error {
96
+ readonly code: 'encodingFailed' | 'outputTooLarge';
97
+ constructor(message: string, options?: ErrorOptions);
98
+ }
99
+ /** Encoded output exceeds the configured byte limit. @public */
100
+ declare class PdfOutputLimitError extends PdfEncodingError {
101
+ readonly limit: number;
102
+ readonly actual: number;
103
+ readonly code = "outputTooLarge";
104
+ constructor(limit: number, actual: number);
105
+ }
106
+ /** Layout exceeds the configured page limit. @public */
107
+ declare class PdfPageLimitError extends RangeError {
108
+ readonly limit: number;
109
+ readonly actual: number;
110
+ readonly code = "pageLimitExceeded";
111
+ constructor(limit: number, actual: number);
112
+ }
113
+ /** Output controls for a caller-owned PDF session. @public */
114
+ type PdfProjectionOptions = Pick<PdfExportOptions, 'comments' | 'fidelityPolicy' | 'timeoutMs' | 'maxOutputBytes' | 'maxPages' | 'signal' | 'displayMode'>;
115
+ /** Font and layout controls for a reusable immutable-byte session. @public */
116
+ type OpenPdfDocumentForExportOptions = Omit<PdfExportOptions, 'comments' | 'fidelityPolicy' | 'timeoutMs' | 'maxOutputBytes' | 'maxPages'>;
117
+ /** Session that retains the admitted fonts and glyph capabilities needed by PDF output. @public */
118
+ type PdfExportSession = FontBackedExportCapabilities;
119
+ /** Open result with the same success/refusal shape as Markdown sessions. @public */
120
+ type OpenPdfDocumentForExportResult = OpenFontBackedDocumentForExportResult;
121
+
122
+ /** Convert DOCX bytes. Disposes its session after success or failure. @public */
123
+ declare function exportPdf(source: Uint8Array, options?: PdfExportOptions): Promise<PdfExportResult>;
124
+ /**
125
+ * Encode a caller-owned font-backed session without reopening the document.
126
+ * Does not dispose the session. The caller must dispose it after all exports.
127
+ * Cancellation stops this export; the session's signal controls shared resource work.
128
+ * @public
129
+ */
130
+ declare function exportPdfFrom(session: PdfExportSession, options?: PdfProjectionOptions): Promise<PdfExportResult>;
131
+
132
+ /**
133
+ * Open a reusable PDF session over immutable DOCX bytes.
134
+ * Pass the session to exportPdfFrom or Markdown's exportMarkdownFrom.
135
+ * The caller must dispose the session. Its signal controls the entire session lifetime.
136
+ * @public
137
+ */
138
+ declare function openDocumentForExport(source: Uint8Array, options?: OpenPdfDocumentForExportOptions): Promise<OpenPdfDocumentForExportResult>;
139
+
140
+ /** Content exceeds a processing budget. @public */
141
+ declare class PdfWorkLimitError extends Error {
142
+ readonly code = "workLimitExceeded";
143
+ constructor();
144
+ }
145
+
146
+ export { type OpenPdfDocumentForExportOptions, type OpenPdfDocumentForExportResult, type PdfDiagnostic, PdfDocumentOpenError, PdfEncodingError, type PdfExportOptions, type PdfExportResult, type PdfExportSession, type PdfExportTimings, PdfFidelityError, type PdfFontOrigin, type PdfFontsSource, PdfOutputLimitError, PdfPageLimitError, type PdfProjectionOptions, PdfWorkLimitError, exportPdf, exportPdfFrom, openDocumentForExport };
@@ -0,0 +1,146 @@
1
+ /// <reference lib="dom" />
2
+ import { OpenFontBackedDocumentForExportOptions, OpenFontBackedDocumentForExportResult, ExportFontResolutionReport, FontBackedExportCapabilities } from '@docx-editor.dev/core/export';
3
+ export { ExportDroppedEmbeddedFont, ExportFontFaceResolution, ExportFontFamilyResolution, ExportFontResolutionReport, ExportResourceError, FontOriginFailure } from '@docx-editor.dev/core/export';
4
+ import { FontOrigin } from '@docx-editor.dev/core/editor';
5
+ export { createFontSource, defineFontResolver } from '@docx-editor.dev/core/editor';
6
+ import { HeadlessDocumentRejection } from '@docx-editor.dev/core/store';
7
+ export { HeadlessDocumentRejection } from '@docx-editor.dev/core/store';
8
+ import { RevisionDisplayMode } from '@docx-editor.dev/core/layout';
9
+ export { FontRequest, FontSubstitution, RevisionDisplayMode } from '@docx-editor.dev/core/layout';
10
+
11
+ /** A bounded explanation of content the PDF cannot reproduce. @public */
12
+ interface PdfDiagnostic {
13
+ /** Machine-readable diagnostic identifier. Handle unknown codes by severity. */
14
+ readonly code: string;
15
+ /** Human-readable explanation. Do not use this text for program control. */
16
+ readonly message: string;
17
+ /** Zero-based page index. Omitted for document-wide diagnostics. */
18
+ readonly pageIndex?: number;
19
+ /** One-based page number for display, consistent with Markdown warnings. */
20
+ readonly pageNumber?: number;
21
+ /** Failed font source index, when this diagnostic describes a source failure. */
22
+ readonly originIndex?: number;
23
+ /** Failed font source name, when the source provided one. */
24
+ readonly originName?: string;
25
+ /** Strict export permits only information diagnostics. */
26
+ readonly severity: 'unsupported' | 'approximation' | 'information';
27
+ }
28
+ /** A font configuration or document-aware resolver. @public */
29
+ type PdfFontOrigin = FontOrigin;
30
+ /** Ordered font configurations or resolvers. Earlier sources take priority. @public */
31
+ type PdfFontsSource = PdfFontOrigin | readonly PdfFontOrigin[];
32
+ /** Node conversion controls. Font substitution follows Core's independent fontPolicy. @public */
33
+ interface PdfExportOptions extends Omit<OpenFontBackedDocumentForExportOptions, 'fonts' | 'measurer' | 'producer' | 'reuseAcrossRevisions'> {
34
+ /** Revision display mode. Defaults to proposed. */
35
+ readonly displayMode?: RevisionDisplayMode;
36
+ /** Apply optional document ligatures during measurement and output. Defaults to true. */
37
+ readonly documentLigatures?: boolean;
38
+ /** Sources after embedded fonts and before the built-in generic substitutes. */
39
+ readonly lastResortFonts?: PdfFontsSource;
40
+ /** Use installed Word fonts before packaged substitutes. Defaults to true. */
41
+ readonly useSystemFonts?: boolean;
42
+ /** Font sources before installed and packaged fonts. */
43
+ readonly fonts?: PdfFontsSource;
44
+ /** Font sources after packaged fonts and before embedded fonts. */
45
+ readonly fallbackFonts?: PdfFontsSource;
46
+ /** Reject unsupported or approximate content by default. */
47
+ readonly fidelityPolicy?: 'strict' | 'best-effort';
48
+ /** Include native PDF comment annotations. Defaults to true. */
49
+ readonly comments?: boolean;
50
+ /** Cooperative conversion deadline. Defaults to 60000 milliseconds. */
51
+ readonly timeoutMs?: number;
52
+ /** Maximum encoded bytes, from 1 to 67108864. Defaults to 67108864. */
53
+ readonly maxOutputBytes?: number;
54
+ /** Maximum output pages, from 1 to 10000. Checked after layout. Defaults to 10000. */
55
+ readonly maxPages?: number;
56
+ }
57
+ /** Elapsed milliseconds for each conversion phase. @public */
58
+ interface PdfExportTimings {
59
+ readonly openMs: number;
60
+ readonly layoutMs: number;
61
+ readonly paintMs: number;
62
+ readonly saveMs: number;
63
+ }
64
+ /** Result owns its bytes; mutating them does not affect a session or subsequent export. @public */
65
+ interface PdfExportResult {
66
+ /** Owned, mutable PDF bytes. Use application/pdf when serving them. */
67
+ readonly bytes: Uint8Array;
68
+ /** Physical PDF page count. */
69
+ readonly pageCount: number;
70
+ /** Layout revision for this conversion; not a persistent document identifier. */
71
+ readonly layoutRevision: number;
72
+ /** Revision display mode applied to the document. */
73
+ readonly displayMode: RevisionDisplayMode;
74
+ /** Selected faces, substitutions, and failed font sources. */
75
+ readonly fontResolution: ExportFontResolutionReport;
76
+ /** Immutable output limitations and informational notices. */
77
+ readonly diagnostics: readonly PdfDiagnostic[];
78
+ /** Wall-clock milliseconds spent opening and resolving fonts, laying out, painting, and saving. */
79
+ readonly timings: PdfExportTimings;
80
+ }
81
+ /** Requested content could not be represented faithfully. @public */
82
+ declare class PdfFidelityError extends Error {
83
+ readonly diagnostics: readonly PdfDiagnostic[];
84
+ readonly code = "fidelityUnsupported";
85
+ constructor(diagnostics: readonly PdfDiagnostic[]);
86
+ }
87
+ /** Core refused the input package. @public */
88
+ declare class PdfDocumentOpenError extends Error {
89
+ readonly reason: HeadlessDocumentRejection | 'aborted';
90
+ readonly detail?: string | undefined;
91
+ readonly code = "documentOpenFailed";
92
+ constructor(reason: HeadlessDocumentRejection | 'aborted', detail?: string | undefined);
93
+ }
94
+ /** PDF encoding failed after a document was opened. @public */
95
+ declare class PdfEncodingError extends Error {
96
+ readonly code: 'encodingFailed' | 'outputTooLarge';
97
+ constructor(message: string, options?: ErrorOptions);
98
+ }
99
+ /** Encoded output exceeds the configured byte limit. @public */
100
+ declare class PdfOutputLimitError extends PdfEncodingError {
101
+ readonly limit: number;
102
+ readonly actual: number;
103
+ readonly code = "outputTooLarge";
104
+ constructor(limit: number, actual: number);
105
+ }
106
+ /** Layout exceeds the configured page limit. @public */
107
+ declare class PdfPageLimitError extends RangeError {
108
+ readonly limit: number;
109
+ readonly actual: number;
110
+ readonly code = "pageLimitExceeded";
111
+ constructor(limit: number, actual: number);
112
+ }
113
+ /** Output controls for a caller-owned PDF session. @public */
114
+ type PdfProjectionOptions = Pick<PdfExportOptions, 'comments' | 'fidelityPolicy' | 'timeoutMs' | 'maxOutputBytes' | 'maxPages' | 'signal' | 'displayMode'>;
115
+ /** Font and layout controls for a reusable immutable-byte session. @public */
116
+ type OpenPdfDocumentForExportOptions = Omit<PdfExportOptions, 'comments' | 'fidelityPolicy' | 'timeoutMs' | 'maxOutputBytes' | 'maxPages'>;
117
+ /** Session that retains the admitted fonts and glyph capabilities needed by PDF output. @public */
118
+ type PdfExportSession = FontBackedExportCapabilities;
119
+ /** Open result with the same success/refusal shape as Markdown sessions. @public */
120
+ type OpenPdfDocumentForExportResult = OpenFontBackedDocumentForExportResult;
121
+
122
+ /** Convert DOCX bytes. Disposes its session after success or failure. @public */
123
+ declare function exportPdf(source: Uint8Array, options?: PdfExportOptions): Promise<PdfExportResult>;
124
+ /**
125
+ * Encode a caller-owned font-backed session without reopening the document.
126
+ * Does not dispose the session. The caller must dispose it after all exports.
127
+ * Cancellation stops this export; the session's signal controls shared resource work.
128
+ * @public
129
+ */
130
+ declare function exportPdfFrom(session: PdfExportSession, options?: PdfProjectionOptions): Promise<PdfExportResult>;
131
+
132
+ /**
133
+ * Open a reusable PDF session over immutable DOCX bytes.
134
+ * Pass the session to exportPdfFrom or Markdown's exportMarkdownFrom.
135
+ * The caller must dispose the session. Its signal controls the entire session lifetime.
136
+ * @public
137
+ */
138
+ declare function openDocumentForExport(source: Uint8Array, options?: OpenPdfDocumentForExportOptions): Promise<OpenPdfDocumentForExportResult>;
139
+
140
+ /** Content exceeds a processing budget. @public */
141
+ declare class PdfWorkLimitError extends Error {
142
+ readonly code = "workLimitExceeded";
143
+ constructor();
144
+ }
145
+
146
+ export { type OpenPdfDocumentForExportOptions, type OpenPdfDocumentForExportResult, type PdfDiagnostic, PdfDocumentOpenError, PdfEncodingError, type PdfExportOptions, type PdfExportResult, type PdfExportSession, type PdfExportTimings, PdfFidelityError, type PdfFontOrigin, type PdfFontsSource, PdfOutputLimitError, PdfPageLimitError, type PdfProjectionOptions, PdfWorkLimitError, exportPdf, exportPdfFrom, openDocumentForExport };