@yudaocode/univer-pdfs 1.6.215 → 1.6.217
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.
- package/PDF_BROWSER_RENDERING_CONTRACT.md +288 -22
- package/fixtures/pdf-s1-s7-fidelity-v1.json +2010 -0
- package/lib/cjs/facade/index.js +18 -10
- package/lib/cjs/facade/index.js.map +1 -1
- package/lib/cjs/index.js +557 -100
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/jsx/index.js +143 -68
- package/lib/cjs/jsx/index.js.map +1 -1
- package/lib/es/{chunk-DYTQBEM7.js → chunk-EMSHTYYU.js} +148 -70
- package/lib/es/chunk-EMSHTYYU.js.map +1 -0
- package/lib/es/facade/index.js +19 -10
- package/lib/es/facade/index.js.map +1 -1
- package/lib/es/index.js +408 -32
- package/lib/es/index.js.map +1 -1
- package/lib/es/jsx/index.js +1 -1
- package/lib/types/facade/index.d.ts +3 -0
- package/lib/types/index.d.ts +74 -4
- package/lib/types/jsx/index.d.ts +2 -2
- package/lib/types/jsx/jsx-dev-runtime.d.ts +1 -1
- package/lib/types/jsx/jsx-runtime.d.ts +1 -1
- package/lib/types/{jsx-dev-runtime-BFeiWVJj.d.ts → jsx-dev-runtime-Dm72R_Vm.d.ts} +15 -1
- package/package.json +3 -1
- package/lib/es/chunk-DYTQBEM7.js.map +0 -1
package/lib/cjs/index.js
CHANGED
|
@@ -77,6 +77,7 @@ __export(src_exports, {
|
|
|
77
77
|
PDF_JSX_ELEMENT_SYMBOL: () => PDF_JSX_ELEMENT_SYMBOL,
|
|
78
78
|
PDF_JSX_FRAGMENT_SYMBOL: () => PDF_JSX_FRAGMENT_SYMBOL,
|
|
79
79
|
PDF_PAGE_PRESETS: () => PDF_PAGE_PRESETS,
|
|
80
|
+
PDF_S1_S7_FIDELITY_EXPECTATIONS: () => PDF_S1_S7_FIDELITY_EXPECTATIONS,
|
|
80
81
|
PDF_TABLE_THEME_PRESETS: () => PDF_TABLE_THEME_PRESETS,
|
|
81
82
|
PT_PER_MM: () => PT_PER_MM,
|
|
82
83
|
Page: () => Page,
|
|
@@ -159,6 +160,7 @@ __export(src_exports, {
|
|
|
159
160
|
computeExifTransformMatrix: () => computeExifTransformMatrix,
|
|
160
161
|
computeExpandedTextHeightMm: () => computeExpandedTextHeightMm,
|
|
161
162
|
computeExpandedTextHeightPt: () => computeExpandedTextHeightPt,
|
|
163
|
+
computeFontUrlCacheKey: () => computeFontUrlCacheKey,
|
|
162
164
|
computeImageFitPlacement: () => computeImageFitPlacement,
|
|
163
165
|
computePasteCascadeOffset: () => computePasteCascadeOffset,
|
|
164
166
|
computePdfPayloadDigest: () => computePdfPayloadDigest,
|
|
@@ -175,6 +177,8 @@ __export(src_exports, {
|
|
|
175
177
|
createDefaultElement: () => createDefaultElement,
|
|
176
178
|
createDefaultPdfUnitData: () => createDefaultPdfUnitData,
|
|
177
179
|
createHttpSilentPrintAdapter: () => createHttpSilentPrintAdapter,
|
|
180
|
+
createPdfAbortError: () => createPdfAbortError,
|
|
181
|
+
createPdfBrowserFidelityExpectations: () => createPdfBrowserFidelityExpectations,
|
|
178
182
|
createPdfBrowserFidelitySamples: () => createPdfBrowserFidelitySamples,
|
|
179
183
|
createPdfCjkFontSources: () => createPdfCjkFontSources,
|
|
180
184
|
createPdfJsxNode: () => createPdfJsxNode,
|
|
@@ -212,6 +216,7 @@ __export(src_exports, {
|
|
|
212
216
|
exportPdfBytes: () => exportPdfBytes,
|
|
213
217
|
exportPdfToDocxSnapshot: () => exportPdfToDocxSnapshot,
|
|
214
218
|
exportPdfToWorkbookSnapshot: () => exportPdfToWorkbookSnapshot,
|
|
219
|
+
exportPdfWithTarget: () => exportPdfWithTarget,
|
|
215
220
|
exportSignedPdfWithAuditSeal: () => exportSignedPdfWithAuditSeal,
|
|
216
221
|
exportToPdfmeTemplate: () => exportToPdfmeTemplate,
|
|
217
222
|
extractAcroFormValuesFromPdfBytes: () => extractAcroFormValuesFromPdfBytes,
|
|
@@ -9647,14 +9652,42 @@ function createPdfCjkFontSources(options) {
|
|
|
9647
9652
|
url: `${cleanBase}/${preset.file}`,
|
|
9648
9653
|
family,
|
|
9649
9654
|
weight,
|
|
9650
|
-
...integrity ? { integrity } : {}
|
|
9655
|
+
...integrity ? { integrity } : {},
|
|
9656
|
+
...options?.credentials !== void 0 ? { credentials: options.credentials } : {},
|
|
9657
|
+
...options?.fetchInit !== void 0 ? { fetchInit: options.fetchInit } : {}
|
|
9651
9658
|
};
|
|
9652
9659
|
});
|
|
9653
9660
|
}
|
|
9654
9661
|
var pdfFontUrlByteCache = /* @__PURE__ */ new Map();
|
|
9662
|
+
function computeFontUrlCacheKey(url, integrity) {
|
|
9663
|
+
return `${url}|${integrity ?? ""}`;
|
|
9664
|
+
}
|
|
9655
9665
|
function clearPdfFontUrlCache() {
|
|
9656
9666
|
pdfFontUrlByteCache.clear();
|
|
9657
9667
|
}
|
|
9668
|
+
var PdfFontCandidateLoadError = class extends Error {
|
|
9669
|
+
constructor(kind, message, status) {
|
|
9670
|
+
super(message);
|
|
9671
|
+
this.name = "PdfFontCandidateLoadError";
|
|
9672
|
+
this.kind = kind;
|
|
9673
|
+
if (status !== void 0) {
|
|
9674
|
+
this.status = status;
|
|
9675
|
+
}
|
|
9676
|
+
}
|
|
9677
|
+
};
|
|
9678
|
+
function toFailedFontEntry(index, src, err) {
|
|
9679
|
+
const kind = err instanceof PdfFontCandidateLoadError ? err.kind : "format";
|
|
9680
|
+
const status = err instanceof PdfFontCandidateLoadError ? err.status : void 0;
|
|
9681
|
+
return {
|
|
9682
|
+
index,
|
|
9683
|
+
...src.family !== void 0 ? { family: src.family } : {},
|
|
9684
|
+
...src.weight !== void 0 ? { weight: src.weight } : {},
|
|
9685
|
+
...src.url !== void 0 ? { url: src.url } : {},
|
|
9686
|
+
kind,
|
|
9687
|
+
...status !== void 0 ? { status } : {},
|
|
9688
|
+
reason: err?.message || String(err)
|
|
9689
|
+
};
|
|
9690
|
+
}
|
|
9658
9691
|
function bytesToBase64Standard(bytes) {
|
|
9659
9692
|
if (typeof Buffer !== "undefined") {
|
|
9660
9693
|
return Buffer.from(bytes).toString("base64");
|
|
@@ -9670,7 +9703,10 @@ async function verifyFontSubresourceIntegrity(bytes, integrity) {
|
|
|
9670
9703
|
if (!trimmed) return;
|
|
9671
9704
|
const m = trimmed.match(/^(sha256|sha384|sha512)-([A-Za-z0-9+/=_-]+)$/i);
|
|
9672
9705
|
if (!m) {
|
|
9673
|
-
throw new
|
|
9706
|
+
throw new PdfFontCandidateLoadError(
|
|
9707
|
+
"integrity",
|
|
9708
|
+
`Unsupported integrity format '${trimmed}' (expected sha256-/sha384-/sha512-).`
|
|
9709
|
+
);
|
|
9674
9710
|
}
|
|
9675
9711
|
const algoMap = {
|
|
9676
9712
|
sha256: "SHA-256",
|
|
@@ -9681,7 +9717,10 @@ async function verifyFontSubresourceIntegrity(bytes, integrity) {
|
|
|
9681
9717
|
const expectedB64 = m[2].replace(/-/g, "+").replace(/_/g, "/");
|
|
9682
9718
|
const subtle = globalThis.crypto?.subtle;
|
|
9683
9719
|
if (!subtle) {
|
|
9684
|
-
throw new
|
|
9720
|
+
throw new PdfFontCandidateLoadError(
|
|
9721
|
+
"integrity",
|
|
9722
|
+
"Web Crypto API is unavailable to verify font integrity."
|
|
9723
|
+
);
|
|
9685
9724
|
}
|
|
9686
9725
|
const digestBuf = await subtle.digest(
|
|
9687
9726
|
algo,
|
|
@@ -9690,45 +9729,84 @@ async function verifyFontSubresourceIntegrity(bytes, integrity) {
|
|
|
9690
9729
|
const actualB64 = bytesToBase64Standard(new Uint8Array(digestBuf)).replace(/=+$/, "");
|
|
9691
9730
|
const normExpected = expectedB64.replace(/=+$/, "");
|
|
9692
9731
|
if (actualB64 !== normExpected) {
|
|
9693
|
-
throw new
|
|
9732
|
+
throw new PdfFontCandidateLoadError("integrity", `Font SRI integrity mismatch (${m[1]}).`);
|
|
9733
|
+
}
|
|
9734
|
+
}
|
|
9735
|
+
async function fetchFontBytesWithSri(url, options) {
|
|
9736
|
+
const cacheKey = computeFontUrlCacheKey(url, options?.integrity);
|
|
9737
|
+
const cached = pdfFontUrlByteCache.get(cacheKey);
|
|
9738
|
+
if (cached) {
|
|
9739
|
+
return cached;
|
|
9740
|
+
}
|
|
9741
|
+
const mergedInit = {
|
|
9742
|
+
...options?.fetchInit ?? {},
|
|
9743
|
+
...options?.credentials !== void 0 ? { credentials: options.credentials } : {}
|
|
9744
|
+
};
|
|
9745
|
+
const hasInitKeys = Object.keys(mergedInit).length > 0;
|
|
9746
|
+
let resp;
|
|
9747
|
+
try {
|
|
9748
|
+
resp = hasInitKeys ? await fetch(url, mergedInit) : await fetch(url);
|
|
9749
|
+
} catch (err) {
|
|
9750
|
+
throw new PdfFontCandidateLoadError(
|
|
9751
|
+
"network",
|
|
9752
|
+
`Network error fetching '${url}': ${err?.message || String(err)}`
|
|
9753
|
+
);
|
|
9754
|
+
}
|
|
9755
|
+
if (!resp.ok) {
|
|
9756
|
+
throw new PdfFontCandidateLoadError(
|
|
9757
|
+
"http",
|
|
9758
|
+
`HTTP ${resp.status} fetching '${url}'.`,
|
|
9759
|
+
resp.status
|
|
9760
|
+
);
|
|
9761
|
+
}
|
|
9762
|
+
let ab;
|
|
9763
|
+
try {
|
|
9764
|
+
ab = await resp.arrayBuffer();
|
|
9765
|
+
} catch (err) {
|
|
9766
|
+
throw new PdfFontCandidateLoadError(
|
|
9767
|
+
"network",
|
|
9768
|
+
`Network error reading font body for '${url}': ${err?.message || String(err)}`
|
|
9769
|
+
);
|
|
9694
9770
|
}
|
|
9771
|
+
const rawBytes = new Uint8Array(ab);
|
|
9772
|
+
if (rawBytes.byteLength === 0) {
|
|
9773
|
+
throw new PdfFontCandidateLoadError("empty", `Font response for '${url}' is empty (0 bytes).`);
|
|
9774
|
+
}
|
|
9775
|
+
if (options?.integrity) {
|
|
9776
|
+
await verifyFontSubresourceIntegrity(rawBytes, options.integrity);
|
|
9777
|
+
}
|
|
9778
|
+
try {
|
|
9779
|
+
inspectTrueTypeFont(rawBytes);
|
|
9780
|
+
} catch (err) {
|
|
9781
|
+
throw new PdfFontCandidateLoadError("format", err?.message || String(err));
|
|
9782
|
+
}
|
|
9783
|
+
pdfFontUrlByteCache.set(cacheKey, rawBytes);
|
|
9784
|
+
return rawBytes;
|
|
9695
9785
|
}
|
|
9696
9786
|
async function loadSingleFontCandidate(src) {
|
|
9697
|
-
let rawBytes;
|
|
9698
9787
|
if (src.bytes != null) {
|
|
9699
|
-
rawBytes = src.bytes instanceof Uint8Array ? src.bytes : new Uint8Array(src.bytes);
|
|
9788
|
+
const rawBytes = src.bytes instanceof Uint8Array ? src.bytes : new Uint8Array(src.bytes);
|
|
9789
|
+
if (rawBytes.byteLength === 0) {
|
|
9790
|
+
throw new PdfFontCandidateLoadError("empty", "Font binary is empty (0 bytes).");
|
|
9791
|
+
}
|
|
9700
9792
|
if (src.integrity) {
|
|
9701
9793
|
await verifyFontSubresourceIntegrity(rawBytes, src.integrity);
|
|
9702
9794
|
}
|
|
9703
|
-
|
|
9704
|
-
const cacheKey = `${src.url}|${src.integrity ?? ""}`;
|
|
9705
|
-
const cached = pdfFontUrlByteCache.get(cacheKey);
|
|
9706
|
-
if (cached) {
|
|
9707
|
-
rawBytes = cached;
|
|
9708
|
-
} else {
|
|
9709
|
-
let resp;
|
|
9710
|
-
try {
|
|
9711
|
-
resp = await fetch(src.url);
|
|
9712
|
-
} catch (err) {
|
|
9713
|
-
throw new Error(`Network error fetching '${src.url}': ${err?.message || String(err)}`);
|
|
9714
|
-
}
|
|
9715
|
-
if (!resp.ok) {
|
|
9716
|
-
throw new Error(`HTTP ${resp.status} fetching '${src.url}'.`);
|
|
9717
|
-
}
|
|
9718
|
-
const ab = await resp.arrayBuffer();
|
|
9719
|
-
rawBytes = new Uint8Array(ab);
|
|
9720
|
-
if (src.integrity) {
|
|
9721
|
-
await verifyFontSubresourceIntegrity(rawBytes, src.integrity);
|
|
9722
|
-
}
|
|
9795
|
+
try {
|
|
9723
9796
|
inspectTrueTypeFont(rawBytes);
|
|
9724
|
-
|
|
9725
|
-
|
|
9797
|
+
} catch (err) {
|
|
9798
|
+
throw new PdfFontCandidateLoadError("format", err?.message || String(err));
|
|
9726
9799
|
}
|
|
9727
|
-
|
|
9728
|
-
throw new Error("Font source has neither bytes nor url.");
|
|
9800
|
+
return rawBytes;
|
|
9729
9801
|
}
|
|
9730
|
-
|
|
9731
|
-
|
|
9802
|
+
if (src.url && src.url.trim()) {
|
|
9803
|
+
return fetchFontBytesWithSri(src.url, {
|
|
9804
|
+
integrity: src.integrity,
|
|
9805
|
+
credentials: src.credentials,
|
|
9806
|
+
fetchInit: src.fetchInit
|
|
9807
|
+
});
|
|
9808
|
+
}
|
|
9809
|
+
throw new PdfFontCandidateLoadError("empty", "Font source has neither bytes nor url.");
|
|
9732
9810
|
}
|
|
9733
9811
|
function getByPath(data, path) {
|
|
9734
9812
|
if (!data || !path) return void 0;
|
|
@@ -10111,13 +10189,7 @@ async function resolveRenderFontsForExport(snapshot, effectiveData, options) {
|
|
|
10111
10189
|
normalFontBytes = await loadSingleFontCandidate(f);
|
|
10112
10190
|
break;
|
|
10113
10191
|
} catch (err) {
|
|
10114
|
-
failedFonts.push(
|
|
10115
|
-
index,
|
|
10116
|
-
family: f.family,
|
|
10117
|
-
weight: f.weight,
|
|
10118
|
-
url: f.url,
|
|
10119
|
-
reason: err?.message || String(err)
|
|
10120
|
-
});
|
|
10192
|
+
failedFonts.push(toFailedFontEntry(index, f, err));
|
|
10121
10193
|
}
|
|
10122
10194
|
}
|
|
10123
10195
|
if (!normalFontBytes) requiredWeightsFailed = true;
|
|
@@ -10129,13 +10201,7 @@ async function resolveRenderFontsForExport(snapshot, effectiveData, options) {
|
|
|
10129
10201
|
boldFontBytes = loadedBold;
|
|
10130
10202
|
break;
|
|
10131
10203
|
} catch (err) {
|
|
10132
|
-
failedFonts.push(
|
|
10133
|
-
index,
|
|
10134
|
-
family: f.family,
|
|
10135
|
-
weight: f.weight,
|
|
10136
|
-
url: f.url,
|
|
10137
|
-
reason: err?.message || String(err)
|
|
10138
|
-
});
|
|
10204
|
+
failedFonts.push(toFailedFontEntry(index, f, err));
|
|
10139
10205
|
}
|
|
10140
10206
|
}
|
|
10141
10207
|
if (!normalFontBytes) requiredWeightsFailed = true;
|
|
@@ -10148,13 +10214,7 @@ async function resolveRenderFontsForExport(snapshot, effectiveData, options) {
|
|
|
10148
10214
|
normalFontBytes = await loadSingleFontCandidate(f);
|
|
10149
10215
|
break;
|
|
10150
10216
|
} catch (err) {
|
|
10151
|
-
failedFonts.push(
|
|
10152
|
-
index,
|
|
10153
|
-
family: f.family,
|
|
10154
|
-
weight: f.weight,
|
|
10155
|
-
url: f.url,
|
|
10156
|
-
reason: err?.message || String(err)
|
|
10157
|
-
});
|
|
10217
|
+
failedFonts.push(toFailedFontEntry(index, f, err));
|
|
10158
10218
|
}
|
|
10159
10219
|
}
|
|
10160
10220
|
if (!normalFontBytes) requiredWeightsFailed = true;
|
|
@@ -10165,13 +10225,7 @@ async function resolveRenderFontsForExport(snapshot, effectiveData, options) {
|
|
|
10165
10225
|
boldFontBytes = await loadSingleFontCandidate(f);
|
|
10166
10226
|
break;
|
|
10167
10227
|
} catch (err) {
|
|
10168
|
-
failedFonts.push(
|
|
10169
|
-
index,
|
|
10170
|
-
family: f.family,
|
|
10171
|
-
weight: f.weight,
|
|
10172
|
-
url: f.url,
|
|
10173
|
-
reason: err?.message || String(err)
|
|
10174
|
-
});
|
|
10228
|
+
failedFonts.push(toFailedFontEntry(index, f, err));
|
|
10175
10229
|
}
|
|
10176
10230
|
}
|
|
10177
10231
|
if (!boldFontBytes) requiredWeightsFailed = true;
|
|
@@ -10190,15 +10244,24 @@ async function resolveRenderFontsForExport(snapshot, effectiveData, options) {
|
|
|
10190
10244
|
}
|
|
10191
10245
|
} else {
|
|
10192
10246
|
boldFontBytes = options?.customBoldFontBytes;
|
|
10193
|
-
if (options?.customFontBytes
|
|
10194
|
-
|
|
10195
|
-
inspectTrueTypeFont(options.customFontBytes);
|
|
10196
|
-
normalFontBytes = options.customFontBytes;
|
|
10197
|
-
} catch (err) {
|
|
10247
|
+
if (options?.customFontBytes !== void 0) {
|
|
10248
|
+
if (options.customFontBytes.byteLength === 0) {
|
|
10198
10249
|
failedFonts.push({
|
|
10199
10250
|
index: failedFonts.length,
|
|
10200
|
-
|
|
10251
|
+
kind: "empty",
|
|
10252
|
+
reason: "Font binary is empty (0 bytes)."
|
|
10201
10253
|
});
|
|
10254
|
+
} else {
|
|
10255
|
+
try {
|
|
10256
|
+
inspectTrueTypeFont(options.customFontBytes);
|
|
10257
|
+
normalFontBytes = options.customFontBytes;
|
|
10258
|
+
} catch (err) {
|
|
10259
|
+
failedFonts.push({
|
|
10260
|
+
index: failedFonts.length,
|
|
10261
|
+
kind: "format",
|
|
10262
|
+
reason: err?.message || String(err)
|
|
10263
|
+
});
|
|
10264
|
+
}
|
|
10202
10265
|
}
|
|
10203
10266
|
}
|
|
10204
10267
|
if (!normalFontBytes && snapshot?.resourceBindings) {
|
|
@@ -10208,12 +10271,22 @@ async function resolveRenderFontsForExport(snapshot, effectiveData, options) {
|
|
|
10208
10271
|
if (fontBinding?.dataUri) {
|
|
10209
10272
|
try {
|
|
10210
10273
|
const decoded = dataUriToBytes(fontBinding.dataUri);
|
|
10211
|
-
|
|
10212
|
-
|
|
10274
|
+
if (decoded.byteLength === 0) {
|
|
10275
|
+
failedFonts.push({
|
|
10276
|
+
index: failedFonts.length,
|
|
10277
|
+
...fontBinding.name ? { family: fontBinding.name } : {},
|
|
10278
|
+
kind: "empty",
|
|
10279
|
+
reason: "Font binary is empty (0 bytes)."
|
|
10280
|
+
});
|
|
10281
|
+
} else {
|
|
10282
|
+
inspectTrueTypeFont(decoded);
|
|
10283
|
+
normalFontBytes = decoded;
|
|
10284
|
+
}
|
|
10213
10285
|
} catch (err) {
|
|
10214
10286
|
failedFonts.push({
|
|
10215
10287
|
index: failedFonts.length,
|
|
10216
|
-
family: fontBinding.name,
|
|
10288
|
+
...fontBinding.name ? { family: fontBinding.name } : {},
|
|
10289
|
+
kind: "format",
|
|
10217
10290
|
reason: err?.message || String(err)
|
|
10218
10291
|
});
|
|
10219
10292
|
}
|
|
@@ -12634,6 +12707,12 @@ async function drawPageHeaderAndFooter(pdfDoc, pdfPage, pageWidth, pageHeight, c
|
|
|
12634
12707
|
}
|
|
12635
12708
|
}
|
|
12636
12709
|
async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
12710
|
+
const throwIfExportAborted = () => {
|
|
12711
|
+
if (options?.signal?.aborted) {
|
|
12712
|
+
throw typeof DOMException === "function" ? new DOMException("The operation was aborted.", "AbortError") : Object.assign(new Error("The operation was aborted."), { name: "AbortError" });
|
|
12713
|
+
}
|
|
12714
|
+
};
|
|
12715
|
+
throwIfExportAborted();
|
|
12637
12716
|
const effectiveData = runtimeData ?? snapshot.metadata?.sampleData;
|
|
12638
12717
|
const excludeBasePdf = Boolean(snapshot.metadata?.excludeBasePdfOnExport);
|
|
12639
12718
|
const wmCfg = snapshot.metadata?.watermarkConfig;
|
|
@@ -12649,6 +12728,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
12649
12728
|
);
|
|
12650
12729
|
const optimizeSize = Boolean(options?.optimizeSize);
|
|
12651
12730
|
const preResolvedFonts = await resolveRenderFontsForExport(snapshot, effectiveData, options);
|
|
12731
|
+
throwIfExportAborted();
|
|
12652
12732
|
const pdfDoc = await import_pdf_lib3.PDFDocument.create();
|
|
12653
12733
|
if (snapshot.metadata?.sanitized) {
|
|
12654
12734
|
pdfDoc.setTitle("");
|
|
@@ -14910,7 +14990,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14910
14990
|
if (optimizeSize) {
|
|
14911
14991
|
pruneUnreferencedObjectsAndCompressStreams(pdfDoc);
|
|
14912
14992
|
}
|
|
14993
|
+
throwIfExportAborted();
|
|
14913
14994
|
const savedPdfBytes = interactiveForm && hasAnyAcroWidget ? await pdfDoc.save({ updateFieldAppearances: false }) : await pdfDoc.save();
|
|
14995
|
+
throwIfExportAborted();
|
|
14914
14996
|
if (options?.diagnosticGridOverlay) {
|
|
14915
14997
|
const gridOpts = typeof options.diagnosticGridOverlay === "object" ? options.diagnosticGridOverlay : void 0;
|
|
14916
14998
|
return await overlayDiagnosticGridOnPdfBytes(savedPdfBytes, snapshot, gridOpts);
|
|
@@ -22354,6 +22436,237 @@ function createPdfBrowserFidelitySamples() {
|
|
|
22354
22436
|
s7DefaultNoFont
|
|
22355
22437
|
};
|
|
22356
22438
|
}
|
|
22439
|
+
function stripUndefinedDeep(val) {
|
|
22440
|
+
return JSON.parse(JSON.stringify(val));
|
|
22441
|
+
}
|
|
22442
|
+
function createPdfBrowserFidelityExpectations() {
|
|
22443
|
+
const samples = createPdfBrowserFidelitySamples();
|
|
22444
|
+
const entries = [
|
|
22445
|
+
{
|
|
22446
|
+
id: "S1",
|
|
22447
|
+
sampleKey: "s1ShortCjk",
|
|
22448
|
+
title: samples.s1ShortCjk.name,
|
|
22449
|
+
inputSnapshot: stripUndefinedDeep(samples.s1ShortCjk),
|
|
22450
|
+
renderScenario: {
|
|
22451
|
+
cjkTextMode: "subset-ttf",
|
|
22452
|
+
suppliesSubsetFont: true,
|
|
22453
|
+
omitsRenderOptions: false,
|
|
22454
|
+
description: "subset-ttf vector CJK short text, fullwidth punctuation, and mixed CJK/Latin"
|
|
22455
|
+
},
|
|
22456
|
+
expected: {
|
|
22457
|
+
pageCount: 1,
|
|
22458
|
+
tableRowsPerPage: [],
|
|
22459
|
+
extractableTextSnippetsByPage: [
|
|
22460
|
+
[
|
|
22461
|
+
"Monthly Report \xB7 \u6708\u5EA6\u7ECF\u8425\u7B80\u62A5\uFF082026\uFF09",
|
|
22462
|
+
"Vector Subset Font & ToUnicode Verification Sample",
|
|
22463
|
+
"Report Period:",
|
|
22464
|
+
"\u4E00\u6708\uFF082026Q1\uFF09",
|
|
22465
|
+
"\u534E\u4E1C\xB7\u4E0A\u6D77\u6D66\u4E1C\u5F20\u6C5F\u9AD8\u79D1\u6280\u56ED\u533A",
|
|
22466
|
+
"\u5DF2\u6838\u9A8C\uFF1A\u4E13\u7968\u901A\u8FC7\uFF01\u3010\u6279\u6B21 A-108\u3011",
|
|
22467
|
+
"\u6838\u5FC3\u6A21\u5757 Controller-V2 \u5B8C\u6210\u5EA6 98.5\uFF05\uFF1B\u6B21\u65E5\u8FBE\u6B63\u5E38\uFF0C\u201C\u96F6\u5DEE\u9519\u201D\u4EA4\u4ED8"
|
|
22468
|
+
]
|
|
22469
|
+
],
|
|
22470
|
+
embedsType0SubsetFont: true,
|
|
22471
|
+
usesRasterTextImages: false
|
|
22472
|
+
}
|
|
22473
|
+
},
|
|
22474
|
+
{
|
|
22475
|
+
id: "S2",
|
|
22476
|
+
sampleKey: "s2LongTextBox",
|
|
22477
|
+
title: samples.s2LongTextBox.name,
|
|
22478
|
+
inputSnapshot: stripUndefinedDeep(samples.s2LongTextBox),
|
|
22479
|
+
renderScenario: {
|
|
22480
|
+
cjkTextMode: "subset-ttf",
|
|
22481
|
+
suppliesSubsetFont: true,
|
|
22482
|
+
omitsRenderOptions: false,
|
|
22483
|
+
description: "subset-ttf multi-paragraph wrapping, 3x3 alignment, box clipping, and autoFitFontSize shrink"
|
|
22484
|
+
},
|
|
22485
|
+
expected: {
|
|
22486
|
+
pageCount: 1,
|
|
22487
|
+
tableRowsPerPage: [],
|
|
22488
|
+
extractableTextSnippetsByPage: [
|
|
22489
|
+
[
|
|
22490
|
+
"S2 \u591A\u6BB5\u6DF7\u6392\u957F\u6587\u672C\u6846",
|
|
22491
|
+
"English words wrap cleanly while",
|
|
22492
|
+
"\u5C45\u4E2D\xB7\u5782\u76F4\u5C45\u4E2D\u793A\u4F8B\uFF08Center / Middle\uFF09",
|
|
22493
|
+
"99.2\uFF05",
|
|
22494
|
+
"\u53F3\u5BF9\u9F50\xB7\u5E95\u90E8\u793A\u4F8B\uFF08Right / Bottom\uFF09",
|
|
22495
|
+
"2026-01-31",
|
|
22496
|
+
"\u7F29\u5C0F\u5B57\u53F7\u81EA\u9002\u5E94\u793A\u4F8B\uFF08autoFitFontSize\uFF09",
|
|
22497
|
+
"Batch-2026-Q1"
|
|
22498
|
+
]
|
|
22499
|
+
],
|
|
22500
|
+
embedsType0SubsetFont: true,
|
|
22501
|
+
usesRasterTextImages: false
|
|
22502
|
+
}
|
|
22503
|
+
},
|
|
22504
|
+
{
|
|
22505
|
+
id: "S3",
|
|
22506
|
+
sampleKey: "s3SinglePageTable",
|
|
22507
|
+
title: samples.s3SinglePageTable.name,
|
|
22508
|
+
inputSnapshot: stripUndefinedDeep(samples.s3SinglePageTable),
|
|
22509
|
+
renderScenario: {
|
|
22510
|
+
cjkTextMode: "subset-ttf",
|
|
22511
|
+
suppliesSubsetFont: true,
|
|
22512
|
+
omitsRenderOptions: false,
|
|
22513
|
+
description: "subset-ttf single-page 5-column (1:2:1:1:1) formatted table with zebra stripes"
|
|
22514
|
+
},
|
|
22515
|
+
expected: {
|
|
22516
|
+
pageCount: 1,
|
|
22517
|
+
tableRowsPerPage: [6],
|
|
22518
|
+
extractableTextSnippetsByPage: [
|
|
22519
|
+
[
|
|
22520
|
+
"S3 \u91C7\u8D2D\u51FA\u5E93\u6838\u9A8C\u5355\u9875\u660E\u7EC6\u8868",
|
|
22521
|
+
"\u5546\u54C1\u89C4\u683C\u8BF4\u660E",
|
|
22522
|
+
"A-01",
|
|
22523
|
+
"\u5DE5\u4E1A\u4F20\u611F\u5668\u6A21\u5757\uFF08\u534E\u4E1C\u6807\u51C6\u7248\uFF09",
|
|
22524
|
+
"1,200",
|
|
22525
|
+
"\xA5358.50",
|
|
22526
|
+
"98.5%",
|
|
22527
|
+
"A-06",
|
|
22528
|
+
"\xA52,150.40",
|
|
22529
|
+
"95.0%"
|
|
22530
|
+
]
|
|
22531
|
+
],
|
|
22532
|
+
embedsType0SubsetFont: true,
|
|
22533
|
+
usesRasterTextImages: false
|
|
22534
|
+
}
|
|
22535
|
+
},
|
|
22536
|
+
{
|
|
22537
|
+
id: "S4",
|
|
22538
|
+
sampleKey: "s4CellOverflow",
|
|
22539
|
+
title: samples.s4CellOverflow.name,
|
|
22540
|
+
inputSnapshot: stripUndefinedDeep(samples.s4CellOverflow),
|
|
22541
|
+
renderScenario: {
|
|
22542
|
+
cjkTextMode: "subset-ttf",
|
|
22543
|
+
suppliesSubsetFont: true,
|
|
22544
|
+
omitsRenderOptions: false,
|
|
22545
|
+
description: "subset-ttf narrow-column cell overflow clipping and table autoFitFontSize"
|
|
22546
|
+
},
|
|
22547
|
+
expected: {
|
|
22548
|
+
pageCount: 1,
|
|
22549
|
+
tableRowsPerPage: [2],
|
|
22550
|
+
extractableTextSnippetsByPage: [
|
|
22551
|
+
[
|
|
22552
|
+
"S4-A \u9ED8\u8BA4\u56FA\u5B9A\u884C\u9AD8\uFF0824pt\uFF09\u7A84\u5217\u6EA2\u51FA\u4E25\u683C\u88C1\u5207",
|
|
22553
|
+
"\u7A84\u5217\u957F\u4E2D\u6587",
|
|
22554
|
+
"\u7A84\u5217\u8D85\u957F\u897F\u6587",
|
|
22555
|
+
"\u6B63\u5E38\u90BB\u683C A1",
|
|
22556
|
+
"\u6B63\u5E38\u90BB\u683C A2",
|
|
22557
|
+
"S4-B \u5F00\u542F\u8868\u683C\u5355\u5143\u683C\u7F29\u5C0F\u5B57\u53F7"
|
|
22558
|
+
]
|
|
22559
|
+
],
|
|
22560
|
+
embedsType0SubsetFont: true,
|
|
22561
|
+
usesRasterTextImages: false
|
|
22562
|
+
}
|
|
22563
|
+
},
|
|
22564
|
+
{
|
|
22565
|
+
id: "S5",
|
|
22566
|
+
sampleKey: "s5MultiPageTable",
|
|
22567
|
+
title: samples.s5MultiPageTable.name,
|
|
22568
|
+
inputSnapshot: stripUndefinedDeep(samples.s5MultiPageTable),
|
|
22569
|
+
renderScenario: {
|
|
22570
|
+
cjkTextMode: "subset-ttf",
|
|
22571
|
+
suppliesSubsetFont: true,
|
|
22572
|
+
omitsRenderOptions: false,
|
|
22573
|
+
description: "subset-ttf 35-row multi-page table (14 + 14 + 7) with repeated headers and trailing footer flow"
|
|
22574
|
+
},
|
|
22575
|
+
expected: {
|
|
22576
|
+
pageCount: 3,
|
|
22577
|
+
tableRowsPerPage: [14, 14, 7],
|
|
22578
|
+
extractableTextSnippetsByPage: [
|
|
22579
|
+
[
|
|
22580
|
+
"S5 \u591A\u9875\u51FA\u5165\u5E93\u6838\u9A8C\u660E\u7EC6\u8868",
|
|
22581
|
+
"\u5355\u636E\u72B6\u6001\uFF1A\u5DF2\u6838\u9A8C",
|
|
22582
|
+
"\u8BA2\u5355\u7F16\u53F7",
|
|
22583
|
+
"R-01",
|
|
22584
|
+
"\u534E\u4E1C\u4E0A\u6D77\u56ED\u533A\xB7\u5DE5\u4E1A\u4F20\u611F\u5668\u6A21\u5757",
|
|
22585
|
+
"\xA5125.50",
|
|
22586
|
+
"R-14",
|
|
22587
|
+
"\xA51,757.00"
|
|
22588
|
+
],
|
|
22589
|
+
[
|
|
22590
|
+
"\u8BA2\u5355\u7F16\u53F7",
|
|
22591
|
+
"R-15",
|
|
22592
|
+
"\xA51,882.50",
|
|
22593
|
+
"R-28",
|
|
22594
|
+
"\xA53,514.00"
|
|
22595
|
+
],
|
|
22596
|
+
[
|
|
22597
|
+
"\u8BA2\u5355\u7F16\u53F7",
|
|
22598
|
+
"R-29",
|
|
22599
|
+
"\xA53,639.50",
|
|
22600
|
+
"R-35",
|
|
22601
|
+
"\xA54,392.50",
|
|
22602
|
+
"\u8868\u540E\u7B7E\u6536\u680F\uFF1A\u5BA1\u6279\u4EBA \u5F20\u5DE5 \uFF5C \u8D22\u52A1\u4E13\u7528\u7AE0 \uFF5C \u4ED3\u5E93\u7B7E\u7AE0"
|
|
22603
|
+
]
|
|
22604
|
+
],
|
|
22605
|
+
embedsType0SubsetFont: true,
|
|
22606
|
+
usesRasterTextImages: false
|
|
22607
|
+
}
|
|
22608
|
+
},
|
|
22609
|
+
{
|
|
22610
|
+
id: "S6",
|
|
22611
|
+
sampleKey: "s6MissingGlyphs",
|
|
22612
|
+
title: samples.s6MissingGlyphs.name,
|
|
22613
|
+
inputSnapshot: stripUndefinedDeep(samples.s6MissingGlyphs),
|
|
22614
|
+
renderScenario: {
|
|
22615
|
+
cjkTextMode: "subset-ttf",
|
|
22616
|
+
suppliesSubsetFont: true,
|
|
22617
|
+
omitsRenderOptions: false,
|
|
22618
|
+
missingGlyph: "warn",
|
|
22619
|
+
description: "subset-ttf missing-glyph diagnostics ('error' throws MISSING_GLYPH; 'warn' emits warning and renders)"
|
|
22620
|
+
},
|
|
22621
|
+
expected: {
|
|
22622
|
+
pageCount: 1,
|
|
22623
|
+
tableRowsPerPage: [],
|
|
22624
|
+
extractableTextSnippetsByPage: [
|
|
22625
|
+
[
|
|
22626
|
+
"Monthly Report \xB7 \u6708\u5EA6\u7ECF\u8425\u7B80\u62A5\uFF082026\uFF09",
|
|
22627
|
+
"\u4E00\u6708\uFF082026Q1\uFF09",
|
|
22628
|
+
"\u7F3A\u5B57\u8BCA\u65AD\u5907\u6CE8\uFF1A\u751F\u50FB\u5B57",
|
|
22629
|
+
"\u4E0E\u56FE\u6807",
|
|
22630
|
+
"\u6838\u9A8C"
|
|
22631
|
+
]
|
|
22632
|
+
],
|
|
22633
|
+
embedsType0SubsetFont: true,
|
|
22634
|
+
usesRasterTextImages: false,
|
|
22635
|
+
expectedErrorWhenStrict: {
|
|
22636
|
+
code: "MISSING_GLYPH",
|
|
22637
|
+
pageId: "page-1",
|
|
22638
|
+
elementId: "s6-missing-note",
|
|
22639
|
+
missingCodePoints: ["U+9F98", "U+1F680"]
|
|
22640
|
+
}
|
|
22641
|
+
}
|
|
22642
|
+
},
|
|
22643
|
+
{
|
|
22644
|
+
id: "S7",
|
|
22645
|
+
sampleKey: "s7DefaultNoFont",
|
|
22646
|
+
title: samples.s7DefaultNoFont.name,
|
|
22647
|
+
inputSnapshot: stripUndefinedDeep(samples.s7DefaultNoFont),
|
|
22648
|
+
renderScenario: {
|
|
22649
|
+
cjkTextMode: "raster-hd",
|
|
22650
|
+
suppliesSubsetFont: false,
|
|
22651
|
+
omitsRenderOptions: true,
|
|
22652
|
+
description: "default omitted render options preserving raster-hd compatibility without fonts"
|
|
22653
|
+
},
|
|
22654
|
+
expected: {
|
|
22655
|
+
pageCount: 1,
|
|
22656
|
+
tableRowsPerPage: [],
|
|
22657
|
+
extractableTextSnippetsByPage: [],
|
|
22658
|
+
embedsType0SubsetFont: false,
|
|
22659
|
+
usesRasterTextImages: true
|
|
22660
|
+
}
|
|
22661
|
+
}
|
|
22662
|
+
];
|
|
22663
|
+
return {
|
|
22664
|
+
schema: "univer-pdf-fidelity-expectations",
|
|
22665
|
+
version: 1,
|
|
22666
|
+
samples: entries
|
|
22667
|
+
};
|
|
22668
|
+
}
|
|
22669
|
+
var PDF_S1_S7_FIDELITY_EXPECTATIONS = Object.freeze(createPdfBrowserFidelityExpectations());
|
|
22357
22670
|
|
|
22358
22671
|
// src/jsx/types.ts
|
|
22359
22672
|
var PDF_JSX_ELEMENT_SYMBOL = /* @__PURE__ */ Symbol.for("univer.pdfs.jsx.element");
|
|
@@ -24006,7 +24319,51 @@ function detectImportFileFormat(file) {
|
|
|
24006
24319
|
}
|
|
24007
24320
|
return "pdf";
|
|
24008
24321
|
}
|
|
24009
|
-
function
|
|
24322
|
+
function createPdfAbortError(signal) {
|
|
24323
|
+
const reason = signal?.reason;
|
|
24324
|
+
if (reason && typeof reason === "object" && reason.name === "AbortError") {
|
|
24325
|
+
return reason;
|
|
24326
|
+
}
|
|
24327
|
+
return typeof DOMException === "function" ? new DOMException("The operation was aborted.", "AbortError") : Object.assign(new Error("The operation was aborted."), { name: "AbortError" });
|
|
24328
|
+
}
|
|
24329
|
+
function isAbortErrorLike(err) {
|
|
24330
|
+
return Boolean(err && typeof err === "object" && err.name === "AbortError");
|
|
24331
|
+
}
|
|
24332
|
+
function throwIfSignalAborted(signal) {
|
|
24333
|
+
if (signal?.aborted) {
|
|
24334
|
+
throw createPdfAbortError(signal);
|
|
24335
|
+
}
|
|
24336
|
+
}
|
|
24337
|
+
async function raceWithAbortSignal(promise, signal) {
|
|
24338
|
+
throwIfSignalAborted(signal);
|
|
24339
|
+
if (!signal) {
|
|
24340
|
+
return promise;
|
|
24341
|
+
}
|
|
24342
|
+
let onAbort = null;
|
|
24343
|
+
const abortPromise = new Promise((_, reject) => {
|
|
24344
|
+
if (signal.aborted) {
|
|
24345
|
+
reject(createPdfAbortError(signal));
|
|
24346
|
+
return;
|
|
24347
|
+
}
|
|
24348
|
+
onAbort = () => reject(createPdfAbortError(signal));
|
|
24349
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
24350
|
+
});
|
|
24351
|
+
void promise.catch(() => {
|
|
24352
|
+
});
|
|
24353
|
+
try {
|
|
24354
|
+
const result = await Promise.race([promise, abortPromise]);
|
|
24355
|
+
throwIfSignalAborted(signal);
|
|
24356
|
+
return result;
|
|
24357
|
+
} finally {
|
|
24358
|
+
if (onAbort) {
|
|
24359
|
+
signal.removeEventListener("abort", onAbort);
|
|
24360
|
+
}
|
|
24361
|
+
}
|
|
24362
|
+
}
|
|
24363
|
+
function attachSuggestedFallbackAndThrow(err, fallback, signal) {
|
|
24364
|
+
if (signal?.aborted || isAbortErrorLike(err)) {
|
|
24365
|
+
throw isAbortErrorLike(err) ? err : createPdfAbortError(signal);
|
|
24366
|
+
}
|
|
24010
24367
|
if (err && typeof err === "object") {
|
|
24011
24368
|
if (!err.suggestedFallback) {
|
|
24012
24369
|
try {
|
|
@@ -24021,6 +24378,7 @@ function attachSuggestedFallbackAndThrow(err, fallback) {
|
|
|
24021
24378
|
throw wrapped;
|
|
24022
24379
|
}
|
|
24023
24380
|
async function importPdfSource(source, options) {
|
|
24381
|
+
throwIfSignalAborted(options?.signal);
|
|
24024
24382
|
let bytes;
|
|
24025
24383
|
let fileName = options?.fileName || "imported.pdf";
|
|
24026
24384
|
if (source instanceof Uint8Array) {
|
|
@@ -24052,7 +24410,7 @@ async function importPdfSource(source, options) {
|
|
|
24052
24410
|
if ("name" in source && typeof source.name === "string" && source.name) {
|
|
24053
24411
|
fileName = options?.fileName || source.name;
|
|
24054
24412
|
}
|
|
24055
|
-
const ab = await source.arrayBuffer();
|
|
24413
|
+
const ab = await raceWithAbortSignal(source.arrayBuffer(), options?.signal);
|
|
24056
24414
|
bytes = new Uint8Array(ab);
|
|
24057
24415
|
} else {
|
|
24058
24416
|
throw new PdfImportError("INVALID_PDF_HEADER", "Unsupported PDF input source.");
|
|
@@ -24063,7 +24421,9 @@ async function importPdfSource(source, options) {
|
|
|
24063
24421
|
"Invalid PDF binary: missing %PDF- header signature."
|
|
24064
24422
|
);
|
|
24065
24423
|
}
|
|
24424
|
+
throwIfSignalAborted(options?.signal);
|
|
24066
24425
|
const { PDFArray: PDFArray6, PDFDict: PDFDict6, PDFDocument: PDFDocument6, PDFName: PDFName6 } = await import("pdf-lib");
|
|
24426
|
+
throwIfSignalAborted(options?.signal);
|
|
24067
24427
|
let pageSizes = [];
|
|
24068
24428
|
let warnings = [];
|
|
24069
24429
|
try {
|
|
@@ -24163,6 +24523,7 @@ async function importPdfSource(source, options) {
|
|
|
24163
24523
|
throw new PdfImportError("CORRUPT_PDF", `Corrupt PDF binary: ${errMsg}`);
|
|
24164
24524
|
}
|
|
24165
24525
|
}
|
|
24526
|
+
throwIfSignalAborted(options?.signal);
|
|
24166
24527
|
const b64 = uint8ToBase64(bytes);
|
|
24167
24528
|
const dataUri = `data:application/pdf;base64,${b64}`;
|
|
24168
24529
|
return {
|
|
@@ -24179,9 +24540,11 @@ async function importPdfSource(source, options) {
|
|
|
24179
24540
|
warnings
|
|
24180
24541
|
};
|
|
24181
24542
|
}
|
|
24182
|
-
async function fallbackReadFileAsOutcome(file, baseSnapshot, password) {
|
|
24543
|
+
async function fallbackReadFileAsOutcome(file, baseSnapshot, password, signal, explicitFileName) {
|
|
24544
|
+
throwIfSignalAborted(signal);
|
|
24183
24545
|
if (detectImportFileFormat(file) === "json") {
|
|
24184
|
-
const rawText = typeof file.text === "function" ? await file.text() : new TextDecoder().decode(await file.arrayBuffer());
|
|
24546
|
+
const rawText = typeof file.text === "function" ? await raceWithAbortSignal(file.text(), signal) : new TextDecoder().decode(await raceWithAbortSignal(file.arrayBuffer(), signal));
|
|
24547
|
+
throwIfSignalAborted(signal);
|
|
24185
24548
|
let parsed;
|
|
24186
24549
|
try {
|
|
24187
24550
|
parsed = JSON.parse(rawText);
|
|
@@ -24205,7 +24568,10 @@ async function fallbackReadFileAsOutcome(file, baseSnapshot, password) {
|
|
|
24205
24568
|
mode: "snapshot",
|
|
24206
24569
|
snapshot: fromPdfmeTemplate(parsed, {
|
|
24207
24570
|
id: baseSnapshot.id,
|
|
24208
|
-
name: (file.name || baseSnapshot.name || "Imported Template").replace(
|
|
24571
|
+
name: (explicitFileName || file.name || baseSnapshot.name || "Imported Template").replace(
|
|
24572
|
+
/\.json$/i,
|
|
24573
|
+
""
|
|
24574
|
+
)
|
|
24209
24575
|
})
|
|
24210
24576
|
};
|
|
24211
24577
|
}
|
|
@@ -24214,7 +24580,11 @@ async function fallbackReadFileAsOutcome(file, baseSnapshot, password) {
|
|
|
24214
24580
|
"\u672A\u8BC6\u522B\u7684 JSON \u6A21\u677F\u683C\u5F0F\uFF1A\u8BF7\u63D0\u4F9B\u6807\u51C6 IPdfUnitData \u6216 pdfme Template JSON\u3002"
|
|
24215
24581
|
);
|
|
24216
24582
|
}
|
|
24217
|
-
const imported = await importPdfSource(file, {
|
|
24583
|
+
const imported = await importPdfSource(file, {
|
|
24584
|
+
fileName: explicitFileName || file.name || "imported.pdf",
|
|
24585
|
+
password,
|
|
24586
|
+
signal
|
|
24587
|
+
});
|
|
24218
24588
|
return {
|
|
24219
24589
|
mode: "overlay",
|
|
24220
24590
|
sourceDocumentRef: imported.sourceDocumentRef,
|
|
@@ -24444,6 +24814,8 @@ var PdfIoService = class extends import_core11.Disposable {
|
|
|
24444
24814
|
return report.outcome;
|
|
24445
24815
|
}
|
|
24446
24816
|
async importPdfWithReport(file, context) {
|
|
24817
|
+
const signal = context?.signal;
|
|
24818
|
+
throwIfSignalAborted(signal);
|
|
24447
24819
|
const { unitId, baseSnapshot } = this._resolveBaseSnapshotForImport(context);
|
|
24448
24820
|
const adapter = this._adapter$.getValue();
|
|
24449
24821
|
const caps = this.getIoCapabilities();
|
|
@@ -24452,11 +24824,12 @@ var PdfIoService = class extends import_core11.Disposable {
|
|
|
24452
24824
|
const requested = context?.target ?? this.getDefaultIoTarget();
|
|
24453
24825
|
const effective = requested === "auto" ? fmtCap.defaultTarget : requested;
|
|
24454
24826
|
const defaultImport = async (f) => {
|
|
24827
|
+
throwIfSignalAborted(signal);
|
|
24455
24828
|
if (context?.defaultImport) {
|
|
24456
|
-
const customRaw = await context.defaultImport(f);
|
|
24829
|
+
const customRaw = await raceWithAbortSignal(context.defaultImport(f), signal);
|
|
24457
24830
|
return normalizeAdapterImportResult(customRaw).outcome;
|
|
24458
24831
|
}
|
|
24459
|
-
return fallbackReadFileAsOutcome(f, baseSnapshot, context?.password);
|
|
24832
|
+
return fallbackReadFileAsOutcome(f, baseSnapshot, context?.password, signal, context?.fileName);
|
|
24460
24833
|
};
|
|
24461
24834
|
let rawResult;
|
|
24462
24835
|
if (effective === "server") {
|
|
@@ -24466,49 +24839,85 @@ var PdfIoService = class extends import_core11.Disposable {
|
|
|
24466
24839
|
);
|
|
24467
24840
|
}
|
|
24468
24841
|
try {
|
|
24469
|
-
rawResult = await
|
|
24470
|
-
|
|
24471
|
-
|
|
24472
|
-
|
|
24473
|
-
|
|
24842
|
+
rawResult = await raceWithAbortSignal(
|
|
24843
|
+
adapter.importPdf(file, {
|
|
24844
|
+
unitId,
|
|
24845
|
+
snapshot: import_core11.Tools.deepClone(baseSnapshot),
|
|
24846
|
+
...signal ? { signal } : {},
|
|
24847
|
+
defaultImport
|
|
24848
|
+
}),
|
|
24849
|
+
signal
|
|
24850
|
+
);
|
|
24474
24851
|
} catch (err) {
|
|
24475
|
-
attachSuggestedFallbackAndThrow(err, "browser");
|
|
24852
|
+
attachSuggestedFallbackAndThrow(err, "browser", signal);
|
|
24476
24853
|
}
|
|
24477
24854
|
} else {
|
|
24478
24855
|
if (!context?.defaultImport && !fmtCap.browser) {
|
|
24479
24856
|
attachSuggestedFallbackAndThrow(
|
|
24480
24857
|
new Error(`\u5F53\u524D\u6D4F\u89C8\u5668\u7AEF\u672A\u542F\u7528 .${fmt} \u683C\u5F0F\u5BFC\u5165\uFF1B\u8BF7\u5207\u6362\u4E3A\u300C\u670D\u52A1\u7AEF\u5904\u7406\u300D\u91CD\u8BD5`),
|
|
24481
|
-
"server"
|
|
24858
|
+
"server",
|
|
24859
|
+
signal
|
|
24482
24860
|
);
|
|
24483
24861
|
}
|
|
24484
24862
|
try {
|
|
24485
|
-
rawResult = context?.defaultImport ? await context.defaultImport(file) : await fallbackReadFileAsOutcome(
|
|
24863
|
+
rawResult = context?.defaultImport ? await raceWithAbortSignal(context.defaultImport(file), signal) : await fallbackReadFileAsOutcome(
|
|
24864
|
+
file,
|
|
24865
|
+
baseSnapshot,
|
|
24866
|
+
context?.password,
|
|
24867
|
+
signal,
|
|
24868
|
+
context?.fileName
|
|
24869
|
+
);
|
|
24486
24870
|
} catch (err) {
|
|
24487
|
-
attachSuggestedFallbackAndThrow(err, "server");
|
|
24871
|
+
attachSuggestedFallbackAndThrow(err, "server", signal);
|
|
24488
24872
|
}
|
|
24489
24873
|
}
|
|
24874
|
+
throwIfSignalAborted(signal);
|
|
24490
24875
|
const { outcome, warnings } = normalizeAdapterImportResult(rawResult);
|
|
24491
24876
|
const candidateSnapshot = outcome.mode === "snapshot" ? import_core11.Tools.deepClone(outcome.snapshot) : buildOverlayImportCandidateSnapshot(baseSnapshot, outcome);
|
|
24877
|
+
throwIfSignalAborted(signal);
|
|
24492
24878
|
return {
|
|
24493
24879
|
snapshot: candidateSnapshot,
|
|
24494
24880
|
outcome,
|
|
24495
24881
|
warnings,
|
|
24496
24882
|
executedBy: effective,
|
|
24497
|
-
fileName: file?.name || (outcome.mode === "overlay" ? outcome.sourceDocumentRef.fileName : candidateSnapshot.name) || void 0
|
|
24883
|
+
fileName: context?.fileName || file?.name || (outcome.mode === "overlay" ? outcome.sourceDocumentRef.fileName : candidateSnapshot.name) || void 0
|
|
24498
24884
|
};
|
|
24499
24885
|
}
|
|
24886
|
+
async exportPdfWithTarget(params) {
|
|
24887
|
+
const signal = params.signal ?? params.options?.signal;
|
|
24888
|
+
throwIfSignalAborted(signal);
|
|
24889
|
+
const { unitId, baseSnapshot } = this._resolveBaseSnapshotForImport({
|
|
24890
|
+
unitId: params.unitId,
|
|
24891
|
+
snapshot: params.snapshot
|
|
24892
|
+
});
|
|
24893
|
+
return this.exportPdf({
|
|
24894
|
+
unitId,
|
|
24895
|
+
snapshot: params.snapshot ?? baseSnapshot,
|
|
24896
|
+
data: params.data,
|
|
24897
|
+
options: params.options,
|
|
24898
|
+
target: params.target,
|
|
24899
|
+
signal
|
|
24900
|
+
});
|
|
24901
|
+
}
|
|
24500
24902
|
async exportPdf(params) {
|
|
24903
|
+
const signal = params.signal ?? params.options?.signal;
|
|
24904
|
+
throwIfSignalAborted(signal);
|
|
24905
|
+
const effectiveOptions = signal ? { ...params.options ?? {}, signal } : params.options;
|
|
24501
24906
|
const beforeEvent = {
|
|
24502
24907
|
unitId: params.unitId,
|
|
24503
24908
|
snapshot: params.snapshot,
|
|
24504
24909
|
data: params.data,
|
|
24505
|
-
options:
|
|
24910
|
+
options: effectiveOptions,
|
|
24506
24911
|
cancel: false
|
|
24507
24912
|
};
|
|
24508
24913
|
if (this.runBeforeExportHooks(beforeEvent)) {
|
|
24509
24914
|
throw new import_core11.CanceledError();
|
|
24510
24915
|
}
|
|
24511
|
-
|
|
24916
|
+
throwIfSignalAborted(signal);
|
|
24917
|
+
const defaultExport = () => raceWithAbortSignal(
|
|
24918
|
+
exportPdfBytes(params.snapshot, params.data, effectiveOptions),
|
|
24919
|
+
signal
|
|
24920
|
+
);
|
|
24512
24921
|
const adapter = this._adapter$.getValue();
|
|
24513
24922
|
const caps = this.getIoCapabilities();
|
|
24514
24923
|
const pdfExportCap = caps.formats.export.pdf;
|
|
@@ -24522,17 +24931,22 @@ var PdfIoService = class extends import_core11.Disposable {
|
|
|
24522
24931
|
}
|
|
24523
24932
|
let bytes;
|
|
24524
24933
|
try {
|
|
24525
|
-
const raw = await
|
|
24526
|
-
|
|
24527
|
-
|
|
24528
|
-
|
|
24529
|
-
|
|
24530
|
-
|
|
24531
|
-
|
|
24532
|
-
|
|
24934
|
+
const raw = await raceWithAbortSignal(
|
|
24935
|
+
adapter.exportPdf({
|
|
24936
|
+
unitId: params.unitId,
|
|
24937
|
+
snapshot: params.snapshot,
|
|
24938
|
+
data: params.data,
|
|
24939
|
+
options: effectiveOptions,
|
|
24940
|
+
...signal ? { signal } : {},
|
|
24941
|
+
defaultExport
|
|
24942
|
+
}),
|
|
24943
|
+
signal
|
|
24944
|
+
);
|
|
24945
|
+
bytes = await raceWithAbortSignal(normalizeBinaryToUint8Array(raw), signal);
|
|
24533
24946
|
} catch (err) {
|
|
24534
|
-
attachSuggestedFallbackAndThrow(err, "browser");
|
|
24947
|
+
attachSuggestedFallbackAndThrow(err, "browser", signal);
|
|
24535
24948
|
}
|
|
24949
|
+
throwIfSignalAborted(signal);
|
|
24536
24950
|
this.notifyExported({
|
|
24537
24951
|
unitId: params.unitId,
|
|
24538
24952
|
bytes,
|
|
@@ -24544,11 +24958,13 @@ var PdfIoService = class extends import_core11.Disposable {
|
|
|
24544
24958
|
if (!pdfExportCap.browser) {
|
|
24545
24959
|
attachSuggestedFallbackAndThrow(
|
|
24546
24960
|
new Error("\u5F53\u524D\u6D4F\u89C8\u5668\u7AEF\u672A\u542F\u7528 PDF \u5BFC\u51FA\uFF1B\u8BF7\u5207\u6362\u4E3A\u300C\u670D\u52A1\u7AEF\u5904\u7406\u300D\u91CD\u8BD5"),
|
|
24547
|
-
"server"
|
|
24961
|
+
"server",
|
|
24962
|
+
signal
|
|
24548
24963
|
);
|
|
24549
24964
|
}
|
|
24550
24965
|
try {
|
|
24551
24966
|
const bytes = await defaultExport();
|
|
24967
|
+
throwIfSignalAborted(signal);
|
|
24552
24968
|
this.notifyExported({
|
|
24553
24969
|
unitId: params.unitId,
|
|
24554
24970
|
bytes,
|
|
@@ -24557,7 +24973,7 @@ var PdfIoService = class extends import_core11.Disposable {
|
|
|
24557
24973
|
});
|
|
24558
24974
|
return bytes;
|
|
24559
24975
|
} catch (err) {
|
|
24560
|
-
attachSuggestedFallbackAndThrow(err, "server");
|
|
24976
|
+
attachSuggestedFallbackAndThrow(err, "server", signal);
|
|
24561
24977
|
}
|
|
24562
24978
|
}
|
|
24563
24979
|
async silentPrint(params) {
|
|
@@ -24613,6 +25029,42 @@ var PdfIoService = class extends import_core11.Disposable {
|
|
|
24613
25029
|
PdfIoService = __decorateClass([
|
|
24614
25030
|
__decorateParam(0, (0, import_core11.Optional)(import_core11.IUniverInstanceService))
|
|
24615
25031
|
], PdfIoService);
|
|
25032
|
+
async function exportPdfWithTarget(arg1, arg2) {
|
|
25033
|
+
if (arg1 && typeof arg1.exportPdfWithTarget === "function") {
|
|
25034
|
+
return arg1.exportPdfWithTarget(arg2 ?? {});
|
|
25035
|
+
}
|
|
25036
|
+
if (arg1 && typeof arg1 === "object" && "document" in arg1 && "editState" in arg1) {
|
|
25037
|
+
const snap = arg1;
|
|
25038
|
+
const extIo = arg2?.ioService;
|
|
25039
|
+
if (extIo) {
|
|
25040
|
+
return extIo.exportPdfWithTarget({
|
|
25041
|
+
...arg2,
|
|
25042
|
+
unitId: arg2?.unitId ?? snap.id,
|
|
25043
|
+
snapshot: snap
|
|
25044
|
+
});
|
|
25045
|
+
}
|
|
25046
|
+
const localIo2 = new PdfIoService();
|
|
25047
|
+
try {
|
|
25048
|
+
return await localIo2.exportPdfWithTarget({
|
|
25049
|
+
...arg2,
|
|
25050
|
+
unitId: arg2?.unitId ?? snap.id,
|
|
25051
|
+
snapshot: snap
|
|
25052
|
+
});
|
|
25053
|
+
} finally {
|
|
25054
|
+
localIo2.dispose();
|
|
25055
|
+
}
|
|
25056
|
+
}
|
|
25057
|
+
const unified = arg1;
|
|
25058
|
+
if (unified.ioService) {
|
|
25059
|
+
return unified.ioService.exportPdfWithTarget(unified);
|
|
25060
|
+
}
|
|
25061
|
+
const localIo = new PdfIoService();
|
|
25062
|
+
try {
|
|
25063
|
+
return await localIo.exportPdfWithTarget(unified);
|
|
25064
|
+
} finally {
|
|
25065
|
+
localIo.dispose();
|
|
25066
|
+
}
|
|
25067
|
+
}
|
|
24616
25068
|
|
|
24617
25069
|
// src/plugin.ts
|
|
24618
25070
|
var UNIVER_PDFS_PLUGIN_NAME = "UNIVER_PDFS_PLUGIN";
|
|
@@ -24754,6 +25206,7 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
24754
25206
|
PDF_JSX_ELEMENT_SYMBOL,
|
|
24755
25207
|
PDF_JSX_FRAGMENT_SYMBOL,
|
|
24756
25208
|
PDF_PAGE_PRESETS,
|
|
25209
|
+
PDF_S1_S7_FIDELITY_EXPECTATIONS,
|
|
24757
25210
|
PDF_TABLE_THEME_PRESETS,
|
|
24758
25211
|
PT_PER_MM,
|
|
24759
25212
|
Page,
|
|
@@ -24836,6 +25289,7 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
24836
25289
|
computeExifTransformMatrix,
|
|
24837
25290
|
computeExpandedTextHeightMm,
|
|
24838
25291
|
computeExpandedTextHeightPt,
|
|
25292
|
+
computeFontUrlCacheKey,
|
|
24839
25293
|
computeImageFitPlacement,
|
|
24840
25294
|
computePasteCascadeOffset,
|
|
24841
25295
|
computePdfPayloadDigest,
|
|
@@ -24852,6 +25306,8 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
24852
25306
|
createDefaultElement,
|
|
24853
25307
|
createDefaultPdfUnitData,
|
|
24854
25308
|
createHttpSilentPrintAdapter,
|
|
25309
|
+
createPdfAbortError,
|
|
25310
|
+
createPdfBrowserFidelityExpectations,
|
|
24855
25311
|
createPdfBrowserFidelitySamples,
|
|
24856
25312
|
createPdfCjkFontSources,
|
|
24857
25313
|
createPdfJsxNode,
|
|
@@ -24889,6 +25345,7 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
24889
25345
|
exportPdfBytes,
|
|
24890
25346
|
exportPdfToDocxSnapshot,
|
|
24891
25347
|
exportPdfToWorkbookSnapshot,
|
|
25348
|
+
exportPdfWithTarget,
|
|
24892
25349
|
exportSignedPdfWithAuditSeal,
|
|
24893
25350
|
exportToPdfmeTemplate,
|
|
24894
25351
|
extractAcroFormValuesFromPdfBytes,
|