@yudaocode/univer-pdfs 1.6.216 → 1.6.218
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/lib/cjs/facade/index.js +2 -1
- package/lib/cjs/facade/index.js.map +1 -1
- package/lib/cjs/index.js +1986 -549
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/jsx/index.js +1346 -338
- package/lib/cjs/jsx/index.js.map +1 -1
- package/lib/es/{chunk-EMSHTYYU.js → chunk-SUXA7HBV.js} +1271 -192
- package/lib/es/chunk-SUXA7HBV.js.map +1 -0
- package/lib/es/facade/index.js +2 -1
- package/lib/es/facade/index.js.map +1 -1
- package/lib/es/index.js +453 -57
- package/lib/es/index.js.map +1 -1
- package/lib/es/jsx/index.js +1 -1
- package/lib/types/index.d.ts +152 -3
- 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-Dm72R_Vm.d.ts → jsx-dev-runtime-DsfnOIFS.d.ts} +37 -1
- package/package.json +1 -1
- package/lib/es/chunk-EMSHTYYU.js.map +0 -1
package/lib/es/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
MultiVariableText,
|
|
20
20
|
PAGE_SIZE_PRESETS_MM,
|
|
21
21
|
PDF_PAGE_PRESETS,
|
|
22
|
+
PDF_PASSWORD_PADDING,
|
|
22
23
|
PDF_TABLE_THEME_PRESETS,
|
|
23
24
|
PT_PER_MM,
|
|
24
25
|
Page,
|
|
@@ -29,6 +30,7 @@ import {
|
|
|
29
30
|
PdfListKind,
|
|
30
31
|
PdfListPresetId,
|
|
31
32
|
PdfRenderError,
|
|
33
|
+
PdfSecurityError,
|
|
32
34
|
PdfTableBorderStyle,
|
|
33
35
|
PdfTableCellVerticalAlign,
|
|
34
36
|
PdfTextAnchor,
|
|
@@ -44,7 +46,10 @@ import {
|
|
|
44
46
|
Text,
|
|
45
47
|
UNIVER_PDF_SCHEMA,
|
|
46
48
|
UNIVER_PDF_SCHEMA_VERSION,
|
|
49
|
+
applyPdfSecurityToDocument,
|
|
47
50
|
buildMinimalTestTrueTypeFont,
|
|
51
|
+
buildObjectEncryptionKey,
|
|
52
|
+
bytesToHex,
|
|
48
53
|
calculatePdfTableRowCapacity,
|
|
49
54
|
clearPdfFontUrlCache,
|
|
50
55
|
cmykToRgb,
|
|
@@ -60,13 +65,18 @@ import {
|
|
|
60
65
|
computeExifTransformMatrix,
|
|
61
66
|
computeExpandedTextHeightMm,
|
|
62
67
|
computeExpandedTextHeightPt,
|
|
68
|
+
computeFileEncryptionKeyFromPadded,
|
|
63
69
|
computeFontUrlCacheKey,
|
|
64
70
|
computeImageFitPlacement,
|
|
71
|
+
computeOwnerPasswordValue,
|
|
65
72
|
computePasteCascadeOffset,
|
|
66
73
|
computePdfTableSummaryRow,
|
|
67
74
|
computeSmartSnapWithEqualGap,
|
|
75
|
+
computeUserPasswordValue,
|
|
68
76
|
createDefaultPdfUnitData,
|
|
69
77
|
createPdfCjkFontSources,
|
|
78
|
+
decodePdfPermissionFlags,
|
|
79
|
+
decryptPdfBytes,
|
|
70
80
|
detectCJKCharacters,
|
|
71
81
|
detectCJKInPdfInputs,
|
|
72
82
|
detectCJKInPdfTemplate,
|
|
@@ -86,14 +96,17 @@ import {
|
|
|
86
96
|
encodeJapanPost,
|
|
87
97
|
encodeNw7,
|
|
88
98
|
encodePdf417,
|
|
99
|
+
encodePdfPermissionFlags,
|
|
89
100
|
encodeQrCodeMatrix,
|
|
90
101
|
encodeUpcA,
|
|
91
102
|
encodeUpcE,
|
|
103
|
+
encryptPdfBytes,
|
|
92
104
|
evaluateSafeTemplateExpression,
|
|
93
105
|
exportBatchPdfBytes,
|
|
94
106
|
exportCalibrationGridPdfBytes,
|
|
95
107
|
exportJsxToPdfBytes,
|
|
96
108
|
exportPdfBytes,
|
|
109
|
+
exportPdfUnitToBytes,
|
|
97
110
|
exportToPdfmeTemplate,
|
|
98
111
|
extractAcroFormValuesFromPdfBytes,
|
|
99
112
|
extractNativeTextSpansFromPdfBytes,
|
|
@@ -106,15 +119,19 @@ import {
|
|
|
106
119
|
fromPdfmeTemplate,
|
|
107
120
|
getDefaultDateTimeFormat,
|
|
108
121
|
getTrueTypeMappedCodePoints,
|
|
122
|
+
hexToBytes,
|
|
109
123
|
importFromPdfmeTemplate,
|
|
110
124
|
insertPdfPagesBytes,
|
|
125
|
+
inspectPdfEncryption,
|
|
111
126
|
inspectPdfExportCapabilities,
|
|
112
127
|
inspectTrueTypeFont,
|
|
113
128
|
isAspectRatioLockedBarcodeType,
|
|
114
129
|
isCircleMarkChecked,
|
|
115
130
|
isExifDimensionsSwapped,
|
|
116
131
|
isFontUrlSafeToFetch,
|
|
132
|
+
isPdfSecurityActive,
|
|
117
133
|
mayBeJson,
|
|
134
|
+
md5Bytes,
|
|
118
135
|
mergePdfBytes,
|
|
119
136
|
mmToPt,
|
|
120
137
|
movePdfPageBytes,
|
|
@@ -123,6 +140,7 @@ import {
|
|
|
123
140
|
normalizeImageCrop,
|
|
124
141
|
organizePdfBytes,
|
|
125
142
|
overlayDiagnosticGridOnPdfBytes,
|
|
143
|
+
padPdfPassword,
|
|
126
144
|
paginatePdfListItems,
|
|
127
145
|
paginatePdfTableRows,
|
|
128
146
|
parseGs1ApplicationIdentifiers,
|
|
@@ -135,6 +153,7 @@ import {
|
|
|
135
153
|
parseSvgToVectorCommands,
|
|
136
154
|
parseSvgTransformAttr,
|
|
137
155
|
ptToMm,
|
|
156
|
+
rc4Bytes,
|
|
138
157
|
readJpegExifOrientation,
|
|
139
158
|
rectsIntersect,
|
|
140
159
|
removePdfPagesBytes,
|
|
@@ -173,10 +192,11 @@ import {
|
|
|
173
192
|
validatePdfInputContract,
|
|
174
193
|
validatePdfTemplateSchema,
|
|
175
194
|
validatePdfTemplateVariables,
|
|
195
|
+
verifyAndDecryptPdfBytes,
|
|
176
196
|
visitTemplateVariables,
|
|
177
197
|
wrapMixedCjkAndLatinLines,
|
|
178
198
|
wrapPdfTextLines
|
|
179
|
-
} from "./chunk-
|
|
199
|
+
} from "./chunk-SUXA7HBV.js";
|
|
180
200
|
import {
|
|
181
201
|
Fragment,
|
|
182
202
|
PDF_JSX_ELEMENT_SYMBOL,
|
|
@@ -732,6 +752,13 @@ var PdfSelectionService = class extends Disposable {
|
|
|
732
752
|
this.viewportRatio$ = this._viewportRatio$.asObservable();
|
|
733
753
|
this._previewOpen$ = new BehaviorSubject(false);
|
|
734
754
|
this.previewOpen$ = this._previewOpen$.asObservable();
|
|
755
|
+
this._findReplaceOpen$ = new BehaviorSubject(false);
|
|
756
|
+
this.findReplaceOpen$ = this._findReplaceOpen$.asObservable();
|
|
757
|
+
this._searchHighlight$ = new BehaviorSubject(null);
|
|
758
|
+
this.searchHighlight$ = this._searchHighlight$.asObservable();
|
|
759
|
+
this._scrollSeq = 0;
|
|
760
|
+
this._scrollTarget$ = new BehaviorSubject(null);
|
|
761
|
+
this.scrollTarget$ = this._scrollTarget$.asObservable();
|
|
735
762
|
this._clipboard$ = new BehaviorSubject([]);
|
|
736
763
|
this.clipboard$ = this._clipboard$.asObservable();
|
|
737
764
|
const sub = this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_PDF).subscribe((unit) => {
|
|
@@ -771,6 +798,9 @@ var PdfSelectionService = class extends Disposable {
|
|
|
771
798
|
this._inkColor$.complete();
|
|
772
799
|
this._viewportRatio$.complete();
|
|
773
800
|
this._previewOpen$.complete();
|
|
801
|
+
this._findReplaceOpen$.complete();
|
|
802
|
+
this._searchHighlight$.complete();
|
|
803
|
+
this._scrollTarget$.complete();
|
|
774
804
|
this._clipboard$.complete();
|
|
775
805
|
}
|
|
776
806
|
getState() {
|
|
@@ -908,6 +938,29 @@ var PdfSelectionService = class extends Disposable {
|
|
|
908
938
|
setPreviewOpen(open) {
|
|
909
939
|
this._previewOpen$.next(open);
|
|
910
940
|
}
|
|
941
|
+
getFindReplaceOpen() {
|
|
942
|
+
return this._findReplaceOpen$.getValue();
|
|
943
|
+
}
|
|
944
|
+
setFindReplaceOpen(open) {
|
|
945
|
+
this._findReplaceOpen$.next(open);
|
|
946
|
+
if (!open) {
|
|
947
|
+
this._searchHighlight$.next(null);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
getSearchHighlight() {
|
|
951
|
+
return this._searchHighlight$.getValue();
|
|
952
|
+
}
|
|
953
|
+
setSearchHighlight(highlight) {
|
|
954
|
+
this._searchHighlight$.next(highlight);
|
|
955
|
+
}
|
|
956
|
+
requestScrollToTopPt(topPt, pageId) {
|
|
957
|
+
this._scrollSeq += 1;
|
|
958
|
+
this._scrollTarget$.next({
|
|
959
|
+
pageId,
|
|
960
|
+
topPt: Math.max(0, Number(topPt) || 0),
|
|
961
|
+
seq: this._scrollSeq
|
|
962
|
+
});
|
|
963
|
+
}
|
|
911
964
|
setClipboard(elements) {
|
|
912
965
|
this._pasteStep = 0;
|
|
913
966
|
this._clipboard$.next(elements);
|
|
@@ -2168,7 +2221,9 @@ var ReplacePdfSnapshotCommand = {
|
|
|
2168
2221
|
document: next.document,
|
|
2169
2222
|
editState: next.editState,
|
|
2170
2223
|
layers: next.layers ?? null,
|
|
2224
|
+
bookmarks: next.bookmarks ?? next.metadata?.bookmarks ?? null,
|
|
2171
2225
|
attachments: next.attachments ?? null,
|
|
2226
|
+
security: next.security ?? next.metadata?.security ?? null,
|
|
2172
2227
|
securityPermissions: next.securityPermissions ?? null,
|
|
2173
2228
|
signatureEnvelope: next.signatureEnvelope ?? null,
|
|
2174
2229
|
pdfACompliant: next.pdfACompliant ?? null,
|
|
@@ -2183,7 +2238,9 @@ var ReplacePdfSnapshotCommand = {
|
|
|
2183
2238
|
document: prev.document,
|
|
2184
2239
|
editState: prev.editState,
|
|
2185
2240
|
layers: prev.layers ?? null,
|
|
2241
|
+
bookmarks: prev.bookmarks ?? prev.metadata?.bookmarks ?? null,
|
|
2186
2242
|
attachments: prev.attachments ?? null,
|
|
2243
|
+
security: prev.security ?? prev.metadata?.security ?? null,
|
|
2187
2244
|
securityPermissions: prev.securityPermissions ?? null,
|
|
2188
2245
|
signatureEnvelope: prev.signatureEnvelope ?? null,
|
|
2189
2246
|
pdfACompliant: prev.pdfACompliant ?? null,
|
|
@@ -2564,15 +2621,26 @@ var SetPdfBookmarksCommand = {
|
|
|
2564
2621
|
handler: (accessor, params) => {
|
|
2565
2622
|
const ctx = resolveContext(accessor, params?.unitId);
|
|
2566
2623
|
if (!ctx || !Array.isArray(params?.bookmarks)) return false;
|
|
2567
|
-
const
|
|
2624
|
+
const prevSnap = ctx.unit.save();
|
|
2625
|
+
const prevBookmarks = Tools2.deepClone(prevSnap.bookmarks ?? prevSnap.metadata?.bookmarks ?? []);
|
|
2626
|
+
const nextBookmarks = Tools2.deepClone(params.bookmarks);
|
|
2627
|
+
const prevMetadata = Tools2.deepClone(prevSnap.metadata ?? {});
|
|
2568
2628
|
const nextMetadata = {
|
|
2569
2629
|
...Tools2.deepClone(prevMetadata),
|
|
2570
|
-
bookmarks: Tools2.deepClone(
|
|
2630
|
+
bookmarks: Tools2.deepClone(nextBookmarks)
|
|
2571
2631
|
};
|
|
2572
2632
|
const commandService = accessor.get(ICommandService);
|
|
2573
2633
|
const undoRedoService = accessor.get(IUndoRedoService);
|
|
2574
|
-
const redoPatch = {
|
|
2575
|
-
|
|
2634
|
+
const redoPatch = {
|
|
2635
|
+
bookmarks: nextBookmarks,
|
|
2636
|
+
metadata: nextMetadata,
|
|
2637
|
+
replaceMetadata: true
|
|
2638
|
+
};
|
|
2639
|
+
const undoPatch = {
|
|
2640
|
+
bookmarks: prevSnap.bookmarks !== void 0 || prevSnap.metadata?.bookmarks !== void 0 ? prevBookmarks : null,
|
|
2641
|
+
metadata: prevMetadata,
|
|
2642
|
+
replaceMetadata: true
|
|
2643
|
+
};
|
|
2576
2644
|
const result = commandService.syncExecuteCommand(UpdatePdfUnitPropsMutation.id, {
|
|
2577
2645
|
unitId: ctx.unitId,
|
|
2578
2646
|
patch: redoPatch
|
|
@@ -2880,6 +2948,48 @@ var SetPdfAttachmentsCommand = {
|
|
|
2880
2948
|
return Boolean(result);
|
|
2881
2949
|
}
|
|
2882
2950
|
};
|
|
2951
|
+
var SetPdfSecurityConfigCommand = {
|
|
2952
|
+
id: "pdfs.command.set-security-config",
|
|
2953
|
+
type: CommandType2.COMMAND,
|
|
2954
|
+
handler: (accessor, params) => {
|
|
2955
|
+
const ctx = resolveContext(accessor, params?.unitId);
|
|
2956
|
+
if (!ctx) return false;
|
|
2957
|
+
const prevSnap = ctx.unit.save();
|
|
2958
|
+
const prevSecurity = prevSnap.security ?? prevSnap.metadata?.security ?? null;
|
|
2959
|
+
const nextSecurity = params?.security ? Tools2.deepClone(params.security) : null;
|
|
2960
|
+
const prevMetadata = Tools2.deepClone(prevSnap.metadata ?? {});
|
|
2961
|
+
const nextMetadata = Tools2.deepClone(prevMetadata);
|
|
2962
|
+
if (nextSecurity) {
|
|
2963
|
+
nextMetadata.security = Tools2.deepClone(nextSecurity);
|
|
2964
|
+
} else {
|
|
2965
|
+
delete nextMetadata.security;
|
|
2966
|
+
}
|
|
2967
|
+
const commandService = accessor.get(ICommandService);
|
|
2968
|
+
const undoRedoService = accessor.get(IUndoRedoService);
|
|
2969
|
+
const redoPatch = {
|
|
2970
|
+
security: nextSecurity,
|
|
2971
|
+
metadata: nextMetadata,
|
|
2972
|
+
replaceMetadata: true
|
|
2973
|
+
};
|
|
2974
|
+
const undoPatch = {
|
|
2975
|
+
security: prevSecurity ? Tools2.deepClone(prevSecurity) : null,
|
|
2976
|
+
metadata: prevMetadata,
|
|
2977
|
+
replaceMetadata: true
|
|
2978
|
+
};
|
|
2979
|
+
const result = commandService.syncExecuteCommand(UpdatePdfUnitPropsMutation.id, {
|
|
2980
|
+
unitId: ctx.unitId,
|
|
2981
|
+
patch: redoPatch
|
|
2982
|
+
});
|
|
2983
|
+
if (result) {
|
|
2984
|
+
undoRedoService.pushUndoRedo({
|
|
2985
|
+
unitID: ctx.unitId,
|
|
2986
|
+
undoMutations: [{ id: UpdatePdfUnitPropsMutation.id, params: { unitId: ctx.unitId, patch: undoPatch } }],
|
|
2987
|
+
redoMutations: [{ id: UpdatePdfUnitPropsMutation.id, params: { unitId: ctx.unitId, patch: redoPatch } }]
|
|
2988
|
+
});
|
|
2989
|
+
}
|
|
2990
|
+
return Boolean(result);
|
|
2991
|
+
}
|
|
2992
|
+
};
|
|
2883
2993
|
var UpdatePdfPagePropsCommand = {
|
|
2884
2994
|
id: "pdfs.command.update-page-props",
|
|
2885
2995
|
type: CommandType2.COMMAND,
|
|
@@ -2951,9 +3061,17 @@ var UpdatePdfUnitPropsCommand = {
|
|
|
2951
3061
|
if (rawPatch.layers !== void 0) {
|
|
2952
3062
|
undoPatch.layers = prevSnap.layers ? Tools2.deepClone(prevSnap.layers) : null;
|
|
2953
3063
|
}
|
|
3064
|
+
if (rawPatch.bookmarks !== void 0) {
|
|
3065
|
+
const prevBm = prevSnap.bookmarks ?? prevSnap.metadata?.bookmarks;
|
|
3066
|
+
undoPatch.bookmarks = prevBm ? Tools2.deepClone(prevBm) : null;
|
|
3067
|
+
}
|
|
2954
3068
|
if (rawPatch.attachments !== void 0) {
|
|
2955
3069
|
undoPatch.attachments = prevSnap.attachments ? Tools2.deepClone(prevSnap.attachments) : null;
|
|
2956
3070
|
}
|
|
3071
|
+
if (rawPatch.security !== void 0) {
|
|
3072
|
+
const prevSec = prevSnap.security ?? prevSnap.metadata?.security;
|
|
3073
|
+
undoPatch.security = prevSec ? Tools2.deepClone(prevSec) : null;
|
|
3074
|
+
}
|
|
2957
3075
|
if (rawPatch.securityPermissions !== void 0) {
|
|
2958
3076
|
undoPatch.securityPermissions = prevSnap.securityPermissions ? Tools2.deepClone(prevSnap.securityPermissions) : null;
|
|
2959
3077
|
}
|
|
@@ -4605,7 +4723,7 @@ function toUtf8Bytes(input) {
|
|
|
4605
4723
|
if (input instanceof Uint8Array) return input;
|
|
4606
4724
|
return new TextEncoder().encode(input);
|
|
4607
4725
|
}
|
|
4608
|
-
function
|
|
4726
|
+
function bytesToHex2(bytes) {
|
|
4609
4727
|
let hex = "";
|
|
4610
4728
|
for (let i = 0; i < bytes.length; i++) {
|
|
4611
4729
|
hex += bytes[i].toString(16).padStart(2, "0");
|
|
@@ -4688,7 +4806,7 @@ function sha256BytesSync(input) {
|
|
|
4688
4806
|
return out;
|
|
4689
4807
|
}
|
|
4690
4808
|
function sha256HexSync(input) {
|
|
4691
|
-
return
|
|
4809
|
+
return bytesToHex2(sha256BytesSync(input));
|
|
4692
4810
|
}
|
|
4693
4811
|
async function sha256Hex(input) {
|
|
4694
4812
|
const bytes = toUtf8Bytes(input);
|
|
@@ -4698,7 +4816,7 @@ async function sha256Hex(input) {
|
|
|
4698
4816
|
const copy = new Uint8Array(bytes.byteLength);
|
|
4699
4817
|
copy.set(bytes);
|
|
4700
4818
|
const digestBuf = await subtle.digest("SHA-256", copy.buffer);
|
|
4701
|
-
return
|
|
4819
|
+
return bytesToHex2(new Uint8Array(digestBuf));
|
|
4702
4820
|
} catch {
|
|
4703
4821
|
return sha256HexSync(bytes);
|
|
4704
4822
|
}
|
|
@@ -4712,7 +4830,7 @@ function canonicalJsonStringify(value) {
|
|
|
4712
4830
|
}
|
|
4713
4831
|
if (typeof value === "string") return JSON.stringify(value);
|
|
4714
4832
|
if (value instanceof Uint8Array) {
|
|
4715
|
-
return JSON.stringify(`uint8:${
|
|
4833
|
+
return JSON.stringify(`uint8:${bytesToHex2(value)}`);
|
|
4716
4834
|
}
|
|
4717
4835
|
if (Array.isArray(value)) {
|
|
4718
4836
|
return `[${value.map((item) => canonicalJsonStringify(item)).join(",")}]`;
|
|
@@ -7609,6 +7727,249 @@ function createPdfBrowserFidelityExpectations() {
|
|
|
7609
7727
|
}
|
|
7610
7728
|
var PDF_S1_S7_FIDELITY_EXPECTATIONS = Object.freeze(createPdfBrowserFidelityExpectations());
|
|
7611
7729
|
|
|
7730
|
+
// src/exporter/pdf-importer.ts
|
|
7731
|
+
import { generateRandomId as generateRandomId6, Tools as Tools6 } from "@univerjs/core";
|
|
7732
|
+
import {
|
|
7733
|
+
PDFArray as PDFArray4,
|
|
7734
|
+
PDFDict as PDFDict4,
|
|
7735
|
+
PDFDocument as PDFDocument4,
|
|
7736
|
+
PDFHexString as PDFHexString4,
|
|
7737
|
+
PDFName as PDFName4,
|
|
7738
|
+
PDFNumber as PDFNumber2,
|
|
7739
|
+
PDFRef as PDFRef4,
|
|
7740
|
+
PDFString as PDFString4
|
|
7741
|
+
} from "pdf-lib";
|
|
7742
|
+
function hasPdfMagicHeader(bytes) {
|
|
7743
|
+
if (!bytes || bytes.byteLength < 5) return false;
|
|
7744
|
+
const maxScan = Math.min(bytes.byteLength - 5, 1024);
|
|
7745
|
+
for (let i = 0; i <= maxScan; i++) {
|
|
7746
|
+
if (bytes[i] === 37 && bytes[i + 1] === 80 && bytes[i + 2] === 68 && bytes[i + 3] === 70 && bytes[i + 4] === 45) {
|
|
7747
|
+
return true;
|
|
7748
|
+
}
|
|
7749
|
+
}
|
|
7750
|
+
return false;
|
|
7751
|
+
}
|
|
7752
|
+
function decodePdfTextValue(obj) {
|
|
7753
|
+
if (obj instanceof PDFHexString4 || obj instanceof PDFString4 || obj instanceof PDFName4) {
|
|
7754
|
+
return obj.decodeText();
|
|
7755
|
+
}
|
|
7756
|
+
return "";
|
|
7757
|
+
}
|
|
7758
|
+
function extractOutlinesBookmarksFromDoc(doc) {
|
|
7759
|
+
const outlinesRef = doc.catalog.get(PDFName4.of("Outlines"));
|
|
7760
|
+
const outlinesDict = doc.context.lookupMaybe(outlinesRef, PDFDict4);
|
|
7761
|
+
if (!outlinesDict) return [];
|
|
7762
|
+
const pages = doc.getPages();
|
|
7763
|
+
const pageRefKeyToIdx = /* @__PURE__ */ new Map();
|
|
7764
|
+
pages.forEach((p, idx) => {
|
|
7765
|
+
pageRefKeyToIdx.set(`${p.ref.objectNumber}:${p.ref.generationNumber}`, idx);
|
|
7766
|
+
});
|
|
7767
|
+
const resolveDest = (itemDict) => {
|
|
7768
|
+
let destObj = itemDict.get(PDFName4.of("Dest"));
|
|
7769
|
+
if (!destObj) {
|
|
7770
|
+
const actionDict = doc.context.lookupMaybe(itemDict.get(PDFName4.of("A")), PDFDict4);
|
|
7771
|
+
if (actionDict) {
|
|
7772
|
+
destObj = actionDict.get(PDFName4.of("D"));
|
|
7773
|
+
}
|
|
7774
|
+
}
|
|
7775
|
+
const destArr = doc.context.lookupMaybe(destObj, PDFArray4);
|
|
7776
|
+
if (!destArr || destArr.size() === 0) return { pageIndex: 0 };
|
|
7777
|
+
const pRef = destArr.get(0);
|
|
7778
|
+
let pageIndex = 0;
|
|
7779
|
+
if (pRef instanceof PDFRef4) {
|
|
7780
|
+
pageIndex = pageRefKeyToIdx.get(`${pRef.objectNumber}:${pRef.generationNumber}`) ?? 0;
|
|
7781
|
+
} else if (pRef instanceof PDFNumber2) {
|
|
7782
|
+
pageIndex = Math.max(0, Math.min(pages.length - 1, Math.floor(pRef.asNumber())));
|
|
7783
|
+
}
|
|
7784
|
+
let topPt;
|
|
7785
|
+
if (destArr.size() >= 4) {
|
|
7786
|
+
const yObj = destArr.get(3);
|
|
7787
|
+
if (yObj instanceof PDFNumber2 && pages[pageIndex]) {
|
|
7788
|
+
const pageHeight = pages[pageIndex].getHeight();
|
|
7789
|
+
topPt = Math.round(Math.max(0, pageHeight - yObj.asNumber()) * 100) / 100;
|
|
7790
|
+
}
|
|
7791
|
+
}
|
|
7792
|
+
return { pageIndex, topPt };
|
|
7793
|
+
};
|
|
7794
|
+
const visited = /* @__PURE__ */ new Set();
|
|
7795
|
+
const walkLevel = (firstRef) => {
|
|
7796
|
+
const list = [];
|
|
7797
|
+
let cur = firstRef;
|
|
7798
|
+
while (cur) {
|
|
7799
|
+
if (cur instanceof PDFRef4) {
|
|
7800
|
+
const key = `${cur.objectNumber}:${cur.generationNumber}`;
|
|
7801
|
+
if (visited.has(key)) break;
|
|
7802
|
+
visited.add(key);
|
|
7803
|
+
}
|
|
7804
|
+
const itemDict = cur instanceof PDFDict4 ? cur : doc.context.lookupMaybe(cur, PDFDict4);
|
|
7805
|
+
if (!itemDict) break;
|
|
7806
|
+
const title = decodePdfTextValue(itemDict.get(PDFName4.of("Title"))) || "Bookmark";
|
|
7807
|
+
const { pageIndex, topPt } = resolveDest(itemDict);
|
|
7808
|
+
const childFirst = itemDict.get(PDFName4.of("First"));
|
|
7809
|
+
const children = childFirst ? walkLevel(childFirst) : [];
|
|
7810
|
+
const bm = {
|
|
7811
|
+
id: `bm-${generateRandomId6(6)}`,
|
|
7812
|
+
title,
|
|
7813
|
+
pageIndex,
|
|
7814
|
+
...topPt !== void 0 ? { topOffsetPt: topPt, topPt } : {},
|
|
7815
|
+
...children.length > 0 ? { children } : {}
|
|
7816
|
+
};
|
|
7817
|
+
list.push(bm);
|
|
7818
|
+
const nextRef = itemDict.get(PDFName4.of("Next"));
|
|
7819
|
+
if (!nextRef || nextRef === cur) break;
|
|
7820
|
+
cur = nextRef;
|
|
7821
|
+
}
|
|
7822
|
+
return list;
|
|
7823
|
+
};
|
|
7824
|
+
return walkLevel(outlinesDict.get(PDFName4.of("First")));
|
|
7825
|
+
}
|
|
7826
|
+
function extractLayersFromDoc(doc) {
|
|
7827
|
+
const ocProps = doc.context.lookupMaybe(doc.catalog.get(PDFName4.of("OCProperties")), PDFDict4);
|
|
7828
|
+
if (!ocProps) return [];
|
|
7829
|
+
const ocgsArr = doc.context.lookupMaybe(ocProps.get(PDFName4.of("OCGs")), PDFArray4);
|
|
7830
|
+
if (!ocgsArr || ocgsArr.size() === 0) return [];
|
|
7831
|
+
const defaultCfg = doc.context.lookupMaybe(ocProps.get(PDFName4.of("D")), PDFDict4);
|
|
7832
|
+
const offRefKeys = /* @__PURE__ */ new Set();
|
|
7833
|
+
const lockedRefKeys = /* @__PURE__ */ new Set();
|
|
7834
|
+
if (defaultCfg) {
|
|
7835
|
+
const offArr = doc.context.lookupMaybe(defaultCfg.get(PDFName4.of("OFF")), PDFArray4);
|
|
7836
|
+
if (offArr) {
|
|
7837
|
+
for (let i = 0; i < offArr.size(); i++) {
|
|
7838
|
+
const r = offArr.get(i);
|
|
7839
|
+
if (r instanceof PDFRef4) offRefKeys.add(`${r.objectNumber}:${r.generationNumber}`);
|
|
7840
|
+
}
|
|
7841
|
+
}
|
|
7842
|
+
const lockedArr = doc.context.lookupMaybe(defaultCfg.get(PDFName4.of("Locked")), PDFArray4);
|
|
7843
|
+
if (lockedArr) {
|
|
7844
|
+
for (let i = 0; i < lockedArr.size(); i++) {
|
|
7845
|
+
const r = lockedArr.get(i);
|
|
7846
|
+
if (r instanceof PDFRef4) lockedRefKeys.add(`${r.objectNumber}:${r.generationNumber}`);
|
|
7847
|
+
}
|
|
7848
|
+
}
|
|
7849
|
+
}
|
|
7850
|
+
const out = [];
|
|
7851
|
+
for (let i = 0; i < ocgsArr.size(); i++) {
|
|
7852
|
+
const entry = ocgsArr.get(i);
|
|
7853
|
+
const key = entry instanceof PDFRef4 ? `${entry.objectNumber}:${entry.generationNumber}` : "";
|
|
7854
|
+
const dict = entry instanceof PDFDict4 ? entry : doc.context.lookupMaybe(entry, PDFDict4);
|
|
7855
|
+
if (!dict) continue;
|
|
7856
|
+
const name = decodePdfTextValue(dict.get(PDFName4.of("Name"))) || `Layer ${i + 1}`;
|
|
7857
|
+
let printable = true;
|
|
7858
|
+
const usage = doc.context.lookupMaybe(dict.get(PDFName4.of("Usage")), PDFDict4);
|
|
7859
|
+
if (usage) {
|
|
7860
|
+
const printDict = doc.context.lookupMaybe(usage.get(PDFName4.of("Print")), PDFDict4);
|
|
7861
|
+
if (printDict && decodePdfTextValue(printDict.get(PDFName4.of("PrintState"))) === "OFF") {
|
|
7862
|
+
printable = false;
|
|
7863
|
+
}
|
|
7864
|
+
}
|
|
7865
|
+
out.push({
|
|
7866
|
+
id: `layer-${generateRandomId6(6)}`,
|
|
7867
|
+
name,
|
|
7868
|
+
visible: key ? !offRefKeys.has(key) : true,
|
|
7869
|
+
locked: key ? lockedRefKeys.has(key) : false,
|
|
7870
|
+
printable
|
|
7871
|
+
});
|
|
7872
|
+
}
|
|
7873
|
+
return out;
|
|
7874
|
+
}
|
|
7875
|
+
async function importPdfBytesToUnit(pdfBytes, options) {
|
|
7876
|
+
if (!hasPdfMagicHeader(pdfBytes)) {
|
|
7877
|
+
throw new Error("Invalid PDF binary: missing %PDF- header signature.");
|
|
7878
|
+
}
|
|
7879
|
+
const encryptionInspection = inspectPdfEncryption(pdfBytes);
|
|
7880
|
+
const decryptedBytes = await verifyAndDecryptPdfBytes(pdfBytes, options?.password);
|
|
7881
|
+
const unitTitle = options?.name ?? options?.title;
|
|
7882
|
+
const unit = await importAcroFormPdfToUnit(decryptedBytes, {
|
|
7883
|
+
unitId: options?.unitId,
|
|
7884
|
+
title: unitTitle
|
|
7885
|
+
});
|
|
7886
|
+
if (options?.fileName && unit.sourceDocumentRef) {
|
|
7887
|
+
unit.sourceDocumentRef.fileName = options.fileName;
|
|
7888
|
+
}
|
|
7889
|
+
try {
|
|
7890
|
+
const doc = await PDFDocument4.load(decryptedBytes, { updateMetadata: false });
|
|
7891
|
+
const parsedBookmarks = extractOutlinesBookmarksFromDoc(doc);
|
|
7892
|
+
if (parsedBookmarks.length > 0) {
|
|
7893
|
+
unit.bookmarks = Tools6.deepClone(parsedBookmarks);
|
|
7894
|
+
unit.metadata = {
|
|
7895
|
+
...unit.metadata ?? {},
|
|
7896
|
+
bookmarks: Tools6.deepClone(parsedBookmarks)
|
|
7897
|
+
};
|
|
7898
|
+
}
|
|
7899
|
+
const parsedLayers = extractLayersFromDoc(doc);
|
|
7900
|
+
if (parsedLayers.length > 0) {
|
|
7901
|
+
unit.layers = Tools6.deepClone(parsedLayers);
|
|
7902
|
+
}
|
|
7903
|
+
if (unitTitle === void 0) {
|
|
7904
|
+
const docTitle = doc.getTitle();
|
|
7905
|
+
if (docTitle) {
|
|
7906
|
+
unit.name = docTitle;
|
|
7907
|
+
} else if (options?.fileName) {
|
|
7908
|
+
unit.name = options.fileName.replace(/\.pdf$/i, "");
|
|
7909
|
+
}
|
|
7910
|
+
}
|
|
7911
|
+
} catch {
|
|
7912
|
+
}
|
|
7913
|
+
if (encryptionInspection.encrypted) {
|
|
7914
|
+
unit.metadata = {
|
|
7915
|
+
...unit.metadata ?? {},
|
|
7916
|
+
importedEncryptionInfo: {
|
|
7917
|
+
encrypted: true,
|
|
7918
|
+
requiresOpenPassword: encryptionInspection.requiresOpenPassword,
|
|
7919
|
+
keyLength: encryptionInspection.keyLength,
|
|
7920
|
+
permissions: { ...encryptionInspection.permissions }
|
|
7921
|
+
}
|
|
7922
|
+
};
|
|
7923
|
+
}
|
|
7924
|
+
if (options?.promoteNativeTextToElements) {
|
|
7925
|
+
const spansByPage = unit.editState.nativeTextSpansByPage ?? {};
|
|
7926
|
+
for (const pageId of unit.document.pageOrder) {
|
|
7927
|
+
const pageSpans = spansByPage[pageId] ?? [];
|
|
7928
|
+
if (!unit.editState.elementsByPage[pageId]) {
|
|
7929
|
+
unit.editState.elementsByPage[pageId] = {};
|
|
7930
|
+
}
|
|
7931
|
+
if (!unit.editState.elementOrderByPage[pageId]) {
|
|
7932
|
+
unit.editState.elementOrderByPage[pageId] = [];
|
|
7933
|
+
}
|
|
7934
|
+
for (const span of pageSpans) {
|
|
7935
|
+
if (span.suppressed) continue;
|
|
7936
|
+
span.suppressed = true;
|
|
7937
|
+
const elId = `el-${generateRandomId6(6)}`;
|
|
7938
|
+
const textEl = {
|
|
7939
|
+
id: elId,
|
|
7940
|
+
type: "text" /* TEXT */,
|
|
7941
|
+
name: "Imported Text",
|
|
7942
|
+
content: span.text,
|
|
7943
|
+
metadata: { promotedFromNativeSpanId: span.id },
|
|
7944
|
+
transform: {
|
|
7945
|
+
left: span.left,
|
|
7946
|
+
top: span.top,
|
|
7947
|
+
width: span.width,
|
|
7948
|
+
height: span.height,
|
|
7949
|
+
angle: 0
|
|
7950
|
+
},
|
|
7951
|
+
style: {
|
|
7952
|
+
fontFamily: "Inter, PingFang SC, Microsoft YaHei, sans-serif",
|
|
7953
|
+
fontSize: span.fontSize,
|
|
7954
|
+
fontWeight: "normal",
|
|
7955
|
+
color: "#1B1C1F",
|
|
7956
|
+
textAlign: "left",
|
|
7957
|
+
verticalAlign: "middle",
|
|
7958
|
+
lineHeight: 1.2,
|
|
7959
|
+
padding: 0
|
|
7960
|
+
}
|
|
7961
|
+
};
|
|
7962
|
+
unit.editState.elementsByPage[pageId][elId] = textEl;
|
|
7963
|
+
unit.editState.elementOrderByPage[pageId].push(elId);
|
|
7964
|
+
}
|
|
7965
|
+
}
|
|
7966
|
+
if (unit.metadata?.nativeTextSpansByPage) {
|
|
7967
|
+
unit.metadata.nativeTextSpansByPage = Tools6.deepClone(spansByPage);
|
|
7968
|
+
}
|
|
7969
|
+
}
|
|
7970
|
+
return unit;
|
|
7971
|
+
}
|
|
7972
|
+
|
|
7612
7973
|
// src/plugin.ts
|
|
7613
7974
|
import {
|
|
7614
7975
|
ICommandService as ICommandService2,
|
|
@@ -7624,10 +7985,10 @@ import {
|
|
|
7624
7985
|
CanceledError,
|
|
7625
7986
|
createIdentifier as createIdentifier2,
|
|
7626
7987
|
Disposable as Disposable2,
|
|
7627
|
-
generateRandomId as
|
|
7988
|
+
generateRandomId as generateRandomId7,
|
|
7628
7989
|
IUniverInstanceService as IUniverInstanceService4,
|
|
7629
7990
|
Optional,
|
|
7630
|
-
Tools as
|
|
7991
|
+
Tools as Tools7,
|
|
7631
7992
|
UniverInstanceType as UniverInstanceType4
|
|
7632
7993
|
} from "@univerjs/core";
|
|
7633
7994
|
import { BehaviorSubject as BehaviorSubject2, Subject } from "rxjs";
|
|
@@ -7683,7 +8044,7 @@ function createHttpSilentPrintAdapter(config) {
|
|
|
7683
8044
|
payload = null;
|
|
7684
8045
|
}
|
|
7685
8046
|
return {
|
|
7686
|
-
jobId: String(payload?.jobId || payload?.id || `print-${
|
|
8047
|
+
jobId: String(payload?.jobId || payload?.id || `print-${generateRandomId7(8)}`),
|
|
7687
8048
|
driver: String(payload?.driver || driver),
|
|
7688
8049
|
byteLength: pdfBytes.byteLength,
|
|
7689
8050
|
printedAt: Number(payload?.printedAt || Date.now())
|
|
@@ -7766,7 +8127,7 @@ function decodeBase64Strict(b64Input) {
|
|
|
7766
8127
|
}
|
|
7767
8128
|
return out;
|
|
7768
8129
|
}
|
|
7769
|
-
function
|
|
8130
|
+
function hasPdfMagicHeader2(bytes) {
|
|
7770
8131
|
if (bytes.byteLength < 8) return false;
|
|
7771
8132
|
const scanLimit = Math.min(1024, bytes.byteLength - 5);
|
|
7772
8133
|
for (let i = 0; i <= scanLimit; i++) {
|
|
@@ -7803,74 +8164,74 @@ function countJsInActionDict(actionDict, doc, PDFArrayCtor, PDFDictCtor, PDFName
|
|
|
7803
8164
|
return count;
|
|
7804
8165
|
}
|
|
7805
8166
|
function inspectPdfDocumentImportWarnings(doc, pdfLib) {
|
|
7806
|
-
const { PDFArray:
|
|
8167
|
+
const { PDFArray: PDFArray5, PDFDict: PDFDict5, PDFName: PDFName5 } = pdfLib;
|
|
7807
8168
|
const warnings = [];
|
|
7808
8169
|
let acroFieldCount = 0;
|
|
7809
|
-
const acroFormDict = doc.catalog.lookupMaybe(
|
|
8170
|
+
const acroFormDict = doc.catalog.lookupMaybe(PDFName5.of("AcroForm"), PDFDict5);
|
|
7810
8171
|
if (acroFormDict) {
|
|
7811
8172
|
try {
|
|
7812
8173
|
acroFieldCount = doc.getForm().getFields().length;
|
|
7813
8174
|
} catch {
|
|
7814
|
-
const fieldsArr = acroFormDict.lookupMaybe(
|
|
8175
|
+
const fieldsArr = acroFormDict.lookupMaybe(PDFName5.of("Fields"), PDFArray5);
|
|
7815
8176
|
if (fieldsArr) {
|
|
7816
8177
|
acroFieldCount = fieldsArr.size();
|
|
7817
8178
|
}
|
|
7818
8179
|
}
|
|
7819
8180
|
}
|
|
7820
8181
|
let jsCount = 0;
|
|
7821
|
-
const namesDict = doc.catalog.lookupMaybe(
|
|
7822
|
-
const jsNameTree = namesDict?.lookupMaybe(
|
|
8182
|
+
const namesDict = doc.catalog.lookupMaybe(PDFName5.of("Names"), PDFDict5);
|
|
8183
|
+
const jsNameTree = namesDict?.lookupMaybe(PDFName5.of("JavaScript"), PDFDict5);
|
|
7823
8184
|
if (jsNameTree) {
|
|
7824
|
-
const namesArr = jsNameTree.lookupMaybe(
|
|
8185
|
+
const namesArr = jsNameTree.lookupMaybe(PDFName5.of("Names"), PDFArray5);
|
|
7825
8186
|
jsCount += namesArr ? Math.max(1, Math.floor(namesArr.size() / 2)) : 1;
|
|
7826
8187
|
}
|
|
7827
|
-
const openAction = doc.catalog.lookupMaybe(
|
|
8188
|
+
const openAction = doc.catalog.lookupMaybe(PDFName5.of("OpenAction"), PDFDict5);
|
|
7828
8189
|
if (openAction) {
|
|
7829
|
-
jsCount += countJsInActionDict(openAction, doc,
|
|
8190
|
+
jsCount += countJsInActionDict(openAction, doc, PDFArray5, PDFDict5, PDFName5);
|
|
7830
8191
|
}
|
|
7831
|
-
const catalogAA = doc.catalog.lookupMaybe(
|
|
8192
|
+
const catalogAA = doc.catalog.lookupMaybe(PDFName5.of("AA"), PDFDict5);
|
|
7832
8193
|
if (catalogAA) {
|
|
7833
8194
|
for (const [, actionRef] of catalogAA.entries()) {
|
|
7834
|
-
const act = doc.context.lookupMaybe(actionRef,
|
|
8195
|
+
const act = doc.context.lookupMaybe(actionRef, PDFDict5);
|
|
7835
8196
|
if (act) {
|
|
7836
|
-
jsCount += countJsInActionDict(act, doc,
|
|
8197
|
+
jsCount += countJsInActionDict(act, doc, PDFArray5, PDFDict5, PDFName5);
|
|
7837
8198
|
}
|
|
7838
8199
|
}
|
|
7839
8200
|
}
|
|
7840
8201
|
let activeAnnotationCount = 0;
|
|
7841
8202
|
let orphanWidgetCount = 0;
|
|
7842
8203
|
for (const page of doc.getPages()) {
|
|
7843
|
-
const pageAA = page.node.lookupMaybe(
|
|
8204
|
+
const pageAA = page.node.lookupMaybe(PDFName5.of("AA"), PDFDict5);
|
|
7844
8205
|
if (pageAA) {
|
|
7845
8206
|
for (const [, actionRef] of pageAA.entries()) {
|
|
7846
|
-
const act = doc.context.lookupMaybe(actionRef,
|
|
8207
|
+
const act = doc.context.lookupMaybe(actionRef, PDFDict5);
|
|
7847
8208
|
if (act) {
|
|
7848
|
-
jsCount += countJsInActionDict(act, doc,
|
|
8209
|
+
jsCount += countJsInActionDict(act, doc, PDFArray5, PDFDict5, PDFName5);
|
|
7849
8210
|
}
|
|
7850
8211
|
}
|
|
7851
8212
|
}
|
|
7852
8213
|
const annots = page.node.Annots();
|
|
7853
|
-
if (annots instanceof
|
|
8214
|
+
if (annots instanceof PDFArray5) {
|
|
7854
8215
|
for (let i = 0; i < annots.size(); i++) {
|
|
7855
|
-
const annot = annots.lookupMaybe(i,
|
|
8216
|
+
const annot = annots.lookupMaybe(i, PDFDict5);
|
|
7856
8217
|
if (!annot) continue;
|
|
7857
|
-
const subtypeObj = annot.get(
|
|
8218
|
+
const subtypeObj = annot.get(PDFName5.of("Subtype"));
|
|
7858
8219
|
const subtype = subtypeObj ? subtypeObj.toString() : "";
|
|
7859
8220
|
if (subtype === "/Widget") {
|
|
7860
8221
|
orphanWidgetCount += 1;
|
|
7861
8222
|
} else if (subtype !== "/Popup") {
|
|
7862
8223
|
activeAnnotationCount += 1;
|
|
7863
8224
|
}
|
|
7864
|
-
const annotAction = annot.lookupMaybe(
|
|
8225
|
+
const annotAction = annot.lookupMaybe(PDFName5.of("A"), PDFDict5);
|
|
7865
8226
|
if (annotAction) {
|
|
7866
|
-
jsCount += countJsInActionDict(annotAction, doc,
|
|
8227
|
+
jsCount += countJsInActionDict(annotAction, doc, PDFArray5, PDFDict5, PDFName5);
|
|
7867
8228
|
}
|
|
7868
|
-
const annotAA = annot.lookupMaybe(
|
|
8229
|
+
const annotAA = annot.lookupMaybe(PDFName5.of("AA"), PDFDict5);
|
|
7869
8230
|
if (annotAA) {
|
|
7870
8231
|
for (const [, actionRef] of annotAA.entries()) {
|
|
7871
|
-
const act = doc.context.lookupMaybe(actionRef,
|
|
8232
|
+
const act = doc.context.lookupMaybe(actionRef, PDFDict5);
|
|
7872
8233
|
if (act) {
|
|
7873
|
-
jsCount += countJsInActionDict(act, doc,
|
|
8234
|
+
jsCount += countJsInActionDict(act, doc, PDFArray5, PDFDict5, PDFName5);
|
|
7874
8235
|
}
|
|
7875
8236
|
}
|
|
7876
8237
|
}
|
|
@@ -7925,23 +8286,23 @@ function normalizePdfImportWarnings(raw) {
|
|
|
7925
8286
|
return normalized;
|
|
7926
8287
|
}
|
|
7927
8288
|
function buildOverlayImportCandidateSnapshot(baseSnapshot, outcome) {
|
|
7928
|
-
const prevSnapshot =
|
|
8289
|
+
const prevSnapshot = Tools7.deepClone(baseSnapshot);
|
|
7929
8290
|
const existingOrder = prevSnapshot.document?.pageOrder ?? [];
|
|
7930
8291
|
const pageSizes = outcome.pageSizes ?? [];
|
|
7931
8292
|
const totalPages = Math.max(1, pageSizes.length || outcome.sourceDocumentRef.pageCount || 1);
|
|
7932
8293
|
const nextPages = {};
|
|
7933
8294
|
const nextPageOrder = [];
|
|
7934
|
-
const nextElementsByPage =
|
|
7935
|
-
const nextElementOrderByPage =
|
|
8295
|
+
const nextElementsByPage = Tools7.deepClone(prevSnapshot.editState?.elementsByPage ?? {});
|
|
8296
|
+
const nextElementOrderByPage = Tools7.deepClone(prevSnapshot.editState?.elementOrderByPage ?? {});
|
|
7936
8297
|
for (let i = 0; i < totalPages; i++) {
|
|
7937
|
-
const pid = existingOrder[i] || `page-${
|
|
8298
|
+
const pid = existingOrder[i] || `page-${generateRandomId7(6)}`;
|
|
7938
8299
|
nextPageOrder.push(pid);
|
|
7939
8300
|
const resolvedSize = pageSizes[i] ?? pageSizes[0] ?? prevSnapshot.document.pageSize;
|
|
7940
8301
|
nextPages[pid] = {
|
|
7941
8302
|
id: pid,
|
|
7942
8303
|
title: `Page ${i + 1}`,
|
|
7943
8304
|
sourcePageNumber: i + 1,
|
|
7944
|
-
pageSize:
|
|
8305
|
+
pageSize: Tools7.deepClone(resolvedSize),
|
|
7945
8306
|
backgroundColor: "#ffffff"
|
|
7946
8307
|
};
|
|
7947
8308
|
if (!nextElementsByPage[pid]) nextElementsByPage[pid] = {};
|
|
@@ -7949,10 +8310,10 @@ function buildOverlayImportCandidateSnapshot(baseSnapshot, outcome) {
|
|
|
7949
8310
|
}
|
|
7950
8311
|
return {
|
|
7951
8312
|
...prevSnapshot,
|
|
7952
|
-
sourceDocumentRef:
|
|
8313
|
+
sourceDocumentRef: Tools7.deepClone(outcome.sourceDocumentRef),
|
|
7953
8314
|
document: {
|
|
7954
8315
|
...prevSnapshot.document,
|
|
7955
|
-
pageSize:
|
|
8316
|
+
pageSize: Tools7.deepClone(pageSizes[0] ?? prevSnapshot.document.pageSize),
|
|
7956
8317
|
pages: nextPages,
|
|
7957
8318
|
pageOrder: nextPageOrder
|
|
7958
8319
|
},
|
|
@@ -7973,8 +8334,8 @@ function normalizeAdapterImportResult(raw) {
|
|
|
7973
8334
|
return {
|
|
7974
8335
|
outcome: {
|
|
7975
8336
|
mode: "overlay",
|
|
7976
|
-
sourceDocumentRef:
|
|
7977
|
-
pageSizes:
|
|
8337
|
+
sourceDocumentRef: Tools7.deepClone(record.sourceDocumentRef),
|
|
8338
|
+
pageSizes: Tools7.deepClone(record.pageSizes ?? []),
|
|
7978
8339
|
...warnings.length > 0 ? { warnings } : {}
|
|
7979
8340
|
},
|
|
7980
8341
|
warnings
|
|
@@ -7982,7 +8343,7 @@ function normalizeAdapterImportResult(raw) {
|
|
|
7982
8343
|
}
|
|
7983
8344
|
if (record.mode === "snapshot") {
|
|
7984
8345
|
const warnings = normalizePdfImportWarnings(record.warnings);
|
|
7985
|
-
const clonedSnapshot =
|
|
8346
|
+
const clonedSnapshot = Tools7.deepClone(record.snapshot);
|
|
7986
8347
|
return {
|
|
7987
8348
|
outcome: {
|
|
7988
8349
|
mode: "snapshot",
|
|
@@ -7994,7 +8355,7 @@ function normalizeAdapterImportResult(raw) {
|
|
|
7994
8355
|
}
|
|
7995
8356
|
if (record.snapshot && typeof record.snapshot === "object") {
|
|
7996
8357
|
const warnings = normalizePdfImportWarnings(record.warnings);
|
|
7997
|
-
const clonedSnapshot =
|
|
8358
|
+
const clonedSnapshot = Tools7.deepClone(record.snapshot);
|
|
7998
8359
|
return {
|
|
7999
8360
|
outcome: {
|
|
8000
8361
|
mode: "snapshot",
|
|
@@ -8006,7 +8367,7 @@ function normalizeAdapterImportResult(raw) {
|
|
|
8006
8367
|
}
|
|
8007
8368
|
if ("schema" in record || "document" in record) {
|
|
8008
8369
|
const warnings = normalizePdfImportWarnings(record.warnings);
|
|
8009
|
-
const clonedSnapshot =
|
|
8370
|
+
const clonedSnapshot = Tools7.deepClone(record);
|
|
8010
8371
|
delete clonedSnapshot.warnings;
|
|
8011
8372
|
return {
|
|
8012
8373
|
outcome: {
|
|
@@ -8127,19 +8488,31 @@ async function importPdfSource(source, options) {
|
|
|
8127
8488
|
} else {
|
|
8128
8489
|
throw new PdfImportError("INVALID_PDF_HEADER", "Unsupported PDF input source.");
|
|
8129
8490
|
}
|
|
8130
|
-
if (!
|
|
8491
|
+
if (!hasPdfMagicHeader2(bytes)) {
|
|
8131
8492
|
throw new PdfImportError(
|
|
8132
8493
|
"INVALID_PDF_HEADER",
|
|
8133
8494
|
"Invalid PDF binary: missing %PDF- header signature."
|
|
8134
8495
|
);
|
|
8135
8496
|
}
|
|
8136
8497
|
throwIfSignalAborted(options?.signal);
|
|
8137
|
-
const { PDFArray:
|
|
8498
|
+
const { PDFArray: PDFArray5, PDFDict: PDFDict5, PDFDocument: PDFDocument5, PDFName: PDFName5 } = await import("pdf-lib");
|
|
8138
8499
|
throwIfSignalAborted(options?.signal);
|
|
8139
8500
|
let pageSizes = [];
|
|
8140
8501
|
let warnings = [];
|
|
8502
|
+
const encInspection = inspectPdfEncryption(bytes);
|
|
8503
|
+
if (encInspection.encrypted) {
|
|
8504
|
+
try {
|
|
8505
|
+
bytes = await verifyAndDecryptPdfBytes(bytes, options?.password);
|
|
8506
|
+
} catch (secErr) {
|
|
8507
|
+
if (secErr instanceof PdfSecurityError) {
|
|
8508
|
+
if (secErr.code === "PDF_PASSWORD_REQUIRED" || secErr.code === "PDF_INVALID_PASSWORD") {
|
|
8509
|
+
throw new PdfImportError("ENCRYPTED_PDF_PASSWORD_REQUIRED", secErr.message);
|
|
8510
|
+
}
|
|
8511
|
+
}
|
|
8512
|
+
}
|
|
8513
|
+
}
|
|
8141
8514
|
try {
|
|
8142
|
-
const doc = await
|
|
8515
|
+
const doc = await PDFDocument5.load(bytes);
|
|
8143
8516
|
if (doc.isEncrypted && !options?.password) {
|
|
8144
8517
|
throw new PdfImportError(
|
|
8145
8518
|
"ENCRYPTED_PDF_PASSWORD_REQUIRED",
|
|
@@ -8154,7 +8527,7 @@ async function importPdfSource(source, options) {
|
|
|
8154
8527
|
const { width, height } = p.getSize();
|
|
8155
8528
|
return { width, height, preset: "CUSTOM" };
|
|
8156
8529
|
});
|
|
8157
|
-
warnings = inspectPdfDocumentImportWarnings(doc, { PDFArray:
|
|
8530
|
+
warnings = inspectPdfDocumentImportWarnings(doc, { PDFArray: PDFArray5, PDFDict: PDFDict5, PDFName: PDFName5 });
|
|
8158
8531
|
} catch (err) {
|
|
8159
8532
|
if (err instanceof PdfImportError) {
|
|
8160
8533
|
throw err;
|
|
@@ -8213,7 +8586,7 @@ async function importPdfSource(source, options) {
|
|
|
8213
8586
|
}
|
|
8214
8587
|
if (!verifiedByPdfjs) {
|
|
8215
8588
|
try {
|
|
8216
|
-
const doc = await
|
|
8589
|
+
const doc = await PDFDocument5.load(bytes, { ignoreEncryption: true });
|
|
8217
8590
|
const pages = doc.getPages();
|
|
8218
8591
|
if (pages.length === 0) {
|
|
8219
8592
|
throw new PdfImportError("CORRUPT_PDF", "PDF document contains zero pages.");
|
|
@@ -8222,7 +8595,7 @@ async function importPdfSource(source, options) {
|
|
|
8222
8595
|
const { width, height } = p.getSize();
|
|
8223
8596
|
return { width, height, preset: "CUSTOM" };
|
|
8224
8597
|
});
|
|
8225
|
-
warnings = inspectPdfDocumentImportWarnings(doc, { PDFArray:
|
|
8598
|
+
warnings = inspectPdfDocumentImportWarnings(doc, { PDFArray: PDFArray5, PDFDict: PDFDict5, PDFName: PDFName5 });
|
|
8226
8599
|
} catch (fallbackErr) {
|
|
8227
8600
|
if (fallbackErr instanceof PdfImportError) throw fallbackErr;
|
|
8228
8601
|
throw new PdfImportError(
|
|
@@ -8242,7 +8615,7 @@ async function importPdfSource(source, options) {
|
|
|
8242
8615
|
mode: "overlay",
|
|
8243
8616
|
bytes,
|
|
8244
8617
|
sourceDocumentRef: {
|
|
8245
|
-
id: `src-${
|
|
8618
|
+
id: `src-${generateRandomId7(6)}`,
|
|
8246
8619
|
fileName,
|
|
8247
8620
|
mimeType: "application/pdf",
|
|
8248
8621
|
dataUri,
|
|
@@ -8493,7 +8866,7 @@ var PdfIoService = class extends Disposable2 {
|
|
|
8493
8866
|
}
|
|
8494
8867
|
_resolveBaseSnapshotForImport(context) {
|
|
8495
8868
|
if (context?.snapshot) {
|
|
8496
|
-
const cloned =
|
|
8869
|
+
const cloned = Tools7.deepClone(context.snapshot);
|
|
8497
8870
|
return {
|
|
8498
8871
|
unitId: context.unitId || cloned.id,
|
|
8499
8872
|
baseSnapshot: cloned
|
|
@@ -8554,7 +8927,7 @@ var PdfIoService = class extends Disposable2 {
|
|
|
8554
8927
|
rawResult = await raceWithAbortSignal(
|
|
8555
8928
|
adapter.importPdf(file, {
|
|
8556
8929
|
unitId,
|
|
8557
|
-
snapshot:
|
|
8930
|
+
snapshot: Tools7.deepClone(baseSnapshot),
|
|
8558
8931
|
...signal ? { signal } : {},
|
|
8559
8932
|
defaultImport
|
|
8560
8933
|
}),
|
|
@@ -8585,7 +8958,7 @@ var PdfIoService = class extends Disposable2 {
|
|
|
8585
8958
|
}
|
|
8586
8959
|
throwIfSignalAborted(signal);
|
|
8587
8960
|
const { outcome, warnings } = normalizeAdapterImportResult(rawResult);
|
|
8588
|
-
const candidateSnapshot = outcome.mode === "snapshot" ?
|
|
8961
|
+
const candidateSnapshot = outcome.mode === "snapshot" ? Tools7.deepClone(outcome.snapshot) : buildOverlayImportCandidateSnapshot(baseSnapshot, outcome);
|
|
8589
8962
|
throwIfSignalAborted(signal);
|
|
8590
8963
|
return {
|
|
8591
8964
|
snapshot: candidateSnapshot,
|
|
@@ -8860,6 +9233,7 @@ var UniverPdfsPlugin = class extends Plugin {
|
|
|
8860
9233
|
SetPdfHeaderFooterConfigCommand,
|
|
8861
9234
|
SetPdfWatermarkConfigCommand,
|
|
8862
9235
|
SetPdfAttachmentsCommand,
|
|
9236
|
+
SetPdfSecurityConfigCommand,
|
|
8863
9237
|
AddPdfLayerCommand,
|
|
8864
9238
|
UpdatePdfLayerCommand,
|
|
8865
9239
|
RemovePdfLayerCommand,
|
|
@@ -8917,6 +9291,7 @@ export {
|
|
|
8917
9291
|
PDF_JSX_ELEMENT_SYMBOL,
|
|
8918
9292
|
PDF_JSX_FRAGMENT_SYMBOL,
|
|
8919
9293
|
PDF_PAGE_PRESETS,
|
|
9294
|
+
PDF_PASSWORD_PADDING,
|
|
8920
9295
|
PDF_S1_S7_FIDELITY_EXPECTATIONS,
|
|
8921
9296
|
PDF_TABLE_THEME_PRESETS,
|
|
8922
9297
|
PT_PER_MM,
|
|
@@ -8931,6 +9306,7 @@ export {
|
|
|
8931
9306
|
PdfListKind,
|
|
8932
9307
|
PdfListPresetId,
|
|
8933
9308
|
PdfRenderError,
|
|
9309
|
+
PdfSecurityError,
|
|
8934
9310
|
PdfSelectionService,
|
|
8935
9311
|
PdfTableBorderStyle,
|
|
8936
9312
|
PdfTableCellVerticalAlign,
|
|
@@ -8959,6 +9335,7 @@ export {
|
|
|
8959
9335
|
SetPdfNativeTextSpansCommand,
|
|
8960
9336
|
SetPdfPageCropBoxCommand,
|
|
8961
9337
|
SetPdfPageSizeCommand,
|
|
9338
|
+
SetPdfSecurityConfigCommand,
|
|
8962
9339
|
SetPdfWatermarkConfigCommand,
|
|
8963
9340
|
Spacer,
|
|
8964
9341
|
Stack,
|
|
@@ -8978,10 +9355,13 @@ export {
|
|
|
8978
9355
|
UpdatePdfUnitPropsCommand,
|
|
8979
9356
|
UpdatePdfUnitPropsMutation,
|
|
8980
9357
|
applyOcrToUnitPage,
|
|
9358
|
+
applyPdfSecurityToDocument,
|
|
8981
9359
|
autoDetectFormFieldsOnPage,
|
|
8982
9360
|
buildMinimalTestTrueTypeFont,
|
|
9361
|
+
buildObjectEncryptionKey,
|
|
8983
9362
|
buildOverlayImportCandidateSnapshot,
|
|
8984
9363
|
buildPdfTemplateFromOcrFields,
|
|
9364
|
+
bytesToHex,
|
|
8985
9365
|
calculatePdfTableRowCapacity,
|
|
8986
9366
|
canonicalJsonStringify,
|
|
8987
9367
|
clearPdfFontUrlCache,
|
|
@@ -9000,12 +9380,15 @@ export {
|
|
|
9000
9380
|
computeExifTransformMatrix,
|
|
9001
9381
|
computeExpandedTextHeightMm,
|
|
9002
9382
|
computeExpandedTextHeightPt,
|
|
9383
|
+
computeFileEncryptionKeyFromPadded,
|
|
9003
9384
|
computeFontUrlCacheKey,
|
|
9004
9385
|
computeImageFitPlacement,
|
|
9386
|
+
computeOwnerPasswordValue,
|
|
9005
9387
|
computePasteCascadeOffset,
|
|
9006
9388
|
computePdfPayloadDigest,
|
|
9007
9389
|
computePdfTableSummaryRow,
|
|
9008
9390
|
computeSmartSnapWithEqualGap,
|
|
9391
|
+
computeUserPasswordValue,
|
|
9009
9392
|
convertImagesToPdfBytes,
|
|
9010
9393
|
convertMarkdownToPdfBytes,
|
|
9011
9394
|
convertMarkdownToPdfUnit,
|
|
@@ -9022,6 +9405,8 @@ export {
|
|
|
9022
9405
|
createPdfBrowserFidelitySamples,
|
|
9023
9406
|
createPdfCjkFontSources,
|
|
9024
9407
|
createPdfJsxNode,
|
|
9408
|
+
decodePdfPermissionFlags,
|
|
9409
|
+
decryptPdfBytes,
|
|
9025
9410
|
detectCJKCharacters,
|
|
9026
9411
|
detectCJKInPdfInputs,
|
|
9027
9412
|
detectCJKInPdfTemplate,
|
|
@@ -9042,9 +9427,11 @@ export {
|
|
|
9042
9427
|
encodeJapanPost,
|
|
9043
9428
|
encodeNw7,
|
|
9044
9429
|
encodePdf417,
|
|
9430
|
+
encodePdfPermissionFlags,
|
|
9045
9431
|
encodeQrCodeMatrix,
|
|
9046
9432
|
encodeUpcA,
|
|
9047
9433
|
encodeUpcE,
|
|
9434
|
+
encryptPdfBytes,
|
|
9048
9435
|
evaluatePdfFormExpression,
|
|
9049
9436
|
evaluatePdfJsxElement,
|
|
9050
9437
|
evaluateSafeTemplateExpression,
|
|
@@ -9056,6 +9443,7 @@ export {
|
|
|
9056
9443
|
exportPdfBytes,
|
|
9057
9444
|
exportPdfToDocxSnapshot,
|
|
9058
9445
|
exportPdfToWorkbookSnapshot,
|
|
9446
|
+
exportPdfUnitToBytes,
|
|
9059
9447
|
exportPdfWithTarget,
|
|
9060
9448
|
exportSignedPdfWithAuditSeal,
|
|
9061
9449
|
exportToPdfmeTemplate,
|
|
@@ -9075,13 +9463,16 @@ export {
|
|
|
9075
9463
|
getDefaultDateTimeFormat,
|
|
9076
9464
|
getRegisteredOcrAdapter,
|
|
9077
9465
|
getTrueTypeMappedCodePoints,
|
|
9466
|
+
hexToBytes,
|
|
9078
9467
|
importAcroFormPdfToUnit,
|
|
9079
9468
|
importFormDataFromFdf,
|
|
9080
9469
|
importFormDataFromXfdf,
|
|
9081
9470
|
importFromPdfmeTemplate,
|
|
9471
|
+
importPdfBytesToUnit,
|
|
9082
9472
|
importPdfSource,
|
|
9083
9473
|
insertPdfPagesBytes,
|
|
9084
9474
|
inspectPdfBytePageSizes,
|
|
9475
|
+
inspectPdfEncryption,
|
|
9085
9476
|
inspectPdfExportCapabilities,
|
|
9086
9477
|
inspectTrueTypeFont,
|
|
9087
9478
|
isAspectRatioLockedBarcodeType,
|
|
@@ -9089,10 +9480,12 @@ export {
|
|
|
9089
9480
|
isExifDimensionsSwapped,
|
|
9090
9481
|
isFontUrlSafeToFetch,
|
|
9091
9482
|
isPdfJsxNode,
|
|
9483
|
+
isPdfSecurityActive,
|
|
9092
9484
|
jsx,
|
|
9093
9485
|
jsxDEV,
|
|
9094
9486
|
jsxs,
|
|
9095
9487
|
mayBeJson,
|
|
9488
|
+
md5Bytes,
|
|
9096
9489
|
mergePdfBytes,
|
|
9097
9490
|
mmToPt,
|
|
9098
9491
|
movePdfPageBytes,
|
|
@@ -9103,6 +9496,7 @@ export {
|
|
|
9103
9496
|
optimizePdfUnit,
|
|
9104
9497
|
organizePdfBytes,
|
|
9105
9498
|
overlayDiagnosticGridOnPdfBytes,
|
|
9499
|
+
padPdfPassword,
|
|
9106
9500
|
paginatePdfListItems,
|
|
9107
9501
|
paginatePdfTableRows,
|
|
9108
9502
|
parseGs1ApplicationIdentifiers,
|
|
@@ -9115,6 +9509,7 @@ export {
|
|
|
9115
9509
|
parseSvgToVectorCommands,
|
|
9116
9510
|
parseSvgTransformAttr,
|
|
9117
9511
|
ptToMm,
|
|
9512
|
+
rc4Bytes,
|
|
9118
9513
|
readJpegExifOrientation,
|
|
9119
9514
|
recalculatePdfFormFields,
|
|
9120
9515
|
rectsIntersect,
|
|
@@ -9165,6 +9560,7 @@ export {
|
|
|
9165
9560
|
validatePdfInputContract,
|
|
9166
9561
|
validatePdfTemplateSchema,
|
|
9167
9562
|
validatePdfTemplateVariables,
|
|
9563
|
+
verifyAndDecryptPdfBytes,
|
|
9168
9564
|
verifyPdfAuditSeal as verifyPdfAuditDigest,
|
|
9169
9565
|
verifyPdfAuditSeal,
|
|
9170
9566
|
verifyPdfUnitSignature,
|