@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/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_PASSWORD_PADDING: () => PDF_PASSWORD_PADDING,
|
|
80
81
|
PDF_S1_S7_FIDELITY_EXPECTATIONS: () => PDF_S1_S7_FIDELITY_EXPECTATIONS,
|
|
81
82
|
PDF_TABLE_THEME_PRESETS: () => PDF_TABLE_THEME_PRESETS,
|
|
82
83
|
PT_PER_MM: () => PT_PER_MM,
|
|
@@ -91,6 +92,7 @@ __export(src_exports, {
|
|
|
91
92
|
PdfListKind: () => PdfListKind,
|
|
92
93
|
PdfListPresetId: () => PdfListPresetId,
|
|
93
94
|
PdfRenderError: () => PdfRenderError,
|
|
95
|
+
PdfSecurityError: () => PdfSecurityError,
|
|
94
96
|
PdfSelectionService: () => PdfSelectionService,
|
|
95
97
|
PdfTableBorderStyle: () => PdfTableBorderStyle,
|
|
96
98
|
PdfTableCellVerticalAlign: () => PdfTableCellVerticalAlign,
|
|
@@ -119,6 +121,7 @@ __export(src_exports, {
|
|
|
119
121
|
SetPdfNativeTextSpansCommand: () => SetPdfNativeTextSpansCommand,
|
|
120
122
|
SetPdfPageCropBoxCommand: () => SetPdfPageCropBoxCommand,
|
|
121
123
|
SetPdfPageSizeCommand: () => SetPdfPageSizeCommand,
|
|
124
|
+
SetPdfSecurityConfigCommand: () => SetPdfSecurityConfigCommand,
|
|
122
125
|
SetPdfWatermarkConfigCommand: () => SetPdfWatermarkConfigCommand,
|
|
123
126
|
Spacer: () => Spacer,
|
|
124
127
|
Stack: () => Stack,
|
|
@@ -138,10 +141,13 @@ __export(src_exports, {
|
|
|
138
141
|
UpdatePdfUnitPropsCommand: () => UpdatePdfUnitPropsCommand,
|
|
139
142
|
UpdatePdfUnitPropsMutation: () => UpdatePdfUnitPropsMutation,
|
|
140
143
|
applyOcrToUnitPage: () => applyOcrToUnitPage,
|
|
144
|
+
applyPdfSecurityToDocument: () => applyPdfSecurityToDocument,
|
|
141
145
|
autoDetectFormFieldsOnPage: () => autoDetectFormFieldsOnPage,
|
|
142
146
|
buildMinimalTestTrueTypeFont: () => buildMinimalTestTrueTypeFont,
|
|
147
|
+
buildObjectEncryptionKey: () => buildObjectEncryptionKey,
|
|
143
148
|
buildOverlayImportCandidateSnapshot: () => buildOverlayImportCandidateSnapshot,
|
|
144
149
|
buildPdfTemplateFromOcrFields: () => buildPdfTemplateFromOcrFields,
|
|
150
|
+
bytesToHex: () => bytesToHex,
|
|
145
151
|
calculatePdfTableRowCapacity: () => calculatePdfTableRowCapacity,
|
|
146
152
|
canonicalJsonStringify: () => canonicalJsonStringify,
|
|
147
153
|
clearPdfFontUrlCache: () => clearPdfFontUrlCache,
|
|
@@ -160,12 +166,15 @@ __export(src_exports, {
|
|
|
160
166
|
computeExifTransformMatrix: () => computeExifTransformMatrix,
|
|
161
167
|
computeExpandedTextHeightMm: () => computeExpandedTextHeightMm,
|
|
162
168
|
computeExpandedTextHeightPt: () => computeExpandedTextHeightPt,
|
|
169
|
+
computeFileEncryptionKeyFromPadded: () => computeFileEncryptionKeyFromPadded,
|
|
163
170
|
computeFontUrlCacheKey: () => computeFontUrlCacheKey,
|
|
164
171
|
computeImageFitPlacement: () => computeImageFitPlacement,
|
|
172
|
+
computeOwnerPasswordValue: () => computeOwnerPasswordValue,
|
|
165
173
|
computePasteCascadeOffset: () => computePasteCascadeOffset,
|
|
166
174
|
computePdfPayloadDigest: () => computePdfPayloadDigest,
|
|
167
175
|
computePdfTableSummaryRow: () => computePdfTableSummaryRow,
|
|
168
176
|
computeSmartSnapWithEqualGap: () => computeSmartSnapWithEqualGap,
|
|
177
|
+
computeUserPasswordValue: () => computeUserPasswordValue,
|
|
169
178
|
convertImagesToPdfBytes: () => convertImagesToPdfBytes,
|
|
170
179
|
convertMarkdownToPdfBytes: () => convertMarkdownToPdfBytes,
|
|
171
180
|
convertMarkdownToPdfUnit: () => convertMarkdownToPdfUnit,
|
|
@@ -182,6 +191,8 @@ __export(src_exports, {
|
|
|
182
191
|
createPdfBrowserFidelitySamples: () => createPdfBrowserFidelitySamples,
|
|
183
192
|
createPdfCjkFontSources: () => createPdfCjkFontSources,
|
|
184
193
|
createPdfJsxNode: () => createPdfJsxNode,
|
|
194
|
+
decodePdfPermissionFlags: () => decodePdfPermissionFlags,
|
|
195
|
+
decryptPdfBytes: () => decryptPdfBytes,
|
|
185
196
|
detectCJKCharacters: () => detectCJKCharacters,
|
|
186
197
|
detectCJKInPdfInputs: () => detectCJKInPdfInputs,
|
|
187
198
|
detectCJKInPdfTemplate: () => detectCJKInPdfTemplate,
|
|
@@ -202,9 +213,11 @@ __export(src_exports, {
|
|
|
202
213
|
encodeJapanPost: () => encodeJapanPost,
|
|
203
214
|
encodeNw7: () => encodeNw7,
|
|
204
215
|
encodePdf417: () => encodePdf417,
|
|
216
|
+
encodePdfPermissionFlags: () => encodePdfPermissionFlags,
|
|
205
217
|
encodeQrCodeMatrix: () => encodeQrCodeMatrix,
|
|
206
218
|
encodeUpcA: () => encodeUpcA,
|
|
207
219
|
encodeUpcE: () => encodeUpcE,
|
|
220
|
+
encryptPdfBytes: () => encryptPdfBytes,
|
|
208
221
|
evaluatePdfFormExpression: () => evaluatePdfFormExpression,
|
|
209
222
|
evaluatePdfJsxElement: () => evaluatePdfJsxElement,
|
|
210
223
|
evaluateSafeTemplateExpression: () => evaluateSafeTemplateExpression,
|
|
@@ -216,6 +229,7 @@ __export(src_exports, {
|
|
|
216
229
|
exportPdfBytes: () => exportPdfBytes,
|
|
217
230
|
exportPdfToDocxSnapshot: () => exportPdfToDocxSnapshot,
|
|
218
231
|
exportPdfToWorkbookSnapshot: () => exportPdfToWorkbookSnapshot,
|
|
232
|
+
exportPdfUnitToBytes: () => exportPdfUnitToBytes,
|
|
219
233
|
exportPdfWithTarget: () => exportPdfWithTarget,
|
|
220
234
|
exportSignedPdfWithAuditSeal: () => exportSignedPdfWithAuditSeal,
|
|
221
235
|
exportToPdfmeTemplate: () => exportToPdfmeTemplate,
|
|
@@ -235,13 +249,16 @@ __export(src_exports, {
|
|
|
235
249
|
getDefaultDateTimeFormat: () => getDefaultDateTimeFormat,
|
|
236
250
|
getRegisteredOcrAdapter: () => getRegisteredOcrAdapter,
|
|
237
251
|
getTrueTypeMappedCodePoints: () => getTrueTypeMappedCodePoints,
|
|
252
|
+
hexToBytes: () => hexToBytes,
|
|
238
253
|
importAcroFormPdfToUnit: () => importAcroFormPdfToUnit,
|
|
239
254
|
importFormDataFromFdf: () => importFormDataFromFdf,
|
|
240
255
|
importFormDataFromXfdf: () => importFormDataFromXfdf,
|
|
241
256
|
importFromPdfmeTemplate: () => importFromPdfmeTemplate,
|
|
257
|
+
importPdfBytesToUnit: () => importPdfBytesToUnit,
|
|
242
258
|
importPdfSource: () => importPdfSource,
|
|
243
259
|
insertPdfPagesBytes: () => insertPdfPagesBytes,
|
|
244
260
|
inspectPdfBytePageSizes: () => inspectPdfBytePageSizes,
|
|
261
|
+
inspectPdfEncryption: () => inspectPdfEncryption,
|
|
245
262
|
inspectPdfExportCapabilities: () => inspectPdfExportCapabilities,
|
|
246
263
|
inspectTrueTypeFont: () => inspectTrueTypeFont,
|
|
247
264
|
isAspectRatioLockedBarcodeType: () => isAspectRatioLockedBarcodeType,
|
|
@@ -249,10 +266,12 @@ __export(src_exports, {
|
|
|
249
266
|
isExifDimensionsSwapped: () => isExifDimensionsSwapped,
|
|
250
267
|
isFontUrlSafeToFetch: () => isFontUrlSafeToFetch,
|
|
251
268
|
isPdfJsxNode: () => isPdfJsxNode,
|
|
269
|
+
isPdfSecurityActive: () => isPdfSecurityActive,
|
|
252
270
|
jsx: () => jsx,
|
|
253
271
|
jsxDEV: () => jsxDEV,
|
|
254
272
|
jsxs: () => jsxs,
|
|
255
273
|
mayBeJson: () => mayBeJson,
|
|
274
|
+
md5Bytes: () => md5Bytes,
|
|
256
275
|
mergePdfBytes: () => mergePdfBytes,
|
|
257
276
|
mmToPt: () => mmToPt,
|
|
258
277
|
movePdfPageBytes: () => movePdfPageBytes,
|
|
@@ -263,6 +282,7 @@ __export(src_exports, {
|
|
|
263
282
|
optimizePdfUnit: () => optimizePdfUnit,
|
|
264
283
|
organizePdfBytes: () => organizePdfBytes,
|
|
265
284
|
overlayDiagnosticGridOnPdfBytes: () => overlayDiagnosticGridOnPdfBytes,
|
|
285
|
+
padPdfPassword: () => padPdfPassword,
|
|
266
286
|
paginatePdfListItems: () => paginatePdfListItems,
|
|
267
287
|
paginatePdfTableRows: () => paginatePdfTableRows,
|
|
268
288
|
parseGs1ApplicationIdentifiers: () => parseGs1ApplicationIdentifiers,
|
|
@@ -275,6 +295,7 @@ __export(src_exports, {
|
|
|
275
295
|
parseSvgToVectorCommands: () => parseSvgToVectorCommands,
|
|
276
296
|
parseSvgTransformAttr: () => parseSvgTransformAttr,
|
|
277
297
|
ptToMm: () => ptToMm,
|
|
298
|
+
rc4Bytes: () => rc4Bytes,
|
|
278
299
|
readJpegExifOrientation: () => readJpegExifOrientation,
|
|
279
300
|
recalculatePdfFormFields: () => recalculatePdfFormFields,
|
|
280
301
|
rectsIntersect: () => rectsIntersect,
|
|
@@ -325,6 +346,7 @@ __export(src_exports, {
|
|
|
325
346
|
validatePdfInputContract: () => validatePdfInputContract,
|
|
326
347
|
validatePdfTemplateSchema: () => validatePdfTemplateSchema,
|
|
327
348
|
validatePdfTemplateVariables: () => validatePdfTemplateVariables,
|
|
349
|
+
verifyAndDecryptPdfBytes: () => verifyAndDecryptPdfBytes,
|
|
328
350
|
verifyPdfAuditDigest: () => verifyPdfAuditSeal,
|
|
329
351
|
verifyPdfAuditSeal: () => verifyPdfAuditSeal,
|
|
330
352
|
verifyPdfUnitSignature: () => verifyPdfUnitSignature,
|
|
@@ -573,7 +595,9 @@ function createDefaultPdfUnitData(partial) {
|
|
|
573
595
|
nativeTextSpansByPage: partial?.editState?.nativeTextSpansByPage ? import_core.Tools.deepClone(partial.editState.nativeTextSpansByPage) : partial?.metadata?.nativeTextSpansByPage ? import_core.Tools.deepClone(partial.metadata.nativeTextSpansByPage) : void 0
|
|
574
596
|
},
|
|
575
597
|
...partial?.layers !== void 0 ? { layers: import_core.Tools.deepClone(partial.layers) } : {},
|
|
598
|
+
...partial?.bookmarks !== void 0 ? { bookmarks: import_core.Tools.deepClone(partial.bookmarks) } : partial?.metadata?.bookmarks !== void 0 ? { bookmarks: import_core.Tools.deepClone(partial.metadata.bookmarks) } : {},
|
|
576
599
|
...partial?.attachments !== void 0 ? { attachments: import_core.Tools.deepClone(partial.attachments) } : {},
|
|
600
|
+
...partial?.security !== void 0 ? { security: import_core.Tools.deepClone(partial.security) } : partial?.metadata?.security !== void 0 ? { security: import_core.Tools.deepClone(partial.metadata.security) } : {},
|
|
577
601
|
...partial?.securityPermissions !== void 0 ? { securityPermissions: import_core.Tools.deepClone(partial.securityPermissions) } : {},
|
|
578
602
|
...partial?.signatureEnvelope !== void 0 ? { signatureEnvelope: import_core.Tools.deepClone(partial.signatureEnvelope) } : {},
|
|
579
603
|
...partial?.pdfACompliant !== void 0 ? { pdfACompliant: partial.pdfACompliant } : {},
|
|
@@ -806,9 +830,33 @@ var PdfUnitModel = class extends import_core.UnitModel {
|
|
|
806
830
|
if (patch.layers !== void 0) {
|
|
807
831
|
this._snapshot.layers = patch.layers ? import_core.Tools.deepClone(patch.layers) : void 0;
|
|
808
832
|
}
|
|
833
|
+
if (patch.bookmarks !== void 0) {
|
|
834
|
+
this._snapshot.bookmarks = patch.bookmarks ? import_core.Tools.deepClone(patch.bookmarks) : void 0;
|
|
835
|
+
if (!this._snapshot.metadata) {
|
|
836
|
+
this._snapshot.metadata = {};
|
|
837
|
+
}
|
|
838
|
+
if (patch.bookmarks && patch.bookmarks.length > 0) {
|
|
839
|
+
this._snapshot.metadata.bookmarks = import_core.Tools.deepClone(patch.bookmarks);
|
|
840
|
+
} else if (patch.bookmarks === null || Array.isArray(patch.bookmarks) && patch.bookmarks.length === 0) {
|
|
841
|
+
if (patch.bookmarks === null) {
|
|
842
|
+
delete this._snapshot.metadata.bookmarks;
|
|
843
|
+
} else {
|
|
844
|
+
this._snapshot.metadata.bookmarks = [];
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
} else if (patch.metadata !== void 0) {
|
|
848
|
+
if (this._snapshot.metadata?.bookmarks !== void 0) {
|
|
849
|
+
this._snapshot.bookmarks = import_core.Tools.deepClone(this._snapshot.metadata.bookmarks);
|
|
850
|
+
} else if (patch.replaceMetadata) {
|
|
851
|
+
delete this._snapshot.bookmarks;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
809
854
|
if (patch.attachments !== void 0) {
|
|
810
855
|
this._snapshot.attachments = patch.attachments ? import_core.Tools.deepClone(patch.attachments) : void 0;
|
|
811
856
|
}
|
|
857
|
+
if (patch.security !== void 0) {
|
|
858
|
+
this._snapshot.security = patch.security ? import_core.Tools.deepClone(patch.security) : void 0;
|
|
859
|
+
}
|
|
812
860
|
if (patch.securityPermissions !== void 0) {
|
|
813
861
|
this._snapshot.securityPermissions = patch.securityPermissions ? import_core.Tools.deepClone(patch.securityPermissions) : void 0;
|
|
814
862
|
}
|
|
@@ -3973,6 +4021,13 @@ var PdfSelectionService = class extends import_core4.Disposable {
|
|
|
3973
4021
|
this.viewportRatio$ = this._viewportRatio$.asObservable();
|
|
3974
4022
|
this._previewOpen$ = new import_rxjs2.BehaviorSubject(false);
|
|
3975
4023
|
this.previewOpen$ = this._previewOpen$.asObservable();
|
|
4024
|
+
this._findReplaceOpen$ = new import_rxjs2.BehaviorSubject(false);
|
|
4025
|
+
this.findReplaceOpen$ = this._findReplaceOpen$.asObservable();
|
|
4026
|
+
this._searchHighlight$ = new import_rxjs2.BehaviorSubject(null);
|
|
4027
|
+
this.searchHighlight$ = this._searchHighlight$.asObservable();
|
|
4028
|
+
this._scrollSeq = 0;
|
|
4029
|
+
this._scrollTarget$ = new import_rxjs2.BehaviorSubject(null);
|
|
4030
|
+
this.scrollTarget$ = this._scrollTarget$.asObservable();
|
|
3976
4031
|
this._clipboard$ = new import_rxjs2.BehaviorSubject([]);
|
|
3977
4032
|
this.clipboard$ = this._clipboard$.asObservable();
|
|
3978
4033
|
const sub = this._univerInstanceService.getCurrentTypeOfUnit$(import_core4.UniverInstanceType.UNIVER_PDF).subscribe((unit) => {
|
|
@@ -4012,6 +4067,9 @@ var PdfSelectionService = class extends import_core4.Disposable {
|
|
|
4012
4067
|
this._inkColor$.complete();
|
|
4013
4068
|
this._viewportRatio$.complete();
|
|
4014
4069
|
this._previewOpen$.complete();
|
|
4070
|
+
this._findReplaceOpen$.complete();
|
|
4071
|
+
this._searchHighlight$.complete();
|
|
4072
|
+
this._scrollTarget$.complete();
|
|
4015
4073
|
this._clipboard$.complete();
|
|
4016
4074
|
}
|
|
4017
4075
|
getState() {
|
|
@@ -4149,6 +4207,29 @@ var PdfSelectionService = class extends import_core4.Disposable {
|
|
|
4149
4207
|
setPreviewOpen(open) {
|
|
4150
4208
|
this._previewOpen$.next(open);
|
|
4151
4209
|
}
|
|
4210
|
+
getFindReplaceOpen() {
|
|
4211
|
+
return this._findReplaceOpen$.getValue();
|
|
4212
|
+
}
|
|
4213
|
+
setFindReplaceOpen(open) {
|
|
4214
|
+
this._findReplaceOpen$.next(open);
|
|
4215
|
+
if (!open) {
|
|
4216
|
+
this._searchHighlight$.next(null);
|
|
4217
|
+
}
|
|
4218
|
+
}
|
|
4219
|
+
getSearchHighlight() {
|
|
4220
|
+
return this._searchHighlight$.getValue();
|
|
4221
|
+
}
|
|
4222
|
+
setSearchHighlight(highlight) {
|
|
4223
|
+
this._searchHighlight$.next(highlight);
|
|
4224
|
+
}
|
|
4225
|
+
requestScrollToTopPt(topPt, pageId) {
|
|
4226
|
+
this._scrollSeq += 1;
|
|
4227
|
+
this._scrollTarget$.next({
|
|
4228
|
+
pageId,
|
|
4229
|
+
topPt: Math.max(0, Number(topPt) || 0),
|
|
4230
|
+
seq: this._scrollSeq
|
|
4231
|
+
});
|
|
4232
|
+
}
|
|
4152
4233
|
setClipboard(elements) {
|
|
4153
4234
|
this._pasteStep = 0;
|
|
4154
4235
|
this._clipboard$.next(elements);
|
|
@@ -5409,7 +5490,9 @@ var ReplacePdfSnapshotCommand = {
|
|
|
5409
5490
|
document: next.document,
|
|
5410
5491
|
editState: next.editState,
|
|
5411
5492
|
layers: next.layers ?? null,
|
|
5493
|
+
bookmarks: next.bookmarks ?? next.metadata?.bookmarks ?? null,
|
|
5412
5494
|
attachments: next.attachments ?? null,
|
|
5495
|
+
security: next.security ?? next.metadata?.security ?? null,
|
|
5413
5496
|
securityPermissions: next.securityPermissions ?? null,
|
|
5414
5497
|
signatureEnvelope: next.signatureEnvelope ?? null,
|
|
5415
5498
|
pdfACompliant: next.pdfACompliant ?? null,
|
|
@@ -5424,7 +5507,9 @@ var ReplacePdfSnapshotCommand = {
|
|
|
5424
5507
|
document: prev.document,
|
|
5425
5508
|
editState: prev.editState,
|
|
5426
5509
|
layers: prev.layers ?? null,
|
|
5510
|
+
bookmarks: prev.bookmarks ?? prev.metadata?.bookmarks ?? null,
|
|
5427
5511
|
attachments: prev.attachments ?? null,
|
|
5512
|
+
security: prev.security ?? prev.metadata?.security ?? null,
|
|
5428
5513
|
securityPermissions: prev.securityPermissions ?? null,
|
|
5429
5514
|
signatureEnvelope: prev.signatureEnvelope ?? null,
|
|
5430
5515
|
pdfACompliant: prev.pdfACompliant ?? null,
|
|
@@ -5805,15 +5890,26 @@ var SetPdfBookmarksCommand = {
|
|
|
5805
5890
|
handler: (accessor, params) => {
|
|
5806
5891
|
const ctx = resolveContext(accessor, params?.unitId);
|
|
5807
5892
|
if (!ctx || !Array.isArray(params?.bookmarks)) return false;
|
|
5808
|
-
const
|
|
5893
|
+
const prevSnap = ctx.unit.save();
|
|
5894
|
+
const prevBookmarks = import_core6.Tools.deepClone(prevSnap.bookmarks ?? prevSnap.metadata?.bookmarks ?? []);
|
|
5895
|
+
const nextBookmarks = import_core6.Tools.deepClone(params.bookmarks);
|
|
5896
|
+
const prevMetadata = import_core6.Tools.deepClone(prevSnap.metadata ?? {});
|
|
5809
5897
|
const nextMetadata = {
|
|
5810
5898
|
...import_core6.Tools.deepClone(prevMetadata),
|
|
5811
|
-
bookmarks: import_core6.Tools.deepClone(
|
|
5899
|
+
bookmarks: import_core6.Tools.deepClone(nextBookmarks)
|
|
5812
5900
|
};
|
|
5813
5901
|
const commandService = accessor.get(import_core6.ICommandService);
|
|
5814
5902
|
const undoRedoService = accessor.get(import_core6.IUndoRedoService);
|
|
5815
|
-
const redoPatch = {
|
|
5816
|
-
|
|
5903
|
+
const redoPatch = {
|
|
5904
|
+
bookmarks: nextBookmarks,
|
|
5905
|
+
metadata: nextMetadata,
|
|
5906
|
+
replaceMetadata: true
|
|
5907
|
+
};
|
|
5908
|
+
const undoPatch = {
|
|
5909
|
+
bookmarks: prevSnap.bookmarks !== void 0 || prevSnap.metadata?.bookmarks !== void 0 ? prevBookmarks : null,
|
|
5910
|
+
metadata: prevMetadata,
|
|
5911
|
+
replaceMetadata: true
|
|
5912
|
+
};
|
|
5817
5913
|
const result = commandService.syncExecuteCommand(UpdatePdfUnitPropsMutation.id, {
|
|
5818
5914
|
unitId: ctx.unitId,
|
|
5819
5915
|
patch: redoPatch
|
|
@@ -6121,6 +6217,48 @@ var SetPdfAttachmentsCommand = {
|
|
|
6121
6217
|
return Boolean(result);
|
|
6122
6218
|
}
|
|
6123
6219
|
};
|
|
6220
|
+
var SetPdfSecurityConfigCommand = {
|
|
6221
|
+
id: "pdfs.command.set-security-config",
|
|
6222
|
+
type: import_core6.CommandType.COMMAND,
|
|
6223
|
+
handler: (accessor, params) => {
|
|
6224
|
+
const ctx = resolveContext(accessor, params?.unitId);
|
|
6225
|
+
if (!ctx) return false;
|
|
6226
|
+
const prevSnap = ctx.unit.save();
|
|
6227
|
+
const prevSecurity = prevSnap.security ?? prevSnap.metadata?.security ?? null;
|
|
6228
|
+
const nextSecurity = params?.security ? import_core6.Tools.deepClone(params.security) : null;
|
|
6229
|
+
const prevMetadata = import_core6.Tools.deepClone(prevSnap.metadata ?? {});
|
|
6230
|
+
const nextMetadata = import_core6.Tools.deepClone(prevMetadata);
|
|
6231
|
+
if (nextSecurity) {
|
|
6232
|
+
nextMetadata.security = import_core6.Tools.deepClone(nextSecurity);
|
|
6233
|
+
} else {
|
|
6234
|
+
delete nextMetadata.security;
|
|
6235
|
+
}
|
|
6236
|
+
const commandService = accessor.get(import_core6.ICommandService);
|
|
6237
|
+
const undoRedoService = accessor.get(import_core6.IUndoRedoService);
|
|
6238
|
+
const redoPatch = {
|
|
6239
|
+
security: nextSecurity,
|
|
6240
|
+
metadata: nextMetadata,
|
|
6241
|
+
replaceMetadata: true
|
|
6242
|
+
};
|
|
6243
|
+
const undoPatch = {
|
|
6244
|
+
security: prevSecurity ? import_core6.Tools.deepClone(prevSecurity) : null,
|
|
6245
|
+
metadata: prevMetadata,
|
|
6246
|
+
replaceMetadata: true
|
|
6247
|
+
};
|
|
6248
|
+
const result = commandService.syncExecuteCommand(UpdatePdfUnitPropsMutation.id, {
|
|
6249
|
+
unitId: ctx.unitId,
|
|
6250
|
+
patch: redoPatch
|
|
6251
|
+
});
|
|
6252
|
+
if (result) {
|
|
6253
|
+
undoRedoService.pushUndoRedo({
|
|
6254
|
+
unitID: ctx.unitId,
|
|
6255
|
+
undoMutations: [{ id: UpdatePdfUnitPropsMutation.id, params: { unitId: ctx.unitId, patch: undoPatch } }],
|
|
6256
|
+
redoMutations: [{ id: UpdatePdfUnitPropsMutation.id, params: { unitId: ctx.unitId, patch: redoPatch } }]
|
|
6257
|
+
});
|
|
6258
|
+
}
|
|
6259
|
+
return Boolean(result);
|
|
6260
|
+
}
|
|
6261
|
+
};
|
|
6124
6262
|
var UpdatePdfPagePropsCommand = {
|
|
6125
6263
|
id: "pdfs.command.update-page-props",
|
|
6126
6264
|
type: import_core6.CommandType.COMMAND,
|
|
@@ -6192,9 +6330,17 @@ var UpdatePdfUnitPropsCommand = {
|
|
|
6192
6330
|
if (rawPatch.layers !== void 0) {
|
|
6193
6331
|
undoPatch.layers = prevSnap.layers ? import_core6.Tools.deepClone(prevSnap.layers) : null;
|
|
6194
6332
|
}
|
|
6333
|
+
if (rawPatch.bookmarks !== void 0) {
|
|
6334
|
+
const prevBm = prevSnap.bookmarks ?? prevSnap.metadata?.bookmarks;
|
|
6335
|
+
undoPatch.bookmarks = prevBm ? import_core6.Tools.deepClone(prevBm) : null;
|
|
6336
|
+
}
|
|
6195
6337
|
if (rawPatch.attachments !== void 0) {
|
|
6196
6338
|
undoPatch.attachments = prevSnap.attachments ? import_core6.Tools.deepClone(prevSnap.attachments) : null;
|
|
6197
6339
|
}
|
|
6340
|
+
if (rawPatch.security !== void 0) {
|
|
6341
|
+
const prevSec = prevSnap.security ?? prevSnap.metadata?.security;
|
|
6342
|
+
undoPatch.security = prevSec ? import_core6.Tools.deepClone(prevSec) : null;
|
|
6343
|
+
}
|
|
6198
6344
|
if (rawPatch.securityPermissions !== void 0) {
|
|
6199
6345
|
undoPatch.securityPermissions = prevSnap.securityPermissions ? import_core6.Tools.deepClone(prevSnap.securityPermissions) : null;
|
|
6200
6346
|
}
|
|
@@ -6226,7 +6372,7 @@ var UpdatePdfUnitPropsCommand = {
|
|
|
6226
6372
|
|
|
6227
6373
|
// src/exporter/pdf-exporter.ts
|
|
6228
6374
|
var import_core7 = require("@univerjs/core");
|
|
6229
|
-
var
|
|
6375
|
+
var import_pdf_lib4 = require("pdf-lib");
|
|
6230
6376
|
var import_qrcode2 = __toESM(require("qrcode"));
|
|
6231
6377
|
|
|
6232
6378
|
// src/exporter/pdf-2d-barcodes.ts
|
|
@@ -8923,8 +9069,1010 @@ async function organizePdfBytes(pdfBytes, planOrOptions) {
|
|
|
8923
9069
|
return await outDoc.save();
|
|
8924
9070
|
}
|
|
8925
9071
|
|
|
8926
|
-
// src/exporter/pdf-
|
|
9072
|
+
// src/exporter/pdf-security.ts
|
|
8927
9073
|
var import_pdf_lib2 = require("pdf-lib");
|
|
9074
|
+
var PdfSecurityError = class extends Error {
|
|
9075
|
+
constructor(code, message) {
|
|
9076
|
+
super(message);
|
|
9077
|
+
this.name = "PdfSecurityError";
|
|
9078
|
+
this.code = code;
|
|
9079
|
+
}
|
|
9080
|
+
};
|
|
9081
|
+
var PDF_PASSWORD_PADDING = new Uint8Array([
|
|
9082
|
+
40,
|
|
9083
|
+
191,
|
|
9084
|
+
78,
|
|
9085
|
+
94,
|
|
9086
|
+
78,
|
|
9087
|
+
117,
|
|
9088
|
+
138,
|
|
9089
|
+
65,
|
|
9090
|
+
100,
|
|
9091
|
+
0,
|
|
9092
|
+
78,
|
|
9093
|
+
86,
|
|
9094
|
+
255,
|
|
9095
|
+
250,
|
|
9096
|
+
1,
|
|
9097
|
+
8,
|
|
9098
|
+
46,
|
|
9099
|
+
46,
|
|
9100
|
+
0,
|
|
9101
|
+
182,
|
|
9102
|
+
208,
|
|
9103
|
+
104,
|
|
9104
|
+
62,
|
|
9105
|
+
128,
|
|
9106
|
+
47,
|
|
9107
|
+
12,
|
|
9108
|
+
169,
|
|
9109
|
+
254,
|
|
9110
|
+
100,
|
|
9111
|
+
83,
|
|
9112
|
+
105,
|
|
9113
|
+
122
|
|
9114
|
+
]);
|
|
9115
|
+
var DEFAULT_ALL_PERMISSIONS = Object.freeze({
|
|
9116
|
+
print: true,
|
|
9117
|
+
highResPrint: true,
|
|
9118
|
+
modify: true,
|
|
9119
|
+
copy: true,
|
|
9120
|
+
annotate: true,
|
|
9121
|
+
fillForms: true,
|
|
9122
|
+
assemble: true
|
|
9123
|
+
});
|
|
9124
|
+
var MD5_SHIFTS = [
|
|
9125
|
+
7,
|
|
9126
|
+
12,
|
|
9127
|
+
17,
|
|
9128
|
+
22,
|
|
9129
|
+
7,
|
|
9130
|
+
12,
|
|
9131
|
+
17,
|
|
9132
|
+
22,
|
|
9133
|
+
7,
|
|
9134
|
+
12,
|
|
9135
|
+
17,
|
|
9136
|
+
22,
|
|
9137
|
+
7,
|
|
9138
|
+
12,
|
|
9139
|
+
17,
|
|
9140
|
+
22,
|
|
9141
|
+
5,
|
|
9142
|
+
9,
|
|
9143
|
+
14,
|
|
9144
|
+
20,
|
|
9145
|
+
5,
|
|
9146
|
+
9,
|
|
9147
|
+
14,
|
|
9148
|
+
20,
|
|
9149
|
+
5,
|
|
9150
|
+
9,
|
|
9151
|
+
14,
|
|
9152
|
+
20,
|
|
9153
|
+
5,
|
|
9154
|
+
9,
|
|
9155
|
+
14,
|
|
9156
|
+
20,
|
|
9157
|
+
4,
|
|
9158
|
+
11,
|
|
9159
|
+
16,
|
|
9160
|
+
23,
|
|
9161
|
+
4,
|
|
9162
|
+
11,
|
|
9163
|
+
16,
|
|
9164
|
+
23,
|
|
9165
|
+
4,
|
|
9166
|
+
11,
|
|
9167
|
+
16,
|
|
9168
|
+
23,
|
|
9169
|
+
4,
|
|
9170
|
+
11,
|
|
9171
|
+
16,
|
|
9172
|
+
23,
|
|
9173
|
+
6,
|
|
9174
|
+
10,
|
|
9175
|
+
15,
|
|
9176
|
+
21,
|
|
9177
|
+
6,
|
|
9178
|
+
10,
|
|
9179
|
+
15,
|
|
9180
|
+
21,
|
|
9181
|
+
6,
|
|
9182
|
+
10,
|
|
9183
|
+
15,
|
|
9184
|
+
21,
|
|
9185
|
+
6,
|
|
9186
|
+
10,
|
|
9187
|
+
15,
|
|
9188
|
+
21
|
|
9189
|
+
];
|
|
9190
|
+
var MD5_K = (() => {
|
|
9191
|
+
const table = new Uint32Array(64);
|
|
9192
|
+
for (let i = 0; i < 64; i++) {
|
|
9193
|
+
table[i] = Math.floor(Math.abs(Math.sin(i + 1)) * 4294967296) >>> 0;
|
|
9194
|
+
}
|
|
9195
|
+
return table;
|
|
9196
|
+
})();
|
|
9197
|
+
function rotl32(x, n) {
|
|
9198
|
+
return (x << n | x >>> 32 - n) >>> 0;
|
|
9199
|
+
}
|
|
9200
|
+
function md5Bytes(data) {
|
|
9201
|
+
const msgLen = data.byteLength;
|
|
9202
|
+
const rem = (msgLen + 9) % 64;
|
|
9203
|
+
const padZeroes = rem === 0 ? 0 : 64 - rem;
|
|
9204
|
+
const totalLen = msgLen + 9 + padZeroes;
|
|
9205
|
+
const buf = new Uint8Array(totalLen);
|
|
9206
|
+
buf.set(data, 0);
|
|
9207
|
+
buf[msgLen] = 128;
|
|
9208
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
9209
|
+
const bitLenLow = msgLen * 8 >>> 0;
|
|
9210
|
+
const bitLenHigh = Math.floor(msgLen * 8 / 4294967296) >>> 0;
|
|
9211
|
+
view.setUint32(totalLen - 8, bitLenLow, true);
|
|
9212
|
+
view.setUint32(totalLen - 4, bitLenHigh, true);
|
|
9213
|
+
let a0 = 1732584193;
|
|
9214
|
+
let b0 = 4023233417;
|
|
9215
|
+
let c0 = 2562383102;
|
|
9216
|
+
let d0 = 271733878;
|
|
9217
|
+
const M = new Uint32Array(16);
|
|
9218
|
+
for (let offset = 0; offset < totalLen; offset += 64) {
|
|
9219
|
+
for (let j = 0; j < 16; j++) {
|
|
9220
|
+
M[j] = view.getUint32(offset + j * 4, true);
|
|
9221
|
+
}
|
|
9222
|
+
let A = a0;
|
|
9223
|
+
let B = b0;
|
|
9224
|
+
let C = c0;
|
|
9225
|
+
let D = d0;
|
|
9226
|
+
for (let i = 0; i < 64; i++) {
|
|
9227
|
+
let F;
|
|
9228
|
+
let g;
|
|
9229
|
+
if (i < 16) {
|
|
9230
|
+
F = B & C | ~B & D;
|
|
9231
|
+
g = i;
|
|
9232
|
+
} else if (i < 32) {
|
|
9233
|
+
F = D & B | ~D & C;
|
|
9234
|
+
g = (5 * i + 1) % 16;
|
|
9235
|
+
} else if (i < 48) {
|
|
9236
|
+
F = B ^ C ^ D;
|
|
9237
|
+
g = (3 * i + 5) % 16;
|
|
9238
|
+
} else {
|
|
9239
|
+
F = C ^ (B | ~D);
|
|
9240
|
+
g = 7 * i % 16;
|
|
9241
|
+
}
|
|
9242
|
+
const sum = A + F + MD5_K[i] + M[g] >>> 0;
|
|
9243
|
+
A = D;
|
|
9244
|
+
D = C;
|
|
9245
|
+
C = B;
|
|
9246
|
+
B = B + rotl32(sum, MD5_SHIFTS[i]) >>> 0;
|
|
9247
|
+
}
|
|
9248
|
+
a0 = a0 + A >>> 0;
|
|
9249
|
+
b0 = b0 + B >>> 0;
|
|
9250
|
+
c0 = c0 + C >>> 0;
|
|
9251
|
+
d0 = d0 + D >>> 0;
|
|
9252
|
+
}
|
|
9253
|
+
const out = new Uint8Array(16);
|
|
9254
|
+
const outView = new DataView(out.buffer);
|
|
9255
|
+
outView.setUint32(0, a0, true);
|
|
9256
|
+
outView.setUint32(4, b0, true);
|
|
9257
|
+
outView.setUint32(8, c0, true);
|
|
9258
|
+
outView.setUint32(12, d0, true);
|
|
9259
|
+
return out;
|
|
9260
|
+
}
|
|
9261
|
+
function rc4Bytes(key, data) {
|
|
9262
|
+
const keyLen = key.byteLength;
|
|
9263
|
+
if (keyLen === 0) return data.slice();
|
|
9264
|
+
const S = new Uint8Array(256);
|
|
9265
|
+
for (let i2 = 0; i2 < 256; i2++) {
|
|
9266
|
+
S[i2] = i2;
|
|
9267
|
+
}
|
|
9268
|
+
let j = 0;
|
|
9269
|
+
for (let i2 = 0; i2 < 256; i2++) {
|
|
9270
|
+
j = j + S[i2] + key[i2 % keyLen] & 255;
|
|
9271
|
+
const tmp = S[i2];
|
|
9272
|
+
S[i2] = S[j];
|
|
9273
|
+
S[j] = tmp;
|
|
9274
|
+
}
|
|
9275
|
+
const out = new Uint8Array(data.byteLength);
|
|
9276
|
+
let i = 0;
|
|
9277
|
+
j = 0;
|
|
9278
|
+
for (let k = 0; k < data.byteLength; k++) {
|
|
9279
|
+
i = i + 1 & 255;
|
|
9280
|
+
j = j + S[i] & 255;
|
|
9281
|
+
const tmp = S[i];
|
|
9282
|
+
S[i] = S[j];
|
|
9283
|
+
S[j] = tmp;
|
|
9284
|
+
out[k] = data[k] ^ S[S[i] + S[j] & 255];
|
|
9285
|
+
}
|
|
9286
|
+
return out;
|
|
9287
|
+
}
|
|
9288
|
+
function bytesToHex(bytes) {
|
|
9289
|
+
let hex = "";
|
|
9290
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
9291
|
+
hex += bytes[i].toString(16).padStart(2, "0").toUpperCase();
|
|
9292
|
+
}
|
|
9293
|
+
return hex;
|
|
9294
|
+
}
|
|
9295
|
+
function hexToBytes(hexRaw) {
|
|
9296
|
+
const cleaned = hexRaw.replace(/\s+/g, "");
|
|
9297
|
+
const padded = cleaned.length % 2 === 1 ? `${cleaned}0` : cleaned;
|
|
9298
|
+
const out = new Uint8Array(padded.length / 2);
|
|
9299
|
+
for (let i = 0; i < out.byteLength; i++) {
|
|
9300
|
+
out[i] = parseInt(padded.slice(i * 2, i * 2 + 2), 16) || 0;
|
|
9301
|
+
}
|
|
9302
|
+
return out;
|
|
9303
|
+
}
|
|
9304
|
+
function encodePasswordToBytes(password) {
|
|
9305
|
+
if (!password) return new Uint8Array(0);
|
|
9306
|
+
let hasHighCodePoint = false;
|
|
9307
|
+
for (let i = 0; i < password.length; i++) {
|
|
9308
|
+
if (password.charCodeAt(i) > 255) {
|
|
9309
|
+
hasHighCodePoint = true;
|
|
9310
|
+
break;
|
|
9311
|
+
}
|
|
9312
|
+
}
|
|
9313
|
+
if (hasHighCodePoint) {
|
|
9314
|
+
return new TextEncoder().encode(password);
|
|
9315
|
+
}
|
|
9316
|
+
const out = new Uint8Array(password.length);
|
|
9317
|
+
for (let i = 0; i < password.length; i++) {
|
|
9318
|
+
out[i] = password.charCodeAt(i) & 255;
|
|
9319
|
+
}
|
|
9320
|
+
return out;
|
|
9321
|
+
}
|
|
9322
|
+
function padPdfPassword(password) {
|
|
9323
|
+
const raw = password instanceof Uint8Array ? password : encodePasswordToBytes(password);
|
|
9324
|
+
const out = new Uint8Array(32);
|
|
9325
|
+
const copyLen = Math.min(32, raw.byteLength);
|
|
9326
|
+
out.set(raw.subarray(0, copyLen), 0);
|
|
9327
|
+
if (copyLen < 32) {
|
|
9328
|
+
out.set(PDF_PASSWORD_PADDING.subarray(0, 32 - copyLen), copyLen);
|
|
9329
|
+
}
|
|
9330
|
+
return out;
|
|
9331
|
+
}
|
|
9332
|
+
function encodePdfPermissionFlags(permissions, revision = 3) {
|
|
9333
|
+
const allowPrint = permissions?.print !== false;
|
|
9334
|
+
const allowModify = permissions?.modify !== false;
|
|
9335
|
+
const allowCopy = permissions?.copy !== false;
|
|
9336
|
+
const allowAnnotate = permissions?.annotate !== false;
|
|
9337
|
+
const allowFillForms = permissions?.fillForms !== false;
|
|
9338
|
+
const allowAssemble = permissions?.assemble !== false;
|
|
9339
|
+
const allowHighResPrint = permissions?.highResPrint !== void 0 ? Boolean(permissions.highResPrint) : allowPrint;
|
|
9340
|
+
let mask = 4294963392 | 1 << 9;
|
|
9341
|
+
if (allowPrint) mask |= 1 << 2;
|
|
9342
|
+
if (allowModify) mask |= 1 << 3;
|
|
9343
|
+
if (allowCopy) mask |= 1 << 4;
|
|
9344
|
+
if (allowAnnotate) mask |= 1 << 5;
|
|
9345
|
+
if (revision >= 3) {
|
|
9346
|
+
if (allowFillForms) mask |= 1 << 8;
|
|
9347
|
+
if (allowAssemble) mask |= 1 << 10;
|
|
9348
|
+
if (allowHighResPrint && allowPrint) mask |= 1 << 11;
|
|
9349
|
+
} else {
|
|
9350
|
+
mask |= 1 << 8 | 1 << 10 | 1 << 11;
|
|
9351
|
+
}
|
|
9352
|
+
return mask | 0;
|
|
9353
|
+
}
|
|
9354
|
+
function decodePdfPermissionFlags(pMask, revision = 3) {
|
|
9355
|
+
const print = (pMask & 1 << 2) !== 0;
|
|
9356
|
+
const modify = (pMask & 1 << 3) !== 0;
|
|
9357
|
+
const copy = (pMask & 1 << 4) !== 0;
|
|
9358
|
+
const annotate = (pMask & 1 << 5) !== 0;
|
|
9359
|
+
const fillForms = revision >= 3 ? (pMask & 1 << 8) !== 0 : annotate;
|
|
9360
|
+
const assemble = revision >= 3 ? (pMask & 1 << 10) !== 0 : modify;
|
|
9361
|
+
const highResPrint = revision >= 3 ? print && (pMask & 1 << 11) !== 0 : print;
|
|
9362
|
+
return {
|
|
9363
|
+
print,
|
|
9364
|
+
highResPrint,
|
|
9365
|
+
modify,
|
|
9366
|
+
copy,
|
|
9367
|
+
annotate,
|
|
9368
|
+
fillForms,
|
|
9369
|
+
assemble
|
|
9370
|
+
};
|
|
9371
|
+
}
|
|
9372
|
+
function isPdfSecurityActive(security) {
|
|
9373
|
+
if (!security || security.enabled === false) return false;
|
|
9374
|
+
if (security.enabled === true) return true;
|
|
9375
|
+
if (security.userPassword && security.userPassword.length > 0) return true;
|
|
9376
|
+
if (security.ownerPassword && security.ownerPassword.length > 0) return true;
|
|
9377
|
+
if (security.permissions && Object.keys(security.permissions).length > 0) return true;
|
|
9378
|
+
return false;
|
|
9379
|
+
}
|
|
9380
|
+
function computeOwnerPasswordValue(userPassword, ownerPassword, revision, keyLengthBits) {
|
|
9381
|
+
const effectiveOwner = ownerPassword || userPassword || "";
|
|
9382
|
+
const ownerPad = padPdfPassword(effectiveOwner);
|
|
9383
|
+
let hash = md5Bytes(ownerPad);
|
|
9384
|
+
if (revision >= 3) {
|
|
9385
|
+
for (let i = 0; i < 50; i++) {
|
|
9386
|
+
hash = md5Bytes(hash);
|
|
9387
|
+
}
|
|
9388
|
+
}
|
|
9389
|
+
const keyByteLen = revision >= 3 ? Math.max(5, Math.min(16, keyLengthBits >>> 3)) : 5;
|
|
9390
|
+
const userPad = padPdfPassword(userPassword);
|
|
9391
|
+
let encrypted = rc4Bytes(hash.subarray(0, keyByteLen), userPad);
|
|
9392
|
+
if (revision >= 3) {
|
|
9393
|
+
const derivedKey = new Uint8Array(keyByteLen);
|
|
9394
|
+
for (let iter = 1; iter <= 19; iter++) {
|
|
9395
|
+
for (let k = 0; k < keyByteLen; k++) {
|
|
9396
|
+
derivedKey[k] = hash[k] ^ iter;
|
|
9397
|
+
}
|
|
9398
|
+
encrypted = rc4Bytes(derivedKey, encrypted);
|
|
9399
|
+
}
|
|
9400
|
+
}
|
|
9401
|
+
return encrypted;
|
|
9402
|
+
}
|
|
9403
|
+
function computeFileEncryptionKeyFromPadded(paddedUserPassword, oValue, pFlagsSigned, fileId, revision, keyLengthBits) {
|
|
9404
|
+
const buf = new Uint8Array(32 + oValue.byteLength + 4 + fileId.byteLength);
|
|
9405
|
+
let offset = 0;
|
|
9406
|
+
buf.set(paddedUserPassword.subarray(0, 32), offset);
|
|
9407
|
+
offset += 32;
|
|
9408
|
+
buf.set(oValue, offset);
|
|
9409
|
+
offset += oValue.byteLength;
|
|
9410
|
+
buf[offset++] = pFlagsSigned & 255;
|
|
9411
|
+
buf[offset++] = pFlagsSigned >>> 8 & 255;
|
|
9412
|
+
buf[offset++] = pFlagsSigned >>> 16 & 255;
|
|
9413
|
+
buf[offset++] = pFlagsSigned >>> 24 & 255;
|
|
9414
|
+
buf.set(fileId, offset);
|
|
9415
|
+
let hash = md5Bytes(buf);
|
|
9416
|
+
const keyByteLen = revision >= 3 ? Math.max(5, Math.min(16, keyLengthBits >>> 3)) : 5;
|
|
9417
|
+
if (revision >= 3) {
|
|
9418
|
+
for (let i = 0; i < 50; i++) {
|
|
9419
|
+
hash = md5Bytes(hash.subarray(0, keyByteLen));
|
|
9420
|
+
}
|
|
9421
|
+
}
|
|
9422
|
+
return hash.subarray(0, keyByteLen);
|
|
9423
|
+
}
|
|
9424
|
+
function computeUserPasswordValue(encryptionKey, fileId, revision) {
|
|
9425
|
+
if (revision === 2) {
|
|
9426
|
+
return rc4Bytes(encryptionKey, PDF_PASSWORD_PADDING);
|
|
9427
|
+
}
|
|
9428
|
+
const hashInput = new Uint8Array(32 + fileId.byteLength);
|
|
9429
|
+
hashInput.set(PDF_PASSWORD_PADDING, 0);
|
|
9430
|
+
hashInput.set(fileId, 32);
|
|
9431
|
+
let check = rc4Bytes(encryptionKey, md5Bytes(hashInput));
|
|
9432
|
+
const keyLen = encryptionKey.byteLength;
|
|
9433
|
+
const derivedKey = new Uint8Array(keyLen);
|
|
9434
|
+
for (let iter = 1; iter <= 19; iter++) {
|
|
9435
|
+
for (let k = 0; k < keyLen; k++) {
|
|
9436
|
+
derivedKey[k] = encryptionKey[k] ^ iter;
|
|
9437
|
+
}
|
|
9438
|
+
check = rc4Bytes(derivedKey, check);
|
|
9439
|
+
}
|
|
9440
|
+
const out = new Uint8Array(32);
|
|
9441
|
+
out.set(check.subarray(0, 16), 0);
|
|
9442
|
+
out.set(PDF_PASSWORD_PADDING.subarray(0, 16), 16);
|
|
9443
|
+
return out;
|
|
9444
|
+
}
|
|
9445
|
+
function authenticatePaddedUserPassword(paddedPassword, oValue, uValue, pFlagsSigned, fileId, revision, keyLengthBits) {
|
|
9446
|
+
const candidateKey = computeFileEncryptionKeyFromPadded(
|
|
9447
|
+
paddedPassword,
|
|
9448
|
+
oValue,
|
|
9449
|
+
pFlagsSigned,
|
|
9450
|
+
fileId,
|
|
9451
|
+
revision,
|
|
9452
|
+
keyLengthBits
|
|
9453
|
+
);
|
|
9454
|
+
const expectedU = computeUserPasswordValue(candidateKey, fileId, revision);
|
|
9455
|
+
const compareLen = revision >= 3 ? 16 : 32;
|
|
9456
|
+
if (uValue.byteLength < compareLen) return null;
|
|
9457
|
+
let diff = 0;
|
|
9458
|
+
for (let i = 0; i < compareLen; i++) {
|
|
9459
|
+
diff |= expectedU[i] ^ uValue[i];
|
|
9460
|
+
}
|
|
9461
|
+
return diff === 0 ? candidateKey : null;
|
|
9462
|
+
}
|
|
9463
|
+
function authenticateOwnerPassword(ownerPassword, oValue, uValue, pFlagsSigned, fileId, revision, keyLengthBits) {
|
|
9464
|
+
const ownerPad = padPdfPassword(ownerPassword);
|
|
9465
|
+
let hash = md5Bytes(ownerPad);
|
|
9466
|
+
if (revision >= 3) {
|
|
9467
|
+
for (let i = 0; i < 50; i++) {
|
|
9468
|
+
hash = md5Bytes(hash);
|
|
9469
|
+
}
|
|
9470
|
+
}
|
|
9471
|
+
const keyByteLen = revision >= 3 ? Math.max(5, Math.min(16, keyLengthBits >>> 3)) : 5;
|
|
9472
|
+
let recoveredUserPad;
|
|
9473
|
+
if (revision >= 3) {
|
|
9474
|
+
recoveredUserPad = oValue.slice(0, 32);
|
|
9475
|
+
const derivedKey = new Uint8Array(keyByteLen);
|
|
9476
|
+
for (let iter = 19; iter >= 0; iter--) {
|
|
9477
|
+
for (let k = 0; k < keyByteLen; k++) {
|
|
9478
|
+
derivedKey[k] = hash[k] ^ iter;
|
|
9479
|
+
}
|
|
9480
|
+
recoveredUserPad = rc4Bytes(derivedKey, recoveredUserPad);
|
|
9481
|
+
}
|
|
9482
|
+
} else {
|
|
9483
|
+
recoveredUserPad = rc4Bytes(hash.subarray(0, 5), oValue.subarray(0, 32));
|
|
9484
|
+
}
|
|
9485
|
+
return authenticatePaddedUserPassword(
|
|
9486
|
+
recoveredUserPad,
|
|
9487
|
+
oValue,
|
|
9488
|
+
uValue,
|
|
9489
|
+
pFlagsSigned,
|
|
9490
|
+
fileId,
|
|
9491
|
+
revision,
|
|
9492
|
+
keyLengthBits
|
|
9493
|
+
);
|
|
9494
|
+
}
|
|
9495
|
+
function buildObjectEncryptionKey(encryptionKey, objectNumber, generationNumber) {
|
|
9496
|
+
const n = encryptionKey.byteLength;
|
|
9497
|
+
const buf = new Uint8Array(n + 5);
|
|
9498
|
+
buf.set(encryptionKey, 0);
|
|
9499
|
+
buf[n] = objectNumber & 255;
|
|
9500
|
+
buf[n + 1] = objectNumber >>> 8 & 255;
|
|
9501
|
+
buf[n + 2] = objectNumber >>> 16 & 255;
|
|
9502
|
+
buf[n + 3] = generationNumber & 255;
|
|
9503
|
+
buf[n + 4] = generationNumber >>> 8 & 255;
|
|
9504
|
+
const digest = md5Bytes(buf);
|
|
9505
|
+
return digest.subarray(0, Math.min(n + 5, 16));
|
|
9506
|
+
}
|
|
9507
|
+
function decodePdfLiteralBodyBytes(body) {
|
|
9508
|
+
const bytes = [];
|
|
9509
|
+
for (let i = 0; i < body.length; i++) {
|
|
9510
|
+
const ch = body.charCodeAt(i) & 255;
|
|
9511
|
+
if (ch !== 92) {
|
|
9512
|
+
bytes.push(ch);
|
|
9513
|
+
continue;
|
|
9514
|
+
}
|
|
9515
|
+
if (i + 1 >= body.length) break;
|
|
9516
|
+
const next = body.charCodeAt(++i) & 255;
|
|
9517
|
+
if (next === 13) {
|
|
9518
|
+
if (i + 1 < body.length && (body.charCodeAt(i + 1) & 255) === 10) i++;
|
|
9519
|
+
} else if (next === 10) {
|
|
9520
|
+
} else if (next === 110) {
|
|
9521
|
+
bytes.push(10);
|
|
9522
|
+
} else if (next === 114) {
|
|
9523
|
+
bytes.push(13);
|
|
9524
|
+
} else if (next === 116) {
|
|
9525
|
+
bytes.push(9);
|
|
9526
|
+
} else if (next === 98) {
|
|
9527
|
+
bytes.push(8);
|
|
9528
|
+
} else if (next === 102) {
|
|
9529
|
+
bytes.push(12);
|
|
9530
|
+
} else if (next >= 48 && next <= 55) {
|
|
9531
|
+
let oct = String.fromCharCode(next);
|
|
9532
|
+
for (let k = 0; k < 2 && i + 1 < body.length; k++) {
|
|
9533
|
+
const peek = body.charCodeAt(i + 1) & 255;
|
|
9534
|
+
if (peek >= 48 && peek <= 55) {
|
|
9535
|
+
oct += String.fromCharCode(peek);
|
|
9536
|
+
i++;
|
|
9537
|
+
} else {
|
|
9538
|
+
break;
|
|
9539
|
+
}
|
|
9540
|
+
}
|
|
9541
|
+
bytes.push(parseInt(oct, 8) & 255);
|
|
9542
|
+
} else {
|
|
9543
|
+
bytes.push(next);
|
|
9544
|
+
}
|
|
9545
|
+
}
|
|
9546
|
+
return new Uint8Array(bytes);
|
|
9547
|
+
}
|
|
9548
|
+
function extractPdfStringRawBytes(strObj) {
|
|
9549
|
+
if (strObj instanceof import_pdf_lib2.PDFHexString) {
|
|
9550
|
+
return strObj.asBytes();
|
|
9551
|
+
}
|
|
9552
|
+
const serialized = strObj.asString();
|
|
9553
|
+
const inner = serialized.startsWith("(") && serialized.endsWith(")") ? serialized.slice(1, -1) : serialized;
|
|
9554
|
+
return decodePdfLiteralBodyBytes(inner);
|
|
9555
|
+
}
|
|
9556
|
+
function isSignatureDict(dict) {
|
|
9557
|
+
const typeVal = dict.get(import_pdf_lib2.PDFName.of("Type"));
|
|
9558
|
+
if (typeVal instanceof import_pdf_lib2.PDFName && typeVal.asString() === "/Sig") return true;
|
|
9559
|
+
const ftVal = dict.get(import_pdf_lib2.PDFName.of("FT"));
|
|
9560
|
+
if (ftVal instanceof import_pdf_lib2.PDFName && ftVal.asString() === "/Sig") return true;
|
|
9561
|
+
return false;
|
|
9562
|
+
}
|
|
9563
|
+
function transformPdfObjectStringsWithRc4(obj, objKey) {
|
|
9564
|
+
if (obj instanceof import_pdf_lib2.PDFHexString || obj instanceof import_pdf_lib2.PDFString) {
|
|
9565
|
+
const raw = extractPdfStringRawBytes(obj);
|
|
9566
|
+
const transformed = rc4Bytes(objKey, raw);
|
|
9567
|
+
return import_pdf_lib2.PDFHexString.of(bytesToHex(transformed));
|
|
9568
|
+
}
|
|
9569
|
+
if (obj instanceof import_pdf_lib2.PDFArray) {
|
|
9570
|
+
for (let i = 0; i < obj.size(); i++) {
|
|
9571
|
+
const item = obj.get(i);
|
|
9572
|
+
const next = transformPdfObjectStringsWithRc4(item, objKey);
|
|
9573
|
+
if (next !== item) {
|
|
9574
|
+
obj.set(i, next);
|
|
9575
|
+
}
|
|
9576
|
+
}
|
|
9577
|
+
return obj;
|
|
9578
|
+
}
|
|
9579
|
+
if (obj instanceof import_pdf_lib2.PDFDict) {
|
|
9580
|
+
const isSig = isSignatureDict(obj);
|
|
9581
|
+
for (const [key, val] of obj.entries()) {
|
|
9582
|
+
if (isSig && key.asString() === "/Contents") {
|
|
9583
|
+
continue;
|
|
9584
|
+
}
|
|
9585
|
+
const next = transformPdfObjectStringsWithRc4(val, objKey);
|
|
9586
|
+
if (next !== val) {
|
|
9587
|
+
obj.set(key, next);
|
|
9588
|
+
}
|
|
9589
|
+
}
|
|
9590
|
+
return obj;
|
|
9591
|
+
}
|
|
9592
|
+
return obj;
|
|
9593
|
+
}
|
|
9594
|
+
function extractOrCreateDocumentFileId(pdfDoc) {
|
|
9595
|
+
const existingId = pdfDoc.context.trailerInfo.ID;
|
|
9596
|
+
if (existingId) {
|
|
9597
|
+
const idArr = existingId instanceof import_pdf_lib2.PDFArray ? existingId : pdfDoc.context.lookupMaybe(existingId, import_pdf_lib2.PDFArray);
|
|
9598
|
+
if (idArr && idArr.size() > 0) {
|
|
9599
|
+
const first = idArr.get(0);
|
|
9600
|
+
if (first instanceof import_pdf_lib2.PDFHexString || first instanceof import_pdf_lib2.PDFString) {
|
|
9601
|
+
const bytes = extractPdfStringRawBytes(first);
|
|
9602
|
+
if (bytes.byteLength > 0) {
|
|
9603
|
+
const hex = bytesToHex(bytes);
|
|
9604
|
+
pdfDoc.context.trailerInfo.ID = pdfDoc.context.obj([
|
|
9605
|
+
import_pdf_lib2.PDFHexString.of(hex),
|
|
9606
|
+
import_pdf_lib2.PDFHexString.of(hex)
|
|
9607
|
+
]);
|
|
9608
|
+
return bytes;
|
|
9609
|
+
}
|
|
9610
|
+
}
|
|
9611
|
+
}
|
|
9612
|
+
}
|
|
9613
|
+
const seedBytes = new Uint8Array(32);
|
|
9614
|
+
if (typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.getRandomValues === "function") {
|
|
9615
|
+
globalThis.crypto.getRandomValues(seedBytes);
|
|
9616
|
+
} else {
|
|
9617
|
+
const fallbackText = `univer-pdf-${Date.now()}-${Math.random()}-${pdfDoc.getPageCount()}`;
|
|
9618
|
+
const enc = new TextEncoder().encode(fallbackText);
|
|
9619
|
+
seedBytes.set(enc.subarray(0, Math.min(32, enc.byteLength)));
|
|
9620
|
+
}
|
|
9621
|
+
const fileId = md5Bytes(seedBytes);
|
|
9622
|
+
const idHex = bytesToHex(fileId);
|
|
9623
|
+
pdfDoc.context.trailerInfo.ID = pdfDoc.context.obj([
|
|
9624
|
+
import_pdf_lib2.PDFHexString.of(idHex),
|
|
9625
|
+
import_pdf_lib2.PDFHexString.of(idHex)
|
|
9626
|
+
]);
|
|
9627
|
+
return fileId;
|
|
9628
|
+
}
|
|
9629
|
+
async function applyPdfSecurityToDocument(pdfDoc, security) {
|
|
9630
|
+
if (security.enabled === false) return;
|
|
9631
|
+
await pdfDoc.flush();
|
|
9632
|
+
const keyLength = security.keyLength === 40 ? 40 : 128;
|
|
9633
|
+
const version = keyLength === 40 ? 1 : 2;
|
|
9634
|
+
const revision = keyLength === 40 ? 2 : 3;
|
|
9635
|
+
const userPassword = security.userPassword ?? "";
|
|
9636
|
+
const ownerPassword = security.ownerPassword && security.ownerPassword.length > 0 ? security.ownerPassword : userPassword.length > 0 ? userPassword : "univer-pdf-owner-guard";
|
|
9637
|
+
const fileId = extractOrCreateDocumentFileId(pdfDoc);
|
|
9638
|
+
const pSigned = encodePdfPermissionFlags(security.permissions, revision);
|
|
9639
|
+
const oBytes = computeOwnerPasswordValue(userPassword, ownerPassword, revision, keyLength);
|
|
9640
|
+
const encryptionKey = computeFileEncryptionKeyFromPadded(
|
|
9641
|
+
padPdfPassword(userPassword),
|
|
9642
|
+
oBytes,
|
|
9643
|
+
pSigned,
|
|
9644
|
+
fileId,
|
|
9645
|
+
revision,
|
|
9646
|
+
keyLength
|
|
9647
|
+
);
|
|
9648
|
+
const uBytes = computeUserPasswordValue(encryptionKey, fileId, revision);
|
|
9649
|
+
const idRef = pdfDoc.context.trailerInfo.ID instanceof import_pdf_lib2.PDFRef ? pdfDoc.context.trailerInfo.ID : null;
|
|
9650
|
+
for (const [ref, obj] of pdfDoc.context.enumerateIndirectObjects()) {
|
|
9651
|
+
if (idRef && ref.objectNumber === idRef.objectNumber && ref.generationNumber === idRef.generationNumber) {
|
|
9652
|
+
continue;
|
|
9653
|
+
}
|
|
9654
|
+
const objKey = buildObjectEncryptionKey(encryptionKey, ref.objectNumber, ref.generationNumber);
|
|
9655
|
+
if (obj instanceof import_pdf_lib2.PDFRawStream) {
|
|
9656
|
+
transformPdfObjectStringsWithRc4(obj.dict, objKey);
|
|
9657
|
+
const encryptedStream = rc4Bytes(objKey, obj.contents);
|
|
9658
|
+
obj.dict.set(import_pdf_lib2.PDFName.of("Length"), import_pdf_lib2.PDFNumber.of(encryptedStream.byteLength));
|
|
9659
|
+
pdfDoc.context.assign(ref, import_pdf_lib2.PDFRawStream.of(obj.dict, encryptedStream));
|
|
9660
|
+
} else if (obj instanceof import_pdf_lib2.PDFStream) {
|
|
9661
|
+
transformPdfObjectStringsWithRc4(obj.dict, objKey);
|
|
9662
|
+
const encodedContents = obj.getContents();
|
|
9663
|
+
const encryptedStream = rc4Bytes(objKey, encodedContents);
|
|
9664
|
+
obj.dict.set(import_pdf_lib2.PDFName.of("Length"), import_pdf_lib2.PDFNumber.of(encryptedStream.byteLength));
|
|
9665
|
+
pdfDoc.context.assign(ref, import_pdf_lib2.PDFRawStream.of(obj.dict, encryptedStream));
|
|
9666
|
+
} else {
|
|
9667
|
+
const next = transformPdfObjectStringsWithRc4(obj, objKey);
|
|
9668
|
+
if (next !== obj) {
|
|
9669
|
+
pdfDoc.context.assign(ref, next);
|
|
9670
|
+
}
|
|
9671
|
+
}
|
|
9672
|
+
}
|
|
9673
|
+
const encryptDict = pdfDoc.context.obj({
|
|
9674
|
+
Filter: import_pdf_lib2.PDFName.of("Standard"),
|
|
9675
|
+
V: import_pdf_lib2.PDFNumber.of(version),
|
|
9676
|
+
R: import_pdf_lib2.PDFNumber.of(revision),
|
|
9677
|
+
Length: import_pdf_lib2.PDFNumber.of(keyLength),
|
|
9678
|
+
P: import_pdf_lib2.PDFNumber.of(pSigned),
|
|
9679
|
+
O: import_pdf_lib2.PDFHexString.of(bytesToHex(oBytes)),
|
|
9680
|
+
U: import_pdf_lib2.PDFHexString.of(bytesToHex(uBytes))
|
|
9681
|
+
});
|
|
9682
|
+
const encryptRef = pdfDoc.context.register(encryptDict);
|
|
9683
|
+
pdfDoc.context.trailerInfo.Encrypt = encryptRef;
|
|
9684
|
+
}
|
|
9685
|
+
async function encryptPdfBytes(pdfBytes, security) {
|
|
9686
|
+
if (!security || security.enabled === false) {
|
|
9687
|
+
return pdfBytes.slice();
|
|
9688
|
+
}
|
|
9689
|
+
const cleanBytes = inspectPdfEncryption(pdfBytes).encrypted ? await decryptPdfBytes(pdfBytes, security.ownerPassword || security.userPassword || "") : pdfBytes;
|
|
9690
|
+
const pdfDoc = await import_pdf_lib2.PDFDocument.load(cleanBytes, { updateMetadata: false });
|
|
9691
|
+
await applyPdfSecurityToDocument(pdfDoc, security);
|
|
9692
|
+
return await pdfDoc.save({ useObjectStreams: false, updateFieldAppearances: false });
|
|
9693
|
+
}
|
|
9694
|
+
function bytesToLatin1(bytes) {
|
|
9695
|
+
let out = "";
|
|
9696
|
+
const chunk = 32768;
|
|
9697
|
+
for (let i = 0; i < bytes.byteLength; i += chunk) {
|
|
9698
|
+
out += String.fromCharCode(...bytes.subarray(i, i + chunk));
|
|
9699
|
+
}
|
|
9700
|
+
return out;
|
|
9701
|
+
}
|
|
9702
|
+
function extractBalancedPdfDict(text, startIdx) {
|
|
9703
|
+
const openIdx = text.indexOf("<<", startIdx);
|
|
9704
|
+
if (openIdx < 0) return null;
|
|
9705
|
+
let depth = 0;
|
|
9706
|
+
let inLiteral = false;
|
|
9707
|
+
let literalDepth = 0;
|
|
9708
|
+
for (let i = openIdx; i < text.length; i++) {
|
|
9709
|
+
const ch = text.charCodeAt(i);
|
|
9710
|
+
if (inLiteral) {
|
|
9711
|
+
if (ch === 92) {
|
|
9712
|
+
i++;
|
|
9713
|
+
continue;
|
|
9714
|
+
}
|
|
9715
|
+
if (ch === 40) literalDepth++;
|
|
9716
|
+
else if (ch === 41) {
|
|
9717
|
+
literalDepth--;
|
|
9718
|
+
if (literalDepth <= 0) {
|
|
9719
|
+
inLiteral = false;
|
|
9720
|
+
}
|
|
9721
|
+
}
|
|
9722
|
+
continue;
|
|
9723
|
+
}
|
|
9724
|
+
if (ch === 40) {
|
|
9725
|
+
inLiteral = true;
|
|
9726
|
+
literalDepth = 1;
|
|
9727
|
+
continue;
|
|
9728
|
+
}
|
|
9729
|
+
if (ch === 37) {
|
|
9730
|
+
while (i < text.length && text.charCodeAt(i) !== 10 && text.charCodeAt(i) !== 13) {
|
|
9731
|
+
i++;
|
|
9732
|
+
}
|
|
9733
|
+
continue;
|
|
9734
|
+
}
|
|
9735
|
+
if (ch === 60 && text.charCodeAt(i + 1) === 60) {
|
|
9736
|
+
depth++;
|
|
9737
|
+
i++;
|
|
9738
|
+
continue;
|
|
9739
|
+
}
|
|
9740
|
+
if (ch === 62 && text.charCodeAt(i + 1) === 62) {
|
|
9741
|
+
depth--;
|
|
9742
|
+
i++;
|
|
9743
|
+
if (depth === 0) {
|
|
9744
|
+
return text.slice(openIdx, i + 1);
|
|
9745
|
+
}
|
|
9746
|
+
}
|
|
9747
|
+
}
|
|
9748
|
+
return null;
|
|
9749
|
+
}
|
|
9750
|
+
function parsePdfStringTokenAfterKey(dictText, keyName) {
|
|
9751
|
+
const re = new RegExp(`\\/${keyName}(?![A-Za-z0-9_.+-])\\s*`);
|
|
9752
|
+
const match = re.exec(dictText);
|
|
9753
|
+
if (!match) return null;
|
|
9754
|
+
let pos = match.index + match[0].length;
|
|
9755
|
+
while (pos < dictText.length && /\s/.test(dictText[pos])) pos++;
|
|
9756
|
+
if (pos >= dictText.length) return null;
|
|
9757
|
+
if (dictText[pos] === "<" && dictText[pos + 1] !== "<") {
|
|
9758
|
+
const close = dictText.indexOf(">", pos + 1);
|
|
9759
|
+
if (close < 0) return null;
|
|
9760
|
+
return hexToBytes(dictText.slice(pos + 1, close));
|
|
9761
|
+
}
|
|
9762
|
+
if (dictText[pos] === "(") {
|
|
9763
|
+
let depth = 1;
|
|
9764
|
+
let i = pos + 1;
|
|
9765
|
+
while (i < dictText.length && depth > 0) {
|
|
9766
|
+
const ch = dictText.charCodeAt(i);
|
|
9767
|
+
if (ch === 92) {
|
|
9768
|
+
i += 2;
|
|
9769
|
+
continue;
|
|
9770
|
+
}
|
|
9771
|
+
if (ch === 40) depth++;
|
|
9772
|
+
else if (ch === 41) depth--;
|
|
9773
|
+
i++;
|
|
9774
|
+
}
|
|
9775
|
+
if (depth === 0) {
|
|
9776
|
+
return decodePdfLiteralBodyBytes(dictText.slice(pos + 1, i - 1));
|
|
9777
|
+
}
|
|
9778
|
+
}
|
|
9779
|
+
return null;
|
|
9780
|
+
}
|
|
9781
|
+
function parseFirstPdfArrayStringBytes(dictText, keyName) {
|
|
9782
|
+
const re = new RegExp(`\\/${keyName}(?![A-Za-z0-9_.+-])\\s*\\[`);
|
|
9783
|
+
const match = re.exec(dictText);
|
|
9784
|
+
if (!match) return null;
|
|
9785
|
+
let pos = match.index + match[0].length;
|
|
9786
|
+
while (pos < dictText.length && /\s/.test(dictText[pos])) pos++;
|
|
9787
|
+
if (pos >= dictText.length) return null;
|
|
9788
|
+
if (dictText[pos] === "<" && dictText[pos + 1] !== "<") {
|
|
9789
|
+
const close = dictText.indexOf(">", pos + 1);
|
|
9790
|
+
if (close >= 0) return hexToBytes(dictText.slice(pos + 1, close));
|
|
9791
|
+
} else if (dictText[pos] === "(") {
|
|
9792
|
+
let depth = 1;
|
|
9793
|
+
let i = pos + 1;
|
|
9794
|
+
while (i < dictText.length && depth > 0) {
|
|
9795
|
+
const ch = dictText.charCodeAt(i);
|
|
9796
|
+
if (ch === 92) {
|
|
9797
|
+
i += 2;
|
|
9798
|
+
continue;
|
|
9799
|
+
}
|
|
9800
|
+
if (ch === 40) depth++;
|
|
9801
|
+
else if (ch === 41) depth--;
|
|
9802
|
+
i++;
|
|
9803
|
+
}
|
|
9804
|
+
if (depth === 0) {
|
|
9805
|
+
return decodePdfLiteralBodyBytes(dictText.slice(pos + 1, i - 1));
|
|
9806
|
+
}
|
|
9807
|
+
}
|
|
9808
|
+
return null;
|
|
9809
|
+
}
|
|
9810
|
+
function parseRawEncryptFromPdfBytes(pdfBytes) {
|
|
9811
|
+
if (!pdfBytes || pdfBytes.byteLength < 16) return null;
|
|
9812
|
+
const rawText = bytesToLatin1(pdfBytes);
|
|
9813
|
+
let containerDict = null;
|
|
9814
|
+
let searchEnd = rawText.length;
|
|
9815
|
+
while (searchEnd > 0) {
|
|
9816
|
+
const trailerIdx = rawText.lastIndexOf("trailer", searchEnd - 1);
|
|
9817
|
+
if (trailerIdx < 0) break;
|
|
9818
|
+
const prevCh = trailerIdx > 0 ? rawText[trailerIdx - 1] : "\n";
|
|
9819
|
+
const afterCh = rawText[trailerIdx + 7] ?? " ";
|
|
9820
|
+
if (/[\s\r\n>]/.test(prevCh) && /[\s\r\n<]/.test(afterCh)) {
|
|
9821
|
+
const candidate = extractBalancedPdfDict(rawText, trailerIdx + 7);
|
|
9822
|
+
if (candidate && /\/Encrypt\b/.test(candidate)) {
|
|
9823
|
+
containerDict = candidate;
|
|
9824
|
+
break;
|
|
9825
|
+
}
|
|
9826
|
+
if (candidate && !containerDict) {
|
|
9827
|
+
containerDict = candidate;
|
|
9828
|
+
}
|
|
9829
|
+
}
|
|
9830
|
+
searchEnd = trailerIdx;
|
|
9831
|
+
}
|
|
9832
|
+
if (!containerDict || !/\/Encrypt\b/.test(containerDict)) {
|
|
9833
|
+
const xrefMatch = /<<[\s\S]{0,2048}?\/Type\s*\/XRef[\s\S]{0,2048}?>>/.exec(rawText);
|
|
9834
|
+
if (xrefMatch && /\/Encrypt\b/.test(xrefMatch[0])) {
|
|
9835
|
+
containerDict = xrefMatch[0];
|
|
9836
|
+
}
|
|
9837
|
+
}
|
|
9838
|
+
if (!containerDict || !/\/Encrypt\b/.test(containerDict)) {
|
|
9839
|
+
return null;
|
|
9840
|
+
}
|
|
9841
|
+
let encryptDictText = null;
|
|
9842
|
+
const refMatch = /\/Encrypt\s+(\d+)\s+(\d+)\s+R\b/.exec(containerDict);
|
|
9843
|
+
if (refMatch) {
|
|
9844
|
+
const objNum = refMatch[1];
|
|
9845
|
+
const genNum = refMatch[2];
|
|
9846
|
+
const objRe = new RegExp(`(?:^|[\\r\\n\\s])${objNum}\\s+${genNum}\\s+obj\\b`, "g");
|
|
9847
|
+
let lastObjMatch = null;
|
|
9848
|
+
let m;
|
|
9849
|
+
while ((m = objRe.exec(rawText)) !== null) {
|
|
9850
|
+
lastObjMatch = m;
|
|
9851
|
+
}
|
|
9852
|
+
if (lastObjMatch) {
|
|
9853
|
+
encryptDictText = extractBalancedPdfDict(rawText, lastObjMatch.index + lastObjMatch[0].length);
|
|
9854
|
+
}
|
|
9855
|
+
} else if (/\/Encrypt\s*<</.test(containerDict)) {
|
|
9856
|
+
const inlineIdx = containerDict.search(/\/Encrypt\s*<</);
|
|
9857
|
+
encryptDictText = extractBalancedPdfDict(containerDict, inlineIdx);
|
|
9858
|
+
}
|
|
9859
|
+
if (!encryptDictText) return null;
|
|
9860
|
+
const filterMatch = /\/Filter\s*\/([A-Za-z0-9_.+-]+)/.exec(encryptDictText);
|
|
9861
|
+
const vMatch = /\/V\s+(-?\d+)/.exec(encryptDictText);
|
|
9862
|
+
const rMatch = /\/R\s+(-?\d+)/.exec(encryptDictText);
|
|
9863
|
+
const lenMatch = /\/Length\s+(\d+)/.exec(encryptDictText);
|
|
9864
|
+
const pMatch = /\/P\s+(-?\d+)/.exec(encryptDictText);
|
|
9865
|
+
const filter = filterMatch ? filterMatch[1] : "Standard";
|
|
9866
|
+
const version = vMatch ? parseInt(vMatch[1], 10) : 1;
|
|
9867
|
+
const revision = rMatch ? parseInt(rMatch[1], 10) : version >= 2 ? 3 : 2;
|
|
9868
|
+
const keyLength = lenMatch ? parseInt(lenMatch[1], 10) : version >= 2 ? 128 : 40;
|
|
9869
|
+
const pSigned = pMatch ? parseInt(pMatch[1], 10) | 0 : -4;
|
|
9870
|
+
const oBytes = parsePdfStringTokenAfterKey(encryptDictText, "O") ?? new Uint8Array(0);
|
|
9871
|
+
const uBytes = parsePdfStringTokenAfterKey(encryptDictText, "U") ?? new Uint8Array(0);
|
|
9872
|
+
let fileId = parseFirstPdfArrayStringBytes(containerDict, "ID");
|
|
9873
|
+
if (!fileId) {
|
|
9874
|
+
const idRefMatch = /\/ID\s+(\d+)\s+(\d+)\s+R\b/.exec(containerDict);
|
|
9875
|
+
if (idRefMatch) {
|
|
9876
|
+
const idObjRe = new RegExp(`(?:^|[\\r\\n\\s])${idRefMatch[1]}\\s+${idRefMatch[2]}\\s+obj\\b([\\s\\S]{0,512}?)endobj`);
|
|
9877
|
+
const idObjM = idObjRe.exec(rawText);
|
|
9878
|
+
if (idObjM) {
|
|
9879
|
+
fileId = parseFirstPdfArrayStringBytes(`/ID ${idObjM[1]}`, "ID");
|
|
9880
|
+
}
|
|
9881
|
+
}
|
|
9882
|
+
}
|
|
9883
|
+
return {
|
|
9884
|
+
filter,
|
|
9885
|
+
version,
|
|
9886
|
+
revision,
|
|
9887
|
+
keyLength,
|
|
9888
|
+
pSigned,
|
|
9889
|
+
oBytes,
|
|
9890
|
+
uBytes,
|
|
9891
|
+
fileId: fileId ?? new Uint8Array(0)
|
|
9892
|
+
};
|
|
9893
|
+
}
|
|
9894
|
+
function extractEncryptMetadataFromDoc(doc) {
|
|
9895
|
+
const encEntry = doc.context.trailerInfo.Encrypt;
|
|
9896
|
+
if (!encEntry) return null;
|
|
9897
|
+
const encDict = encEntry instanceof import_pdf_lib2.PDFDict ? encEntry : doc.context.lookupMaybe(encEntry, import_pdf_lib2.PDFDict);
|
|
9898
|
+
if (!encDict) return null;
|
|
9899
|
+
const filterObj = encDict.get(import_pdf_lib2.PDFName.of("Filter"));
|
|
9900
|
+
const filter = filterObj instanceof import_pdf_lib2.PDFName ? filterObj.decodeText() : "Standard";
|
|
9901
|
+
const vObj = encDict.get(import_pdf_lib2.PDFName.of("V"));
|
|
9902
|
+
const version = vObj instanceof import_pdf_lib2.PDFNumber ? vObj.asNumber() : 1;
|
|
9903
|
+
const rObj = encDict.get(import_pdf_lib2.PDFName.of("R"));
|
|
9904
|
+
const revision = rObj instanceof import_pdf_lib2.PDFNumber ? rObj.asNumber() : version >= 2 ? 3 : 2;
|
|
9905
|
+
const lenObj = encDict.get(import_pdf_lib2.PDFName.of("Length"));
|
|
9906
|
+
const keyLength = lenObj instanceof import_pdf_lib2.PDFNumber ? lenObj.asNumber() : version >= 2 ? 128 : 40;
|
|
9907
|
+
const pObj = encDict.get(import_pdf_lib2.PDFName.of("P"));
|
|
9908
|
+
const pSigned = pObj instanceof import_pdf_lib2.PDFNumber ? pObj.asNumber() | 0 : -4;
|
|
9909
|
+
const oObj = encDict.get(import_pdf_lib2.PDFName.of("O"));
|
|
9910
|
+
const oBytes = oObj instanceof import_pdf_lib2.PDFHexString || oObj instanceof import_pdf_lib2.PDFString ? extractPdfStringRawBytes(oObj) : new Uint8Array(0);
|
|
9911
|
+
const uObj = encDict.get(import_pdf_lib2.PDFName.of("U"));
|
|
9912
|
+
const uBytes = uObj instanceof import_pdf_lib2.PDFHexString || uObj instanceof import_pdf_lib2.PDFString ? extractPdfStringRawBytes(uObj) : new Uint8Array(0);
|
|
9913
|
+
let fileId = new Uint8Array(0);
|
|
9914
|
+
const idEntry = doc.context.trailerInfo.ID;
|
|
9915
|
+
const idArr = idEntry instanceof import_pdf_lib2.PDFArray ? idEntry : doc.context.lookupMaybe(idEntry, import_pdf_lib2.PDFArray);
|
|
9916
|
+
if (idArr && idArr.size() > 0) {
|
|
9917
|
+
const first = idArr.get(0);
|
|
9918
|
+
if (first instanceof import_pdf_lib2.PDFHexString || first instanceof import_pdf_lib2.PDFString) {
|
|
9919
|
+
fileId = extractPdfStringRawBytes(first);
|
|
9920
|
+
}
|
|
9921
|
+
}
|
|
9922
|
+
return {
|
|
9923
|
+
filter,
|
|
9924
|
+
version,
|
|
9925
|
+
revision,
|
|
9926
|
+
keyLength,
|
|
9927
|
+
pSigned,
|
|
9928
|
+
oBytes,
|
|
9929
|
+
uBytes,
|
|
9930
|
+
fileId
|
|
9931
|
+
};
|
|
9932
|
+
}
|
|
9933
|
+
function inspectPdfEncryption(pdfBytes) {
|
|
9934
|
+
const meta = parseRawEncryptFromPdfBytes(pdfBytes);
|
|
9935
|
+
if (!meta) {
|
|
9936
|
+
return {
|
|
9937
|
+
encrypted: false,
|
|
9938
|
+
requiresOpenPassword: false,
|
|
9939
|
+
permissions: { ...DEFAULT_ALL_PERMISSIONS }
|
|
9940
|
+
};
|
|
9941
|
+
}
|
|
9942
|
+
let requiresOpenPassword = true;
|
|
9943
|
+
if (meta.filter === "Standard" && (meta.version === 1 || meta.version === 2) && (meta.revision === 2 || meta.revision === 3) && meta.oBytes.byteLength >= 32 && meta.uBytes.byteLength >= 16) {
|
|
9944
|
+
const emptyKey = authenticatePaddedUserPassword(
|
|
9945
|
+
padPdfPassword(""),
|
|
9946
|
+
meta.oBytes,
|
|
9947
|
+
meta.uBytes,
|
|
9948
|
+
meta.pSigned,
|
|
9949
|
+
meta.fileId,
|
|
9950
|
+
meta.revision,
|
|
9951
|
+
meta.keyLength
|
|
9952
|
+
);
|
|
9953
|
+
requiresOpenPassword = emptyKey === null;
|
|
9954
|
+
}
|
|
9955
|
+
return {
|
|
9956
|
+
encrypted: true,
|
|
9957
|
+
requiresOpenPassword,
|
|
9958
|
+
filter: meta.filter,
|
|
9959
|
+
version: meta.version,
|
|
9960
|
+
revision: meta.revision,
|
|
9961
|
+
keyLength: meta.keyLength,
|
|
9962
|
+
permissionFlagsRaw: meta.pSigned,
|
|
9963
|
+
permissions: decodePdfPermissionFlags(meta.pSigned, meta.revision)
|
|
9964
|
+
};
|
|
9965
|
+
}
|
|
9966
|
+
async function decryptPdfBytes(pdfBytes, password) {
|
|
9967
|
+
let meta = parseRawEncryptFromPdfBytes(pdfBytes);
|
|
9968
|
+
const doc = await import_pdf_lib2.PDFDocument.load(pdfBytes, {
|
|
9969
|
+
ignoreEncryption: true,
|
|
9970
|
+
updateMetadata: false
|
|
9971
|
+
});
|
|
9972
|
+
if (!meta && doc.isEncrypted) {
|
|
9973
|
+
meta = extractEncryptMetadataFromDoc(doc);
|
|
9974
|
+
}
|
|
9975
|
+
if (!meta) {
|
|
9976
|
+
return pdfBytes.slice();
|
|
9977
|
+
}
|
|
9978
|
+
if (meta.filter !== "Standard" || meta.version !== 1 && meta.version !== 2 || meta.revision !== 2 && meta.revision !== 3) {
|
|
9979
|
+
throw new PdfSecurityError(
|
|
9980
|
+
"PDF_UNSUPPORTED_ENCRYPTION",
|
|
9981
|
+
`Unsupported PDF encryption handler (Filter=/${meta.filter}, V=${meta.version}, R=${meta.revision}).`
|
|
9982
|
+
);
|
|
9983
|
+
}
|
|
9984
|
+
const rev = meta.revision;
|
|
9985
|
+
const emptyOpenKey = authenticatePaddedUserPassword(
|
|
9986
|
+
padPdfPassword(""),
|
|
9987
|
+
meta.oBytes,
|
|
9988
|
+
meta.uBytes,
|
|
9989
|
+
meta.pSigned,
|
|
9990
|
+
meta.fileId,
|
|
9991
|
+
rev,
|
|
9992
|
+
meta.keyLength
|
|
9993
|
+
);
|
|
9994
|
+
const requiresOpenPassword = emptyOpenKey === null;
|
|
9995
|
+
const candidatePw = password ?? "";
|
|
9996
|
+
if (requiresOpenPassword && candidatePw.length === 0) {
|
|
9997
|
+
throw new PdfSecurityError(
|
|
9998
|
+
"PDF_PASSWORD_REQUIRED",
|
|
9999
|
+
"Encrypted PDF document requires an open password."
|
|
10000
|
+
);
|
|
10001
|
+
}
|
|
10002
|
+
let encryptionKey = null;
|
|
10003
|
+
if (candidatePw.length === 0 && emptyOpenKey) {
|
|
10004
|
+
encryptionKey = emptyOpenKey;
|
|
10005
|
+
} else {
|
|
10006
|
+
encryptionKey = authenticatePaddedUserPassword(
|
|
10007
|
+
padPdfPassword(candidatePw),
|
|
10008
|
+
meta.oBytes,
|
|
10009
|
+
meta.uBytes,
|
|
10010
|
+
meta.pSigned,
|
|
10011
|
+
meta.fileId,
|
|
10012
|
+
rev,
|
|
10013
|
+
meta.keyLength
|
|
10014
|
+
);
|
|
10015
|
+
if (!encryptionKey) {
|
|
10016
|
+
encryptionKey = authenticateOwnerPassword(
|
|
10017
|
+
candidatePw,
|
|
10018
|
+
meta.oBytes,
|
|
10019
|
+
meta.uBytes,
|
|
10020
|
+
meta.pSigned,
|
|
10021
|
+
meta.fileId,
|
|
10022
|
+
rev,
|
|
10023
|
+
meta.keyLength
|
|
10024
|
+
);
|
|
10025
|
+
}
|
|
10026
|
+
}
|
|
10027
|
+
if (!encryptionKey) {
|
|
10028
|
+
throw new PdfSecurityError(
|
|
10029
|
+
"PDF_INVALID_PASSWORD",
|
|
10030
|
+
"Incorrect password for encrypted PDF document."
|
|
10031
|
+
);
|
|
10032
|
+
}
|
|
10033
|
+
const encryptRef = doc.context.trailerInfo.Encrypt instanceof import_pdf_lib2.PDFRef ? doc.context.trailerInfo.Encrypt : null;
|
|
10034
|
+
const idRef = doc.context.trailerInfo.ID instanceof import_pdf_lib2.PDFRef ? doc.context.trailerInfo.ID : null;
|
|
10035
|
+
for (const [ref, obj] of doc.context.enumerateIndirectObjects()) {
|
|
10036
|
+
if (encryptRef && ref.objectNumber === encryptRef.objectNumber && ref.generationNumber === encryptRef.generationNumber) {
|
|
10037
|
+
continue;
|
|
10038
|
+
}
|
|
10039
|
+
if (idRef && ref.objectNumber === idRef.objectNumber && ref.generationNumber === idRef.generationNumber) {
|
|
10040
|
+
continue;
|
|
10041
|
+
}
|
|
10042
|
+
const objKey = buildObjectEncryptionKey(encryptionKey, ref.objectNumber, ref.generationNumber);
|
|
10043
|
+
if (obj instanceof import_pdf_lib2.PDFRawStream) {
|
|
10044
|
+
transformPdfObjectStringsWithRc4(obj.dict, objKey);
|
|
10045
|
+
const decryptedStream = rc4Bytes(objKey, obj.contents);
|
|
10046
|
+
obj.dict.set(import_pdf_lib2.PDFName.of("Length"), import_pdf_lib2.PDFNumber.of(decryptedStream.byteLength));
|
|
10047
|
+
doc.context.assign(ref, import_pdf_lib2.PDFRawStream.of(obj.dict, decryptedStream));
|
|
10048
|
+
} else if (obj instanceof import_pdf_lib2.PDFStream) {
|
|
10049
|
+
transformPdfObjectStringsWithRc4(obj.dict, objKey);
|
|
10050
|
+
const decryptedStream = rc4Bytes(objKey, obj.getContents());
|
|
10051
|
+
obj.dict.set(import_pdf_lib2.PDFName.of("Length"), import_pdf_lib2.PDFNumber.of(decryptedStream.byteLength));
|
|
10052
|
+
doc.context.assign(ref, import_pdf_lib2.PDFRawStream.of(obj.dict, decryptedStream));
|
|
10053
|
+
} else {
|
|
10054
|
+
const next = transformPdfObjectStringsWithRc4(obj, objKey);
|
|
10055
|
+
if (next !== obj) {
|
|
10056
|
+
doc.context.assign(ref, next);
|
|
10057
|
+
}
|
|
10058
|
+
}
|
|
10059
|
+
}
|
|
10060
|
+
delete doc.context.trailerInfo.Encrypt;
|
|
10061
|
+
if (encryptRef) {
|
|
10062
|
+
doc.context.delete(encryptRef);
|
|
10063
|
+
}
|
|
10064
|
+
return await doc.save({ useObjectStreams: false, updateFieldAppearances: false });
|
|
10065
|
+
}
|
|
10066
|
+
async function verifyAndDecryptPdfBytes(pdfBytes, password) {
|
|
10067
|
+
const inspection = inspectPdfEncryption(pdfBytes);
|
|
10068
|
+
if (!inspection.encrypted) {
|
|
10069
|
+
return pdfBytes;
|
|
10070
|
+
}
|
|
10071
|
+
return decryptPdfBytes(pdfBytes, password);
|
|
10072
|
+
}
|
|
10073
|
+
|
|
10074
|
+
// src/exporter/pdf-svg-vector.ts
|
|
10075
|
+
var import_pdf_lib3 = require("pdf-lib");
|
|
8928
10076
|
function parseObjectPositionRatios(objectPosition) {
|
|
8929
10077
|
if (!objectPosition || !objectPosition.trim()) {
|
|
8930
10078
|
return { ax: 0.5, ayTop: 0.5 };
|
|
@@ -9027,12 +10175,12 @@ function computeElementCenterTransformMatrix(box, angleDeg = 0, flipX = false, f
|
|
|
9027
10175
|
function toPdfLibColor(parsed, colorType) {
|
|
9028
10176
|
if (colorType === "cmyk" || parsed.sourceSpace === "cmyk") {
|
|
9029
10177
|
if (typeof parsed.c === "number" && typeof parsed.m === "number" && typeof parsed.y === "number" && typeof parsed.k === "number") {
|
|
9030
|
-
return (0,
|
|
10178
|
+
return (0, import_pdf_lib3.cmyk)(parsed.c, parsed.m, parsed.y, parsed.k);
|
|
9031
10179
|
}
|
|
9032
10180
|
const conv = rgbToCmyk(parsed.r, parsed.g, parsed.b);
|
|
9033
|
-
return (0,
|
|
10181
|
+
return (0, import_pdf_lib3.cmyk)(conv.c, conv.m, conv.y, conv.k);
|
|
9034
10182
|
}
|
|
9035
|
-
return (0,
|
|
10183
|
+
return (0, import_pdf_lib3.rgb)(parsed.r, parsed.g, parsed.b);
|
|
9036
10184
|
}
|
|
9037
10185
|
function multiplySvgMat(m1, m2) {
|
|
9038
10186
|
return [
|
|
@@ -9568,7 +10716,7 @@ function drawVectorSvgOnPdfPage(pdfPage, pageHeight, left, top, width, height, s
|
|
|
9568
10716
|
const ops = parseSvgToVectorCommands(svgXml, width, height, opacity);
|
|
9569
10717
|
if (ops.length === 0) return 0;
|
|
9570
10718
|
const pdfY = pageHeight - top - height;
|
|
9571
|
-
pdfPage.pushOperators((0,
|
|
10719
|
+
pdfPage.pushOperators((0, import_pdf_lib3.pushGraphicsState)(), (0, import_pdf_lib3.rectangle)(left, pdfY, width, height), (0, import_pdf_lib3.clip)(), (0, import_pdf_lib3.endPath)());
|
|
9572
10720
|
try {
|
|
9573
10721
|
for (const op of ops) {
|
|
9574
10722
|
pdfPage.drawSvgPath(op.pathData, {
|
|
@@ -9583,7 +10731,7 @@ function drawVectorSvgOnPdfPage(pdfPage, pageHeight, left, top, width, height, s
|
|
|
9583
10731
|
});
|
|
9584
10732
|
}
|
|
9585
10733
|
} finally {
|
|
9586
|
-
pdfPage.pushOperators((0,
|
|
10734
|
+
pdfPage.pushOperators((0, import_pdf_lib3.popGraphicsState)());
|
|
9587
10735
|
}
|
|
9588
10736
|
return ops.length;
|
|
9589
10737
|
}
|
|
@@ -10040,8 +11188,8 @@ function registerSubsetType0FontInDoc(pdfDoc, fontBytes, usedCodePoints, fontTag
|
|
|
10040
11188
|
Subtype: "CIDFontType2",
|
|
10041
11189
|
BaseFont: fontTag,
|
|
10042
11190
|
CIDSystemInfo: {
|
|
10043
|
-
Registry:
|
|
10044
|
-
Ordering:
|
|
11191
|
+
Registry: import_pdf_lib4.PDFString.of("Adobe"),
|
|
11192
|
+
Ordering: import_pdf_lib4.PDFString.of("Identity"),
|
|
10045
11193
|
Supplement: 0
|
|
10046
11194
|
},
|
|
10047
11195
|
FontDescriptor: fontDescriptorRef,
|
|
@@ -10437,8 +11585,8 @@ function initVectorCjkEmbedState(pdfDoc, snapshot, effectiveData, options, preRe
|
|
|
10437
11585
|
Subtype: "CIDFontType2",
|
|
10438
11586
|
BaseFont: "STSong-Light",
|
|
10439
11587
|
CIDSystemInfo: {
|
|
10440
|
-
Registry:
|
|
10441
|
-
Ordering:
|
|
11588
|
+
Registry: import_pdf_lib4.PDFString.of("Adobe"),
|
|
11589
|
+
Ordering: import_pdf_lib4.PDFString.of("GB1"),
|
|
10442
11590
|
Supplement: 4
|
|
10443
11591
|
},
|
|
10444
11592
|
FontDescriptor: fontDescriptorRef,
|
|
@@ -10630,25 +11778,25 @@ function drawVectorCjkTextBox(page, pageHeight, text, left, top, width, height,
|
|
|
10630
11778
|
}
|
|
10631
11779
|
const fillOp = colorType === "cmyk" ? (() => {
|
|
10632
11780
|
const cm = rgbToCmyk(color.r, color.g, color.b);
|
|
10633
|
-
return (0,
|
|
10634
|
-
})() : (0,
|
|
11781
|
+
return (0, import_pdf_lib4.setFillingCmykColor)(cm.c, cm.m, cm.y, cm.k);
|
|
11782
|
+
})() : (0, import_pdf_lib4.setFillingRgbColor)(color.r, color.g, color.b);
|
|
10635
11783
|
const syntheticBoldOps = wantBold && !usedDedicatedBold ? [
|
|
10636
|
-
|
|
10637
|
-
(0,
|
|
11784
|
+
import_pdf_lib4.PDFOperator.of("Tr", [import_pdf_lib4.PDFNumber.of(2)]),
|
|
11785
|
+
(0, import_pdf_lib4.setLineWidth)(Math.max(0.25, fontSize * 0.032)),
|
|
10638
11786
|
colorType === "cmyk" ? (() => {
|
|
10639
11787
|
const cm = rgbToCmyk(color.r, color.g, color.b);
|
|
10640
|
-
return (0,
|
|
10641
|
-
})() : (0,
|
|
11788
|
+
return (0, import_pdf_lib4.setStrokingCmykColor)(cm.c, cm.m, cm.y, cm.k);
|
|
11789
|
+
})() : (0, import_pdf_lib4.setStrokingRgbColor)(color.r, color.g, color.b)
|
|
10642
11790
|
] : [];
|
|
10643
11791
|
const decoCol = toPdfLibColor(color, colorType);
|
|
10644
11792
|
const decoThickness = Math.max(0.6, fontSize * 0.065);
|
|
10645
11793
|
const applyClip = !noWrapSingleLine && width > 0 && height > 0;
|
|
10646
11794
|
if (applyClip) {
|
|
10647
11795
|
page.pushOperators(
|
|
10648
|
-
(0,
|
|
10649
|
-
(0,
|
|
10650
|
-
(0,
|
|
10651
|
-
(0,
|
|
11796
|
+
(0, import_pdf_lib4.pushGraphicsState)(),
|
|
11797
|
+
(0, import_pdf_lib4.rectangle)(left, pdfY, width, height),
|
|
11798
|
+
(0, import_pdf_lib4.clip)(),
|
|
11799
|
+
(0, import_pdf_lib4.endPath)()
|
|
10652
11800
|
);
|
|
10653
11801
|
}
|
|
10654
11802
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -10676,25 +11824,25 @@ function drawVectorCjkTextBox(page, pageHeight, text, left, top, width, height,
|
|
|
10676
11824
|
}
|
|
10677
11825
|
const hexStr = encodeVectorCjkLineHex(line, state, activeSubset);
|
|
10678
11826
|
const totalTc = charSpacing + extraJustifyTc;
|
|
10679
|
-
const posOp = style?.italic ?
|
|
10680
|
-
|
|
10681
|
-
|
|
10682
|
-
|
|
10683
|
-
|
|
10684
|
-
|
|
10685
|
-
|
|
10686
|
-
]) : (0,
|
|
11827
|
+
const posOp = style?.italic ? import_pdf_lib4.PDFOperator.of("Tm", [
|
|
11828
|
+
import_pdf_lib4.PDFNumber.of(1),
|
|
11829
|
+
import_pdf_lib4.PDFNumber.of(0),
|
|
11830
|
+
import_pdf_lib4.PDFNumber.of(0.2126),
|
|
11831
|
+
import_pdf_lib4.PDFNumber.of(1),
|
|
11832
|
+
import_pdf_lib4.PDFNumber.of(drawX),
|
|
11833
|
+
import_pdf_lib4.PDFNumber.of(drawY)
|
|
11834
|
+
]) : (0, import_pdf_lib4.moveText)(drawX, drawY);
|
|
10687
11835
|
page.pushOperators(
|
|
10688
|
-
(0,
|
|
10689
|
-
(0,
|
|
11836
|
+
(0, import_pdf_lib4.pushGraphicsState)(),
|
|
11837
|
+
(0, import_pdf_lib4.beginText)(),
|
|
10690
11838
|
fillOp,
|
|
10691
11839
|
...syntheticBoldOps,
|
|
10692
|
-
(0,
|
|
10693
|
-
...totalTc !== 0 ? [(0,
|
|
11840
|
+
(0, import_pdf_lib4.setFontAndSize)(fontKey, fontSize),
|
|
11841
|
+
...totalTc !== 0 ? [(0, import_pdf_lib4.setCharacterSpacing)(totalTc)] : [],
|
|
10694
11842
|
posOp,
|
|
10695
|
-
(0,
|
|
10696
|
-
(0,
|
|
10697
|
-
(0,
|
|
11843
|
+
(0, import_pdf_lib4.showText)(import_pdf_lib4.PDFHexString.of(hexStr)),
|
|
11844
|
+
(0, import_pdf_lib4.endText)(),
|
|
11845
|
+
(0, import_pdf_lib4.popGraphicsState)()
|
|
10698
11846
|
);
|
|
10699
11847
|
if (style?.underline) {
|
|
10700
11848
|
const ulY = drawY - fontSize * 0.12;
|
|
@@ -10718,7 +11866,7 @@ function drawVectorCjkTextBox(page, pageHeight, text, left, top, width, height,
|
|
|
10718
11866
|
}
|
|
10719
11867
|
}
|
|
10720
11868
|
if (applyClip) {
|
|
10721
|
-
page.pushOperators((0,
|
|
11869
|
+
page.pushOperators((0, import_pdf_lib4.popGraphicsState)());
|
|
10722
11870
|
}
|
|
10723
11871
|
}
|
|
10724
11872
|
function renderTextToPngBytesInBrowser(text, widthPt, heightPt, style) {
|
|
@@ -11077,21 +12225,21 @@ var STANDARD_FONT_CACHE = /* @__PURE__ */ new WeakMap();
|
|
|
11077
12225
|
function resolveStandardPdfFont(fontFamily, bold, italic) {
|
|
11078
12226
|
const fam = (fontFamily ?? "").toLowerCase();
|
|
11079
12227
|
if (fam.includes("courier") || fam.includes("mono") || fam.includes("consolas")) {
|
|
11080
|
-
if (bold && italic) return
|
|
11081
|
-
if (bold) return
|
|
11082
|
-
if (italic) return
|
|
11083
|
-
return
|
|
12228
|
+
if (bold && italic) return import_pdf_lib4.StandardFonts.CourierBoldOblique;
|
|
12229
|
+
if (bold) return import_pdf_lib4.StandardFonts.CourierBold;
|
|
12230
|
+
if (italic) return import_pdf_lib4.StandardFonts.CourierOblique;
|
|
12231
|
+
return import_pdf_lib4.StandardFonts.Courier;
|
|
11084
12232
|
}
|
|
11085
12233
|
if ((fam.includes("times") || fam.includes("serif") || fam.includes("georgia")) && !fam.includes("sans")) {
|
|
11086
|
-
if (bold && italic) return
|
|
11087
|
-
if (bold) return
|
|
11088
|
-
if (italic) return
|
|
11089
|
-
return
|
|
12234
|
+
if (bold && italic) return import_pdf_lib4.StandardFonts.TimesRomanBoldItalic;
|
|
12235
|
+
if (bold) return import_pdf_lib4.StandardFonts.TimesRomanBold;
|
|
12236
|
+
if (italic) return import_pdf_lib4.StandardFonts.TimesRomanItalic;
|
|
12237
|
+
return import_pdf_lib4.StandardFonts.TimesRoman;
|
|
11090
12238
|
}
|
|
11091
|
-
if (bold && italic) return
|
|
11092
|
-
if (bold) return
|
|
11093
|
-
if (italic) return
|
|
11094
|
-
return
|
|
12239
|
+
if (bold && italic) return import_pdf_lib4.StandardFonts.HelveticaBoldOblique;
|
|
12240
|
+
if (bold) return import_pdf_lib4.StandardFonts.HelveticaBold;
|
|
12241
|
+
if (italic) return import_pdf_lib4.StandardFonts.HelveticaOblique;
|
|
12242
|
+
return import_pdf_lib4.StandardFonts.Helvetica;
|
|
11095
12243
|
}
|
|
11096
12244
|
async function getOrEmbedStandardFont(pdfDoc, fontName) {
|
|
11097
12245
|
let docMap = STANDARD_FONT_CACHE.get(pdfDoc);
|
|
@@ -11234,10 +12382,10 @@ async function drawTextBox(pdfDoc, page, pageHeight, text, left, top, width, hei
|
|
|
11234
12382
|
const applyAsciiClip = !extraOpts?.noWrapSingleLine && bgWidth > 0 && height > 0;
|
|
11235
12383
|
if (applyAsciiClip) {
|
|
11236
12384
|
page.pushOperators(
|
|
11237
|
-
(0,
|
|
11238
|
-
(0,
|
|
11239
|
-
(0,
|
|
11240
|
-
(0,
|
|
12385
|
+
(0, import_pdf_lib4.pushGraphicsState)(),
|
|
12386
|
+
(0, import_pdf_lib4.rectangle)(left, pdfY, bgWidth, height),
|
|
12387
|
+
(0, import_pdf_lib4.clip)(),
|
|
12388
|
+
(0, import_pdf_lib4.endPath)()
|
|
11241
12389
|
);
|
|
11242
12390
|
}
|
|
11243
12391
|
for (let i = 0; i < wrappedLines.length; i++) {
|
|
@@ -11270,10 +12418,10 @@ async function drawTextBox(pdfDoc, page, pageHeight, text, left, top, width, hei
|
|
|
11270
12418
|
}
|
|
11271
12419
|
const totalTc = charSpacing + extraJustifyTc;
|
|
11272
12420
|
if (totalTc !== 0 || extraWordSpacing !== 0) {
|
|
11273
|
-
const ops = [(0,
|
|
11274
|
-
if (totalTc !== 0) ops.push((0,
|
|
12421
|
+
const ops = [(0, import_pdf_lib4.pushGraphicsState)()];
|
|
12422
|
+
if (totalTc !== 0) ops.push((0, import_pdf_lib4.setCharacterSpacing)(totalTc));
|
|
11275
12423
|
if (extraWordSpacing !== 0) {
|
|
11276
|
-
ops.push(
|
|
12424
|
+
ops.push(import_pdf_lib4.PDFOperator.of("Tw", [import_pdf_lib4.PDFNumber.of(extraWordSpacing)]));
|
|
11277
12425
|
}
|
|
11278
12426
|
page.pushOperators(...ops);
|
|
11279
12427
|
page.drawText(lineText, {
|
|
@@ -11284,7 +12432,7 @@ async function drawTextBox(pdfDoc, page, pageHeight, text, left, top, width, hei
|
|
|
11284
12432
|
color: pdfCol,
|
|
11285
12433
|
opacity: color.a
|
|
11286
12434
|
});
|
|
11287
|
-
page.pushOperators((0,
|
|
12435
|
+
page.pushOperators((0, import_pdf_lib4.popGraphicsState)());
|
|
11288
12436
|
} else {
|
|
11289
12437
|
page.drawText(lineText, {
|
|
11290
12438
|
x: drawX,
|
|
@@ -11317,7 +12465,7 @@ async function drawTextBox(pdfDoc, page, pageHeight, text, left, top, width, hei
|
|
|
11317
12465
|
}
|
|
11318
12466
|
}
|
|
11319
12467
|
if (applyAsciiClip) {
|
|
11320
|
-
page.pushOperators((0,
|
|
12468
|
+
page.pushOperators((0, import_pdf_lib4.popGraphicsState)());
|
|
11321
12469
|
}
|
|
11322
12470
|
}
|
|
11323
12471
|
function parseNumericCellValue(rawValue) {
|
|
@@ -12059,7 +13207,7 @@ async function drawRichOrColumnTextBox(pdfDoc, page, pageHeight, spans, left, to
|
|
|
12059
13207
|
const key = `${code ? "C" : "S"}-${bold ? "B" : "N"}-${italic ? "I" : "R"}`;
|
|
12060
13208
|
const existing = fontCache.get(key);
|
|
12061
13209
|
if (existing) return existing;
|
|
12062
|
-
const stdName = code ? bold && italic ?
|
|
13210
|
+
const stdName = code ? bold && italic ? import_pdf_lib4.StandardFonts.CourierBoldOblique : bold ? import_pdf_lib4.StandardFonts.CourierBold : italic ? import_pdf_lib4.StandardFonts.CourierOblique : import_pdf_lib4.StandardFonts.Courier : bold && italic ? import_pdf_lib4.StandardFonts.HelveticaBoldOblique : bold ? import_pdf_lib4.StandardFonts.HelveticaBold : italic ? import_pdf_lib4.StandardFonts.HelveticaOblique : import_pdf_lib4.StandardFonts.Helvetica;
|
|
12063
13211
|
const embedded = await pdfDoc.embedFont(stdName);
|
|
12064
13212
|
fontCache.set(key, embedded);
|
|
12065
13213
|
return embedded;
|
|
@@ -12112,34 +13260,34 @@ async function drawRichOrColumnTextBox(pdfDoc, page, pageHeight, spans, left, to
|
|
|
12112
13260
|
const hexStr = encodeVectorCjkLineHex(seg.text, cjkState, activeSubset);
|
|
12113
13261
|
const fillOp = colorType === "cmyk" ? (() => {
|
|
12114
13262
|
const cm = rgbToCmyk(col.r, col.g, col.b);
|
|
12115
|
-
return (0,
|
|
12116
|
-
})() : (0,
|
|
13263
|
+
return (0, import_pdf_lib4.setFillingCmykColor)(cm.c, cm.m, cm.y, cm.k);
|
|
13264
|
+
})() : (0, import_pdf_lib4.setFillingRgbColor)(col.r, col.g, col.b);
|
|
12117
13265
|
const boldOps = seg.bold && !usedDedicatedBold ? [
|
|
12118
|
-
|
|
12119
|
-
(0,
|
|
13266
|
+
import_pdf_lib4.PDFOperator.of("Tr", [import_pdf_lib4.PDFNumber.of(2)]),
|
|
13267
|
+
(0, import_pdf_lib4.setLineWidth)(Math.max(0.25, seg.fontSize * 0.032)),
|
|
12120
13268
|
colorType === "cmyk" ? (() => {
|
|
12121
13269
|
const cm = rgbToCmyk(col.r, col.g, col.b);
|
|
12122
|
-
return (0,
|
|
12123
|
-
})() : (0,
|
|
13270
|
+
return (0, import_pdf_lib4.setStrokingCmykColor)(cm.c, cm.m, cm.y, cm.k);
|
|
13271
|
+
})() : (0, import_pdf_lib4.setStrokingRgbColor)(col.r, col.g, col.b)
|
|
12124
13272
|
] : [];
|
|
12125
|
-
const posOp = seg.italic ?
|
|
12126
|
-
|
|
12127
|
-
|
|
12128
|
-
|
|
12129
|
-
|
|
12130
|
-
|
|
12131
|
-
|
|
12132
|
-
]) : (0,
|
|
13273
|
+
const posOp = seg.italic ? import_pdf_lib4.PDFOperator.of("Tm", [
|
|
13274
|
+
import_pdf_lib4.PDFNumber.of(1),
|
|
13275
|
+
import_pdf_lib4.PDFNumber.of(0),
|
|
13276
|
+
import_pdf_lib4.PDFNumber.of(0.2126),
|
|
13277
|
+
import_pdf_lib4.PDFNumber.of(1),
|
|
13278
|
+
import_pdf_lib4.PDFNumber.of(segX),
|
|
13279
|
+
import_pdf_lib4.PDFNumber.of(baselineY)
|
|
13280
|
+
]) : (0, import_pdf_lib4.moveText)(segX, baselineY);
|
|
12133
13281
|
page.pushOperators(
|
|
12134
|
-
(0,
|
|
12135
|
-
(0,
|
|
13282
|
+
(0, import_pdf_lib4.pushGraphicsState)(),
|
|
13283
|
+
(0, import_pdf_lib4.beginText)(),
|
|
12136
13284
|
fillOp,
|
|
12137
13285
|
...boldOps,
|
|
12138
|
-
(0,
|
|
13286
|
+
(0, import_pdf_lib4.setFontAndSize)(fontKey, seg.fontSize),
|
|
12139
13287
|
posOp,
|
|
12140
|
-
(0,
|
|
12141
|
-
(0,
|
|
12142
|
-
(0,
|
|
13288
|
+
(0, import_pdf_lib4.showText)(import_pdf_lib4.PDFHexString.of(hexStr)),
|
|
13289
|
+
(0, import_pdf_lib4.endText)(),
|
|
13290
|
+
(0, import_pdf_lib4.popGraphicsState)()
|
|
12143
13291
|
);
|
|
12144
13292
|
} else if (hasNonAscii(seg.text)) {
|
|
12145
13293
|
const pngBytes = renderTextToPngBytesInBrowser(seg.text, Math.max(8, seg.widthPt + 4), seg.fontSize * 1.35, {
|
|
@@ -12279,10 +13427,11 @@ function attachPdfOutlinesTree(pdfDoc, bookmarks) {
|
|
|
12279
13427
|
const selfRef = itemRefs[i];
|
|
12280
13428
|
const clampedPageIdx = Math.max(0, Math.min(allPages.length - 1, Math.floor(item.pageIndex || 0)));
|
|
12281
13429
|
const targetPage = allPages[clampedPageIdx];
|
|
12282
|
-
const
|
|
12283
|
-
const
|
|
13430
|
+
const effectiveTopOffset = item.topPt ?? item.topOffsetPt;
|
|
13431
|
+
const destY = effectiveTopOffset !== void 0 ? Math.round(Math.max(0, targetPage.getHeight() - effectiveTopOffset) * 100) / 100 : null;
|
|
13432
|
+
const destArray = pdfDoc.context.obj([targetPage.ref, import_pdf_lib4.PDFName.of("XYZ"), null, destY, null]);
|
|
12284
13433
|
const dictObj = {
|
|
12285
|
-
Title:
|
|
13434
|
+
Title: import_pdf_lib4.PDFHexString.fromText(item.title || "Bookmark"),
|
|
12286
13435
|
Parent: parentRef,
|
|
12287
13436
|
Dest: destArray
|
|
12288
13437
|
};
|
|
@@ -12315,15 +13464,15 @@ function attachPdfOutlinesTree(pdfDoc, bookmarks) {
|
|
|
12315
13464
|
Count: rootChain.totalCount
|
|
12316
13465
|
})
|
|
12317
13466
|
);
|
|
12318
|
-
pdfDoc.catalog.set(
|
|
13467
|
+
pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("Outlines"), outlinesRef);
|
|
12319
13468
|
}
|
|
12320
13469
|
function ensurePagePropertiesDict(pdfDoc, pdfPage) {
|
|
12321
13470
|
pdfPage.node.normalize();
|
|
12322
13471
|
const res = pdfPage.node.Resources();
|
|
12323
|
-
let props = pdfDoc.context.lookupMaybe(res.get(
|
|
13472
|
+
let props = pdfDoc.context.lookupMaybe(res.get(import_pdf_lib4.PDFName.of("Properties")), import_pdf_lib4.PDFDict);
|
|
12324
13473
|
if (!props) {
|
|
12325
13474
|
props = pdfDoc.context.obj({});
|
|
12326
|
-
res.set(
|
|
13475
|
+
res.set(import_pdf_lib4.PDFName.of("Properties"), props);
|
|
12327
13476
|
}
|
|
12328
13477
|
return props;
|
|
12329
13478
|
}
|
|
@@ -12339,11 +13488,11 @@ function attachOptionalContentLayers(pdfDoc, layers) {
|
|
|
12339
13488
|
const isPrint = layer.printable !== false;
|
|
12340
13489
|
const ocgDict = pdfDoc.context.obj({
|
|
12341
13490
|
Type: "OCG",
|
|
12342
|
-
Name:
|
|
12343
|
-
Intent: [
|
|
13491
|
+
Name: import_pdf_lib4.PDFHexString.fromText(layer.name || layer.id),
|
|
13492
|
+
Intent: [import_pdf_lib4.PDFName.of("View"), import_pdf_lib4.PDFName.of("Design")],
|
|
12344
13493
|
Usage: {
|
|
12345
|
-
View: { ViewState:
|
|
12346
|
-
Print: { PrintState:
|
|
13494
|
+
View: { ViewState: import_pdf_lib4.PDFName.of(isVis ? "ON" : "OFF") },
|
|
13495
|
+
Print: { PrintState: import_pdf_lib4.PDFName.of(isPrint ? "ON" : "OFF") }
|
|
12347
13496
|
}
|
|
12348
13497
|
});
|
|
12349
13498
|
const ocgRef = pdfDoc.context.register(ocgDict);
|
|
@@ -12358,11 +13507,11 @@ function attachOptionalContentLayers(pdfDoc, layers) {
|
|
|
12358
13507
|
});
|
|
12359
13508
|
});
|
|
12360
13509
|
pdfDoc.catalog.set(
|
|
12361
|
-
|
|
13510
|
+
import_pdf_lib4.PDFName.of("OCProperties"),
|
|
12362
13511
|
pdfDoc.context.obj({
|
|
12363
13512
|
OCGs: allRefs,
|
|
12364
13513
|
D: {
|
|
12365
|
-
BaseState:
|
|
13514
|
+
BaseState: import_pdf_lib4.PDFName.of("ON"),
|
|
12366
13515
|
ON: onRefs,
|
|
12367
13516
|
OFF: offRefs,
|
|
12368
13517
|
Order: allRefs,
|
|
@@ -12381,7 +13530,7 @@ function attachEmbeddedFileAttachments(pdfDoc, attachments) {
|
|
|
12381
13530
|
const subtypeSafe = (att.mimeType || "application/octet-stream").replace(/\//g, "#2F");
|
|
12382
13531
|
const efStream = pdfDoc.context.flateStream(fileBytes, {
|
|
12383
13532
|
Type: "EmbeddedFile",
|
|
12384
|
-
Subtype:
|
|
13533
|
+
Subtype: import_pdf_lib4.PDFName.of(subtypeSafe),
|
|
12385
13534
|
Params: {
|
|
12386
13535
|
Size: fileBytes.byteLength
|
|
12387
13536
|
}
|
|
@@ -12389,30 +13538,30 @@ function attachEmbeddedFileAttachments(pdfDoc, attachments) {
|
|
|
12389
13538
|
const efRef = pdfDoc.context.register(efStream);
|
|
12390
13539
|
const filespecObj = {
|
|
12391
13540
|
Type: "Filespec",
|
|
12392
|
-
F:
|
|
12393
|
-
UF:
|
|
13541
|
+
F: import_pdf_lib4.PDFString.of((att.fileName || "attachment.bin").replace(/[^\x20-\x7E]/g, "_")),
|
|
13542
|
+
UF: import_pdf_lib4.PDFHexString.fromText(att.fileName || "attachment.bin"),
|
|
12394
13543
|
EF: {
|
|
12395
13544
|
F: efRef,
|
|
12396
13545
|
UF: efRef
|
|
12397
13546
|
}
|
|
12398
13547
|
};
|
|
12399
13548
|
if (att.description) {
|
|
12400
|
-
filespecObj.Desc =
|
|
13549
|
+
filespecObj.Desc = import_pdf_lib4.PDFHexString.fromText(att.description);
|
|
12401
13550
|
}
|
|
12402
13551
|
const filespecRef = pdfDoc.context.register(pdfDoc.context.obj(filespecObj));
|
|
12403
|
-
namesArr.push(
|
|
13552
|
+
namesArr.push(import_pdf_lib4.PDFHexString.fromText(att.fileName || "attachment.bin"), filespecRef);
|
|
12404
13553
|
}
|
|
12405
13554
|
const efTreeRef = pdfDoc.context.register(
|
|
12406
13555
|
pdfDoc.context.obj({
|
|
12407
13556
|
Names: namesArr
|
|
12408
13557
|
})
|
|
12409
13558
|
);
|
|
12410
|
-
const existingNames = pdfDoc.context.lookupMaybe(pdfDoc.catalog.get(
|
|
13559
|
+
const existingNames = pdfDoc.context.lookupMaybe(pdfDoc.catalog.get(import_pdf_lib4.PDFName.of("Names")), import_pdf_lib4.PDFDict);
|
|
12411
13560
|
if (existingNames) {
|
|
12412
|
-
existingNames.set(
|
|
13561
|
+
existingNames.set(import_pdf_lib4.PDFName.of("EmbeddedFiles"), efTreeRef);
|
|
12413
13562
|
} else {
|
|
12414
13563
|
pdfDoc.catalog.set(
|
|
12415
|
-
|
|
13564
|
+
import_pdf_lib4.PDFName.of("Names"),
|
|
12416
13565
|
pdfDoc.context.obj({
|
|
12417
13566
|
EmbeddedFiles: efTreeRef
|
|
12418
13567
|
})
|
|
@@ -12456,7 +13605,7 @@ function attachPdfAComplianceMetadata(pdfDoc, snapshot, includePdfUa) {
|
|
|
12456
13605
|
Length: xmpBytes.byteLength
|
|
12457
13606
|
});
|
|
12458
13607
|
const metadataRef = pdfDoc.context.register(metadataStream);
|
|
12459
|
-
pdfDoc.catalog.set(
|
|
13608
|
+
pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("Metadata"), metadataRef);
|
|
12460
13609
|
const srgbHeaderBytes = new TextEncoder().encode("sRGB IEC61966-2.1 ICC Output Profile");
|
|
12461
13610
|
const iccStream = pdfDoc.context.flateStream(srgbHeaderBytes, {
|
|
12462
13611
|
N: 3,
|
|
@@ -12467,13 +13616,13 @@ function attachPdfAComplianceMetadata(pdfDoc, snapshot, includePdfUa) {
|
|
|
12467
13616
|
pdfDoc.context.obj({
|
|
12468
13617
|
Type: "OutputIntent",
|
|
12469
13618
|
S: "GTS_PDFA1",
|
|
12470
|
-
OutputConditionIdentifier:
|
|
12471
|
-
RegistryName:
|
|
12472
|
-
Info:
|
|
13619
|
+
OutputConditionIdentifier: import_pdf_lib4.PDFString.of("sRGB IEC61966-2.1"),
|
|
13620
|
+
RegistryName: import_pdf_lib4.PDFString.of("http://www.color.org"),
|
|
13621
|
+
Info: import_pdf_lib4.PDFString.of("sRGB IEC61966-2.1"),
|
|
12473
13622
|
DestOutputProfile: iccRef
|
|
12474
13623
|
})
|
|
12475
13624
|
);
|
|
12476
|
-
pdfDoc.catalog.set(
|
|
13625
|
+
pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("OutputIntents"), pdfDoc.context.obj([outputIntentRef]));
|
|
12477
13626
|
}
|
|
12478
13627
|
function resolveElementStructRole(el) {
|
|
12479
13628
|
switch (el.type) {
|
|
@@ -12505,9 +13654,9 @@ function resolveElementStructRole(el) {
|
|
|
12505
13654
|
}
|
|
12506
13655
|
}
|
|
12507
13656
|
function attachTaggedStructTreeRoot(pdfDoc, snapshot, items, totalPages) {
|
|
12508
|
-
pdfDoc.catalog.set(
|
|
12509
|
-
pdfDoc.catalog.set(
|
|
12510
|
-
pdfDoc.catalog.set(
|
|
13657
|
+
pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("Lang"), import_pdf_lib4.PDFString.of(snapshot.locale ? String(snapshot.locale) : "zh-CN"));
|
|
13658
|
+
pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("MarkInfo"), pdfDoc.context.obj({ Marked: import_pdf_lib4.PDFBool.True }));
|
|
13659
|
+
pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("ViewerPreferences"), pdfDoc.context.obj({ DisplayDocTitle: import_pdf_lib4.PDFBool.True }));
|
|
12511
13660
|
if (!snapshot.metadata?.sanitized && snapshot.name) {
|
|
12512
13661
|
pdfDoc.setTitle(snapshot.name);
|
|
12513
13662
|
}
|
|
@@ -12519,16 +13668,16 @@ function attachTaggedStructTreeRoot(pdfDoc, snapshot, items, totalPages) {
|
|
|
12519
13668
|
const elemRef = pdfDoc.context.nextRef();
|
|
12520
13669
|
const elemDict = {
|
|
12521
13670
|
Type: "StructElem",
|
|
12522
|
-
S:
|
|
13671
|
+
S: import_pdf_lib4.PDFName.of(item.role),
|
|
12523
13672
|
P: docElemRef,
|
|
12524
13673
|
Pg: item.pageRef,
|
|
12525
|
-
K:
|
|
13674
|
+
K: import_pdf_lib4.PDFNumber.of(item.mcid)
|
|
12526
13675
|
};
|
|
12527
13676
|
if (item.altText) {
|
|
12528
|
-
elemDict.Alt =
|
|
13677
|
+
elemDict.Alt = import_pdf_lib4.PDFHexString.fromText(item.altText);
|
|
12529
13678
|
}
|
|
12530
13679
|
if (item.title) {
|
|
12531
|
-
elemDict.T =
|
|
13680
|
+
elemDict.T = import_pdf_lib4.PDFHexString.fromText(item.title);
|
|
12532
13681
|
}
|
|
12533
13682
|
pdfDoc.context.assign(elemRef, pdfDoc.context.obj(elemDict));
|
|
12534
13683
|
childElemRefs.push(elemRef);
|
|
@@ -12543,7 +13692,7 @@ function attachTaggedStructTreeRoot(pdfDoc, snapshot, items, totalPages) {
|
|
|
12543
13692
|
docElemRef,
|
|
12544
13693
|
pdfDoc.context.obj({
|
|
12545
13694
|
Type: "StructElem",
|
|
12546
|
-
S:
|
|
13695
|
+
S: import_pdf_lib4.PDFName.of("Document"),
|
|
12547
13696
|
P: structTreeRootRef,
|
|
12548
13697
|
K: childElemRefs
|
|
12549
13698
|
})
|
|
@@ -12551,7 +13700,7 @@ function attachTaggedStructTreeRoot(pdfDoc, snapshot, items, totalPages) {
|
|
|
12551
13700
|
const numsList = [];
|
|
12552
13701
|
for (let p = 0; p < totalPages; p++) {
|
|
12553
13702
|
const refsForPage = (byPageMcid.get(p) ?? []).filter(Boolean);
|
|
12554
|
-
numsList.push(
|
|
13703
|
+
numsList.push(import_pdf_lib4.PDFNumber.of(p), pdfDoc.context.obj(refsForPage));
|
|
12555
13704
|
}
|
|
12556
13705
|
const parentTreeRef = pdfDoc.context.register(pdfDoc.context.obj({ Nums: numsList }));
|
|
12557
13706
|
pdfDoc.context.assign(
|
|
@@ -12563,14 +13712,14 @@ function attachTaggedStructTreeRoot(pdfDoc, snapshot, items, totalPages) {
|
|
|
12563
13712
|
ParentTreeNextKey: totalPages
|
|
12564
13713
|
})
|
|
12565
13714
|
);
|
|
12566
|
-
pdfDoc.catalog.set(
|
|
13715
|
+
pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("StructTreeRoot"), structTreeRootRef);
|
|
12567
13716
|
}
|
|
12568
13717
|
function pruneUnreferencedObjectsAndCompressStreams(pdfDoc) {
|
|
12569
13718
|
for (const [ref, obj] of pdfDoc.context.enumerateIndirectObjects()) {
|
|
12570
|
-
if (obj instanceof
|
|
12571
|
-
const typeName = obj.dict.get(
|
|
12572
|
-
const isMetadata = typeName instanceof
|
|
12573
|
-
const hasFilter = Boolean(obj.dict.get(
|
|
13719
|
+
if (obj instanceof import_pdf_lib4.PDFRawStream) {
|
|
13720
|
+
const typeName = obj.dict.get(import_pdf_lib4.PDFName.of("Type"));
|
|
13721
|
+
const isMetadata = typeName instanceof import_pdf_lib4.PDFName && typeName.decodeText() === "Metadata";
|
|
13722
|
+
const hasFilter = Boolean(obj.dict.get(import_pdf_lib4.PDFName.of("Filter")));
|
|
12574
13723
|
if (!isMetadata && !hasFilter && obj.contents.byteLength > 64) {
|
|
12575
13724
|
const compressed = pdfDoc.context.flateStream(obj.contents);
|
|
12576
13725
|
for (const [k, v] of obj.dict.entries()) {
|
|
@@ -12587,26 +13736,26 @@ function pruneUnreferencedObjectsAndCompressStreams(pdfDoc) {
|
|
|
12587
13736
|
const refToString = (r) => `${r.objectNumber}:${r.generationNumber}`;
|
|
12588
13737
|
const visit = (node) => {
|
|
12589
13738
|
if (!node) return;
|
|
12590
|
-
if (node instanceof
|
|
13739
|
+
if (node instanceof import_pdf_lib4.PDFRef) {
|
|
12591
13740
|
const key = refToString(node);
|
|
12592
13741
|
if (reachable.has(key)) return;
|
|
12593
13742
|
reachable.add(key);
|
|
12594
13743
|
visit(pdfDoc.context.lookup(node));
|
|
12595
13744
|
return;
|
|
12596
13745
|
}
|
|
12597
|
-
if (node instanceof
|
|
13746
|
+
if (node instanceof import_pdf_lib4.PDFDict) {
|
|
12598
13747
|
for (const [, val] of node.entries()) {
|
|
12599
13748
|
visit(val);
|
|
12600
13749
|
}
|
|
12601
13750
|
return;
|
|
12602
13751
|
}
|
|
12603
|
-
if (node instanceof
|
|
13752
|
+
if (node instanceof import_pdf_lib4.PDFArray) {
|
|
12604
13753
|
for (let i = 0; i < node.size(); i++) {
|
|
12605
13754
|
visit(node.get(i));
|
|
12606
13755
|
}
|
|
12607
13756
|
return;
|
|
12608
13757
|
}
|
|
12609
|
-
if (node instanceof
|
|
13758
|
+
if (node instanceof import_pdf_lib4.PDFRawStream || node instanceof import_pdf_lib4.PDFStream) {
|
|
12610
13759
|
visit(node.dict);
|
|
12611
13760
|
}
|
|
12612
13761
|
};
|
|
@@ -12637,30 +13786,30 @@ async function drawInvisibleSearchableOcrSpans(pdfDoc, pdfPage, pageHeight, span
|
|
|
12637
13786
|
const { fontKey } = getOrRegisterPageCjkFontKey(pdfPage, localCjkState);
|
|
12638
13787
|
const hexStr = encodeVectorCjkLineHex(txt, localCjkState);
|
|
12639
13788
|
pdfPage.pushOperators(
|
|
12640
|
-
(0,
|
|
12641
|
-
(0,
|
|
12642
|
-
|
|
12643
|
-
(0,
|
|
12644
|
-
(0,
|
|
12645
|
-
(0,
|
|
12646
|
-
(0,
|
|
12647
|
-
(0,
|
|
13789
|
+
(0, import_pdf_lib4.pushGraphicsState)(),
|
|
13790
|
+
(0, import_pdf_lib4.beginText)(),
|
|
13791
|
+
import_pdf_lib4.PDFOperator.of("Tr", [import_pdf_lib4.PDFNumber.of(3)]),
|
|
13792
|
+
(0, import_pdf_lib4.setFontAndSize)(fontKey, fs),
|
|
13793
|
+
(0, import_pdf_lib4.moveText)(span.left, baselineY),
|
|
13794
|
+
(0, import_pdf_lib4.showText)(import_pdf_lib4.PDFHexString.of(hexStr)),
|
|
13795
|
+
(0, import_pdf_lib4.endText)(),
|
|
13796
|
+
(0, import_pdf_lib4.popGraphicsState)()
|
|
12648
13797
|
);
|
|
12649
13798
|
} else {
|
|
12650
13799
|
if (!helvFont) {
|
|
12651
|
-
helvFont = await pdfDoc.embedFont(
|
|
13800
|
+
helvFont = await pdfDoc.embedFont(import_pdf_lib4.StandardFonts.Helvetica);
|
|
12652
13801
|
}
|
|
12653
13802
|
const fontKey = pdfPage.node.newFontDictionary("FOcr", helvFont.ref);
|
|
12654
13803
|
const asciiHex = Array.from(txt).map((c) => (c.charCodeAt(0) & 255).toString(16).padStart(2, "0").toUpperCase()).join("");
|
|
12655
13804
|
pdfPage.pushOperators(
|
|
12656
|
-
(0,
|
|
12657
|
-
(0,
|
|
12658
|
-
|
|
12659
|
-
(0,
|
|
12660
|
-
(0,
|
|
12661
|
-
(0,
|
|
12662
|
-
(0,
|
|
12663
|
-
(0,
|
|
13805
|
+
(0, import_pdf_lib4.pushGraphicsState)(),
|
|
13806
|
+
(0, import_pdf_lib4.beginText)(),
|
|
13807
|
+
import_pdf_lib4.PDFOperator.of("Tr", [import_pdf_lib4.PDFNumber.of(3)]),
|
|
13808
|
+
(0, import_pdf_lib4.setFontAndSize)(fontKey, fs),
|
|
13809
|
+
(0, import_pdf_lib4.moveText)(span.left, baselineY),
|
|
13810
|
+
(0, import_pdf_lib4.showText)(import_pdf_lib4.PDFHexString.of(asciiHex)),
|
|
13811
|
+
(0, import_pdf_lib4.endText)(),
|
|
13812
|
+
(0, import_pdf_lib4.popGraphicsState)()
|
|
12664
13813
|
);
|
|
12665
13814
|
}
|
|
12666
13815
|
}
|
|
@@ -12729,7 +13878,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
12729
13878
|
const optimizeSize = Boolean(options?.optimizeSize);
|
|
12730
13879
|
const preResolvedFonts = await resolveRenderFontsForExport(snapshot, effectiveData, options);
|
|
12731
13880
|
throwIfExportAborted();
|
|
12732
|
-
const pdfDoc = await
|
|
13881
|
+
const pdfDoc = await import_pdf_lib4.PDFDocument.create();
|
|
12733
13882
|
if (snapshot.metadata?.sanitized) {
|
|
12734
13883
|
pdfDoc.setTitle("");
|
|
12735
13884
|
pdfDoc.setAuthor("");
|
|
@@ -12768,7 +13917,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
12768
13917
|
};
|
|
12769
13918
|
const ensureAcroHelvetica = async () => {
|
|
12770
13919
|
if (!acroHelveticaFont) {
|
|
12771
|
-
acroHelveticaFont = await getOrEmbedStandardFont(pdfDoc,
|
|
13920
|
+
acroHelveticaFont = await getOrEmbedStandardFont(pdfDoc, import_pdf_lib4.StandardFonts.Helvetica);
|
|
12772
13921
|
}
|
|
12773
13922
|
return acroHelveticaFont;
|
|
12774
13923
|
};
|
|
@@ -12929,7 +14078,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
12929
14078
|
if (!excludeBasePdf && snapshot.sourceDocumentRef?.dataUri) {
|
|
12930
14079
|
try {
|
|
12931
14080
|
const srcBytes = dataUriToBytes(snapshot.sourceDocumentRef.dataUri);
|
|
12932
|
-
sourcePdfDoc = await
|
|
14081
|
+
sourcePdfDoc = await import_pdf_lib4.PDFDocument.load(srcBytes);
|
|
12933
14082
|
} catch {
|
|
12934
14083
|
sourcePdfDoc = null;
|
|
12935
14084
|
}
|
|
@@ -13143,21 +14292,21 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13143
14292
|
const [copied] = await pdfDoc.copyPages(sourcePdfDoc, [pageMeta.sourcePageNumber - 1]);
|
|
13144
14293
|
pdfPage = pdfDoc.addPage(copied);
|
|
13145
14294
|
if (snapshot.metadata?.importedAcroFormBase) {
|
|
13146
|
-
const existingAnnots = pdfDoc.context.lookupMaybe(pdfPage.node.get(
|
|
14295
|
+
const existingAnnots = pdfDoc.context.lookupMaybe(pdfPage.node.get(import_pdf_lib4.PDFName.of("Annots")), import_pdf_lib4.PDFArray);
|
|
13147
14296
|
if (existingAnnots) {
|
|
13148
14297
|
const filtered = [];
|
|
13149
14298
|
for (let ai = 0; ai < existingAnnots.size(); ai++) {
|
|
13150
14299
|
const aRef = existingAnnots.get(ai);
|
|
13151
|
-
const aDict = pdfDoc.context.lookupMaybe(aRef,
|
|
13152
|
-
const sub = aDict?.get(
|
|
13153
|
-
if (!(sub instanceof
|
|
14300
|
+
const aDict = pdfDoc.context.lookupMaybe(aRef, import_pdf_lib4.PDFDict);
|
|
14301
|
+
const sub = aDict?.get(import_pdf_lib4.PDFName.of("Subtype"));
|
|
14302
|
+
if (!(sub instanceof import_pdf_lib4.PDFName && sub.decodeText() === "Widget")) {
|
|
13154
14303
|
filtered.push(aRef);
|
|
13155
14304
|
}
|
|
13156
14305
|
}
|
|
13157
14306
|
if (filtered.length > 0) {
|
|
13158
|
-
pdfPage.node.set(
|
|
14307
|
+
pdfPage.node.set(import_pdf_lib4.PDFName.of("Annots"), pdfDoc.context.obj(filtered));
|
|
13159
14308
|
} else {
|
|
13160
|
-
pdfPage.node.delete(
|
|
14309
|
+
pdfPage.node.delete(import_pdf_lib4.PDFName.of("Annots"));
|
|
13161
14310
|
}
|
|
13162
14311
|
}
|
|
13163
14312
|
}
|
|
@@ -13168,7 +14317,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13168
14317
|
let size = pageMeta.pageSize ?? snapshot.document.pageSize;
|
|
13169
14318
|
if (excludeBasePdf && snapshot.sourceDocumentRef?.dataUri && !pageMeta.pageSize) {
|
|
13170
14319
|
try {
|
|
13171
|
-
const tempSrc = await
|
|
14320
|
+
const tempSrc = await import_pdf_lib4.PDFDocument.load(dataUriToBytes(snapshot.sourceDocumentRef.dataUri));
|
|
13172
14321
|
const pIdx0 = Math.max(0, (pageMeta.sourcePageNumber ?? 1) - 1);
|
|
13173
14322
|
if (pIdx0 < tempSrc.getPageCount()) {
|
|
13174
14323
|
const refSz = tempSrc.getPage(pIdx0).getSize();
|
|
@@ -13185,14 +14334,14 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13185
14334
|
y: 0,
|
|
13186
14335
|
width: size.width,
|
|
13187
14336
|
height: size.height,
|
|
13188
|
-
color: (0,
|
|
14337
|
+
color: (0, import_pdf_lib4.rgb)(bgColor.r, bgColor.g, bgColor.b)
|
|
13189
14338
|
});
|
|
13190
14339
|
}
|
|
13191
14340
|
}
|
|
13192
14341
|
const pageHeight = pdfPage.getHeight();
|
|
13193
14342
|
const pageWidth = pdfPage.getWidth();
|
|
13194
14343
|
if (pageMeta.rotation !== void 0) {
|
|
13195
|
-
pdfPage.setRotation((0,
|
|
14344
|
+
pdfPage.setRotation((0, import_pdf_lib4.degrees)(pageMeta.rotation));
|
|
13196
14345
|
}
|
|
13197
14346
|
if (pageMeta.cropBox) {
|
|
13198
14347
|
const cb = pageMeta.cropBox;
|
|
@@ -13206,14 +14355,14 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13206
14355
|
y: pageHeight - sRect.top - sRect.height,
|
|
13207
14356
|
width: sRect.width,
|
|
13208
14357
|
height: sRect.height,
|
|
13209
|
-
color: (0,
|
|
14358
|
+
color: (0, import_pdf_lib4.rgb)(1, 1, 1),
|
|
13210
14359
|
borderWidth: 0
|
|
13211
14360
|
});
|
|
13212
14361
|
}
|
|
13213
14362
|
}
|
|
13214
14363
|
if (accessibilityTagged) {
|
|
13215
|
-
pdfPage.node.set(
|
|
13216
|
-
pdfPage.node.set(
|
|
14364
|
+
pdfPage.node.set(import_pdf_lib4.PDFName.of("StructParents"), import_pdf_lib4.PDFNumber.of(pIndex));
|
|
14365
|
+
pdfPage.node.set(import_pdf_lib4.PDFName.of("Tabs"), import_pdf_lib4.PDFName.of("S"));
|
|
13217
14366
|
}
|
|
13218
14367
|
let nextPageMcid = 0;
|
|
13219
14368
|
const activeDynamicRange = planItem.dynamicSplitRanges ? planItem.dynamicSplitRanges[chunkIndex] : void 0;
|
|
@@ -13268,9 +14417,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13268
14417
|
let hasOpenCenterTransform = false;
|
|
13269
14418
|
if (ocgEntry) {
|
|
13270
14419
|
const propsDict = ensurePagePropertiesDict(pdfDoc, pdfPage);
|
|
13271
|
-
propsDict.set(
|
|
14420
|
+
propsDict.set(import_pdf_lib4.PDFName.of(ocgEntry.propName), ocgEntry.ocgRef);
|
|
13272
14421
|
pdfPage.pushOperators(
|
|
13273
|
-
|
|
14422
|
+
import_pdf_lib4.PDFOperator.of("BDC", [import_pdf_lib4.PDFName.of("OC"), import_pdf_lib4.PDFName.of(ocgEntry.propName)])
|
|
13274
14423
|
);
|
|
13275
14424
|
openBdcCount++;
|
|
13276
14425
|
}
|
|
@@ -13278,10 +14427,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13278
14427
|
const mcid = nextPageMcid++;
|
|
13279
14428
|
const mcPropName = `MC_${mcid}`;
|
|
13280
14429
|
const propsDict = ensurePagePropertiesDict(pdfDoc, pdfPage);
|
|
13281
|
-
propsDict.set(
|
|
14430
|
+
propsDict.set(import_pdf_lib4.PDFName.of(mcPropName), pdfDoc.context.obj({ MCID: import_pdf_lib4.PDFNumber.of(mcid) }));
|
|
13282
14431
|
const role = resolveElementStructRole(el);
|
|
13283
14432
|
pdfPage.pushOperators(
|
|
13284
|
-
|
|
14433
|
+
import_pdf_lib4.PDFOperator.of("BDC", [import_pdf_lib4.PDFName.of(role), import_pdf_lib4.PDFName.of(mcPropName)])
|
|
13285
14434
|
);
|
|
13286
14435
|
openBdcCount++;
|
|
13287
14436
|
taggedStructItems.push({
|
|
@@ -13330,8 +14479,8 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13330
14479
|
) : null;
|
|
13331
14480
|
if (centerMatrix) {
|
|
13332
14481
|
pdfPage.pushOperators(
|
|
13333
|
-
(0,
|
|
13334
|
-
(0,
|
|
14482
|
+
(0, import_pdf_lib4.pushGraphicsState)(),
|
|
14483
|
+
(0, import_pdf_lib4.concatTransformationMatrix)(
|
|
13335
14484
|
centerMatrix[0],
|
|
13336
14485
|
centerMatrix[1],
|
|
13337
14486
|
centerMatrix[2],
|
|
@@ -13611,9 +14760,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13611
14760
|
if (isMultiline) {
|
|
13612
14761
|
tf.enableMultiline();
|
|
13613
14762
|
}
|
|
13614
|
-
if (textEl.style?.textAlign === "center") tf.setAlignment(
|
|
13615
|
-
else if (textEl.style?.textAlign === "right") tf.setAlignment(
|
|
13616
|
-
else tf.setAlignment(
|
|
14763
|
+
if (textEl.style?.textAlign === "center") tf.setAlignment(import_pdf_lib4.TextAlignment.Center);
|
|
14764
|
+
else if (textEl.style?.textAlign === "right") tf.setAlignment(import_pdf_lib4.TextAlignment.Right);
|
|
14765
|
+
else tf.setAlignment(import_pdf_lib4.TextAlignment.Left);
|
|
13617
14766
|
const bg = parseHexColor(textEl.style?.backgroundColor) ?? { r: 1, g: 1, b: 1, a: 1 };
|
|
13618
14767
|
const border = parseHexColor(textEl.style?.borderColor) ?? { r: 0.75, g: 0.82, b: 0.9, a: 1 };
|
|
13619
14768
|
const txtCol = parseHexColor(textEl.style?.color) ?? { r: 0.12, g: 0.14, b: 0.16, a: 1 };
|
|
@@ -13624,11 +14773,11 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13624
14773
|
y: pdfY,
|
|
13625
14774
|
width,
|
|
13626
14775
|
height,
|
|
13627
|
-
rotate: (0,
|
|
14776
|
+
rotate: (0, import_pdf_lib4.degrees)(rotDeg),
|
|
13628
14777
|
borderWidth: textEl.style?.borderWidth ?? 1,
|
|
13629
|
-
borderColor: (0,
|
|
13630
|
-
backgroundColor: (0,
|
|
13631
|
-
textColor: (0,
|
|
14778
|
+
borderColor: (0, import_pdf_lib4.rgb)(border.r, border.g, border.b),
|
|
14779
|
+
backgroundColor: (0, import_pdf_lib4.rgb)(bg.r, bg.g, bg.b),
|
|
14780
|
+
textColor: (0, import_pdf_lib4.rgb)(txtCol.r, txtCol.g, txtCol.b)
|
|
13632
14781
|
});
|
|
13633
14782
|
if (resolved) {
|
|
13634
14783
|
tf.setText(resolved);
|
|
@@ -13636,9 +14785,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13636
14785
|
if (textEl.locked) tf.enableReadOnly();
|
|
13637
14786
|
if (textEl.required) tf.enableRequired();
|
|
13638
14787
|
tf.acroField.dict.set(
|
|
13639
|
-
|
|
14788
|
+
import_pdf_lib4.PDFName.of("YudaoMeta"),
|
|
13640
14789
|
pdfDoc.context.obj({
|
|
13641
|
-
ElementType:
|
|
14790
|
+
ElementType: import_pdf_lib4.PDFName.of("text"),
|
|
13642
14791
|
Left: left,
|
|
13643
14792
|
Top: top,
|
|
13644
14793
|
Width: width,
|
|
@@ -13658,10 +14807,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13658
14807
|
txtCol
|
|
13659
14808
|
});
|
|
13660
14809
|
const daStr = `/FCjk ${fmtPdfNum(fsVal)} Tf ${fmtPdfNum(txtCol.r)} ${fmtPdfNum(txtCol.g)} ${fmtPdfNum(txtCol.b)} rg`;
|
|
13661
|
-
tf.acroField.dict.set(
|
|
14810
|
+
tf.acroField.dict.set(import_pdf_lib4.PDFName.of("DA"), import_pdf_lib4.PDFString.of(daStr));
|
|
13662
14811
|
for (const w of tf.acroField.getWidgets()) {
|
|
13663
|
-
w.dict.set(
|
|
13664
|
-
w.dict.set(
|
|
14812
|
+
w.dict.set(import_pdf_lib4.PDFName.of("AP"), pdfDoc.context.obj({ N: apRef }));
|
|
14813
|
+
w.dict.set(import_pdf_lib4.PDFName.of("DA"), import_pdf_lib4.PDFString.of(daStr));
|
|
13665
14814
|
}
|
|
13666
14815
|
} else {
|
|
13667
14816
|
tf.defaultUpdateAppearances(await ensureAcroHelvetica());
|
|
@@ -13805,23 +14954,23 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13805
14954
|
};
|
|
13806
14955
|
const strokeOp = elColorType === "cmyk" ? (() => {
|
|
13807
14956
|
const cm = rgbToCmyk(strokeCol.r, strokeCol.g, strokeCol.b);
|
|
13808
|
-
return (0,
|
|
13809
|
-
})() : (0,
|
|
14957
|
+
return (0, import_pdf_lib4.setStrokingCmykColor)(cm.c, cm.m, cm.y, cm.k);
|
|
14958
|
+
})() : (0, import_pdf_lib4.setStrokingRgbColor)(strokeCol.r, strokeCol.g, strokeCol.b);
|
|
13810
14959
|
const ellipse = computeCircleMarkBezierEllipse(
|
|
13811
14960
|
{ x: left, y: pdfY, width, height },
|
|
13812
14961
|
cmEl.strokeWidthMm ?? 0.6
|
|
13813
14962
|
);
|
|
13814
14963
|
pdfPage.pushOperators(
|
|
13815
|
-
(0,
|
|
14964
|
+
(0, import_pdf_lib4.pushGraphicsState)(),
|
|
13816
14965
|
strokeOp,
|
|
13817
|
-
(0,
|
|
13818
|
-
(0,
|
|
14966
|
+
(0, import_pdf_lib4.setLineWidth)(ellipse.strokeWidthPt),
|
|
14967
|
+
(0, import_pdf_lib4.moveTo)(ellipse.start[0], ellipse.start[1]),
|
|
13819
14968
|
...ellipse.segments.map(
|
|
13820
|
-
([x1, y1, x2, y2, x3, y3]) => (0,
|
|
14969
|
+
([x1, y1, x2, y2, x3, y3]) => (0, import_pdf_lib4.appendBezierCurve)(x1, y1, x2, y2, x3, y3)
|
|
13821
14970
|
),
|
|
13822
|
-
(0,
|
|
13823
|
-
(0,
|
|
13824
|
-
(0,
|
|
14971
|
+
(0, import_pdf_lib4.closePath)(),
|
|
14972
|
+
(0, import_pdf_lib4.stroke)(),
|
|
14973
|
+
(0, import_pdf_lib4.popGraphicsState)()
|
|
13825
14974
|
);
|
|
13826
14975
|
}
|
|
13827
14976
|
} else if (el.type === "dateTime" /* DATE_TIME */) {
|
|
@@ -13842,9 +14991,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13842
14991
|
usedAcroFieldNames
|
|
13843
14992
|
);
|
|
13844
14993
|
const tf = form.createTextField(fieldName);
|
|
13845
|
-
if (dtAlign === "center") tf.setAlignment(
|
|
13846
|
-
else if (dtAlign === "right") tf.setAlignment(
|
|
13847
|
-
else tf.setAlignment(
|
|
14994
|
+
if (dtAlign === "center") tf.setAlignment(import_pdf_lib4.TextAlignment.Center);
|
|
14995
|
+
else if (dtAlign === "right") tf.setAlignment(import_pdf_lib4.TextAlignment.Right);
|
|
14996
|
+
else tf.setAlignment(import_pdf_lib4.TextAlignment.Left);
|
|
13848
14997
|
const bg = parseHexColor(dtBgHex) ?? { r: 1, g: 1, b: 1, a: 1 };
|
|
13849
14998
|
const border = parseHexColor(dtEl.style?.borderColor) ?? { r: 0.75, g: 0.82, b: 0.9, a: 1 };
|
|
13850
14999
|
const txtCol = parseHexColor(dtColorHex) ?? { r: 0.11, g: 0.11, b: 0.12, a: 1 };
|
|
@@ -13854,11 +15003,11 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13854
15003
|
y: pdfY,
|
|
13855
15004
|
width,
|
|
13856
15005
|
height,
|
|
13857
|
-
rotate: (0,
|
|
15006
|
+
rotate: (0, import_pdf_lib4.degrees)(rotDeg),
|
|
13858
15007
|
borderWidth: dtEl.style?.borderWidth ?? 1,
|
|
13859
|
-
borderColor: (0,
|
|
13860
|
-
backgroundColor: (0,
|
|
13861
|
-
textColor: (0,
|
|
15008
|
+
borderColor: (0, import_pdf_lib4.rgb)(border.r, border.g, border.b),
|
|
15009
|
+
backgroundColor: (0, import_pdf_lib4.rgb)(bg.r, bg.g, bg.b),
|
|
15010
|
+
textColor: (0, import_pdf_lib4.rgb)(txtCol.r, txtCol.g, txtCol.b)
|
|
13862
15011
|
});
|
|
13863
15012
|
if (formattedDt) {
|
|
13864
15013
|
tf.setText(formattedDt);
|
|
@@ -13866,21 +15015,21 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13866
15015
|
if (dtEl.locked) tf.enableReadOnly();
|
|
13867
15016
|
if (dtEl.required) tf.enableRequired();
|
|
13868
15017
|
tf.acroField.dict.set(
|
|
13869
|
-
|
|
13870
|
-
|
|
15018
|
+
import_pdf_lib4.PDFName.of("TU"),
|
|
15019
|
+
import_pdf_lib4.PDFHexString.fromText(
|
|
13871
15020
|
`dateTime:${dtEl.dateKind || "date"}|${dtEl.format || "YYYY-MM-DD"}|${dtEl.locale || ""}`
|
|
13872
15021
|
)
|
|
13873
15022
|
);
|
|
13874
15023
|
tf.acroField.dict.set(
|
|
13875
|
-
|
|
15024
|
+
import_pdf_lib4.PDFName.of("YudaoMeta"),
|
|
13876
15025
|
pdfDoc.context.obj({
|
|
13877
|
-
ElementType:
|
|
13878
|
-
DateKind:
|
|
13879
|
-
Format:
|
|
13880
|
-
...dtEl.locale ? { Locale:
|
|
13881
|
-
RawValue:
|
|
15026
|
+
ElementType: import_pdf_lib4.PDFName.of("dateTime"),
|
|
15027
|
+
DateKind: import_pdf_lib4.PDFString.of(dtEl.dateKind || "date"),
|
|
15028
|
+
Format: import_pdf_lib4.PDFHexString.fromText(dtEl.format || "YYYY-MM-DD"),
|
|
15029
|
+
...dtEl.locale ? { Locale: import_pdf_lib4.PDFString.of(dtEl.locale) } : {},
|
|
15030
|
+
RawValue: import_pdf_lib4.PDFHexString.fromText(rawDtVal),
|
|
13882
15031
|
FontSize: dtFontSize,
|
|
13883
|
-
Align:
|
|
15032
|
+
Align: import_pdf_lib4.PDFString.of(dtAlign),
|
|
13884
15033
|
...dtEl.characterSpacing !== void 0 ? { CharacterSpacing: dtEl.characterSpacing } : {},
|
|
13885
15034
|
Left: left,
|
|
13886
15035
|
Top: top,
|
|
@@ -13901,10 +15050,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13901
15050
|
txtCol
|
|
13902
15051
|
});
|
|
13903
15052
|
const daStr = `/FCjk ${fmtPdfNum(dtFontSize)} Tf ${fmtPdfNum(txtCol.r)} ${fmtPdfNum(txtCol.g)} ${fmtPdfNum(txtCol.b)} rg`;
|
|
13904
|
-
tf.acroField.dict.set(
|
|
15053
|
+
tf.acroField.dict.set(import_pdf_lib4.PDFName.of("DA"), import_pdf_lib4.PDFString.of(daStr));
|
|
13905
15054
|
for (const w of tf.acroField.getWidgets()) {
|
|
13906
|
-
w.dict.set(
|
|
13907
|
-
w.dict.set(
|
|
15055
|
+
w.dict.set(import_pdf_lib4.PDFName.of("AP"), pdfDoc.context.obj({ N: apRef }));
|
|
15056
|
+
w.dict.set(import_pdf_lib4.PDFName.of("DA"), import_pdf_lib4.PDFString.of(daStr));
|
|
13908
15057
|
}
|
|
13909
15058
|
} else {
|
|
13910
15059
|
tf.defaultUpdateAppearances(await ensureAcroHelvetica());
|
|
@@ -13956,10 +15105,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13956
15105
|
y: pdfY + (height - boxSz) / 2,
|
|
13957
15106
|
width: boxSz,
|
|
13958
15107
|
height: boxSz,
|
|
13959
|
-
rotate: (0,
|
|
15108
|
+
rotate: (0, import_pdf_lib4.degrees)(rotDeg),
|
|
13960
15109
|
borderWidth: 1,
|
|
13961
|
-
borderColor: (0,
|
|
13962
|
-
backgroundColor: (0,
|
|
15110
|
+
borderColor: (0, import_pdf_lib4.rgb)(0.28, 0.33, 0.41),
|
|
15111
|
+
backgroundColor: (0, import_pdf_lib4.rgb)(1, 1, 1)
|
|
13963
15112
|
});
|
|
13964
15113
|
if (isChecked) cb.check();
|
|
13965
15114
|
else cb.uncheck();
|
|
@@ -13967,14 +15116,14 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
13967
15116
|
if (cbEl.required) cb.enableRequired();
|
|
13968
15117
|
cb.defaultUpdateAppearances();
|
|
13969
15118
|
cb.acroField.dict.set(
|
|
13970
|
-
|
|
13971
|
-
|
|
15119
|
+
import_pdf_lib4.PDFName.of("TU"),
|
|
15120
|
+
import_pdf_lib4.PDFHexString.fromText(cbEl.label || fieldName)
|
|
13972
15121
|
);
|
|
13973
15122
|
cb.acroField.dict.set(
|
|
13974
|
-
|
|
15123
|
+
import_pdf_lib4.PDFName.of("YudaoMeta"),
|
|
13975
15124
|
pdfDoc.context.obj({
|
|
13976
|
-
ElementType:
|
|
13977
|
-
Label:
|
|
15125
|
+
ElementType: import_pdf_lib4.PDFName.of("checkbox"),
|
|
15126
|
+
Label: import_pdf_lib4.PDFHexString.fromText(cbEl.label || ""),
|
|
13978
15127
|
BoxWidth: boxSz,
|
|
13979
15128
|
Left: left,
|
|
13980
15129
|
Top: top,
|
|
@@ -14004,8 +15153,8 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14004
15153
|
y: pdfY + (height - boxSz) / 2,
|
|
14005
15154
|
width: boxSz,
|
|
14006
15155
|
height: boxSz,
|
|
14007
|
-
color: isChecked ? (0,
|
|
14008
|
-
borderColor: (0,
|
|
15156
|
+
color: isChecked ? (0, import_pdf_lib4.rgb)(0.15, 0.39, 0.92) : (0, import_pdf_lib4.rgb)(1, 1, 1),
|
|
15157
|
+
borderColor: (0, import_pdf_lib4.rgb)(0.28, 0.33, 0.41),
|
|
14009
15158
|
borderWidth: 1
|
|
14010
15159
|
});
|
|
14011
15160
|
await drawTextBox(
|
|
@@ -14050,10 +15199,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14050
15199
|
y: btnY,
|
|
14051
15200
|
width: btnSz,
|
|
14052
15201
|
height: btnSz,
|
|
14053
|
-
rotate: (0,
|
|
15202
|
+
rotate: (0, import_pdf_lib4.degrees)(rotDeg),
|
|
14054
15203
|
borderWidth: 1,
|
|
14055
|
-
borderColor: (0,
|
|
14056
|
-
backgroundColor: (0,
|
|
15204
|
+
borderColor: (0, import_pdf_lib4.rgb)(0.28, 0.33, 0.41),
|
|
15205
|
+
backgroundColor: (0, import_pdf_lib4.rgb)(1, 1, 1)
|
|
14057
15206
|
});
|
|
14058
15207
|
await drawTextBox(
|
|
14059
15208
|
pdfDoc,
|
|
@@ -14078,10 +15227,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14078
15227
|
y: btnY,
|
|
14079
15228
|
width: btnSz,
|
|
14080
15229
|
height: btnSz,
|
|
14081
|
-
rotate: (0,
|
|
15230
|
+
rotate: (0, import_pdf_lib4.degrees)(rotDeg),
|
|
14082
15231
|
borderWidth: 1,
|
|
14083
|
-
borderColor: (0,
|
|
14084
|
-
backgroundColor: (0,
|
|
15232
|
+
borderColor: (0, import_pdf_lib4.rgb)(0.28, 0.33, 0.41),
|
|
15233
|
+
backgroundColor: (0, import_pdf_lib4.rgb)(1, 1, 1)
|
|
14085
15234
|
});
|
|
14086
15235
|
await drawTextBox(
|
|
14087
15236
|
pdfDoc,
|
|
@@ -14105,10 +15254,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14105
15254
|
if (rgEl.required) rg.enableRequired();
|
|
14106
15255
|
rg.defaultUpdateAppearances();
|
|
14107
15256
|
rg.acroField.dict.set(
|
|
14108
|
-
|
|
15257
|
+
import_pdf_lib4.PDFName.of("YudaoMeta"),
|
|
14109
15258
|
pdfDoc.context.obj({
|
|
14110
|
-
ElementType:
|
|
14111
|
-
Direction:
|
|
15259
|
+
ElementType: import_pdf_lib4.PDFName.of("radioGroup"),
|
|
15260
|
+
Direction: import_pdf_lib4.PDFString.of(rgEl.direction || "horizontal"),
|
|
14112
15261
|
Left: left,
|
|
14113
15262
|
Top: top,
|
|
14114
15263
|
Width: width,
|
|
@@ -14164,11 +15313,11 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14164
15313
|
y: pdfY,
|
|
14165
15314
|
width,
|
|
14166
15315
|
height,
|
|
14167
|
-
rotate: (0,
|
|
15316
|
+
rotate: (0, import_pdf_lib4.degrees)(rotDeg),
|
|
14168
15317
|
borderWidth: selEl.style?.borderWidth ?? 1,
|
|
14169
|
-
borderColor: (0,
|
|
14170
|
-
backgroundColor: (0,
|
|
14171
|
-
textColor: (0,
|
|
15318
|
+
borderColor: (0, import_pdf_lib4.rgb)(border.r, border.g, border.b),
|
|
15319
|
+
backgroundColor: (0, import_pdf_lib4.rgb)(bg.r, bg.g, bg.b),
|
|
15320
|
+
textColor: (0, import_pdf_lib4.rgb)(txtCol.r, txtCol.g, txtCol.b)
|
|
14172
15321
|
});
|
|
14173
15322
|
if (curVal && baseOpts.includes(curVal)) {
|
|
14174
15323
|
dd.select(curVal);
|
|
@@ -14176,10 +15325,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14176
15325
|
if (selEl.locked) dd.enableReadOnly();
|
|
14177
15326
|
if (selEl.required) dd.enableRequired();
|
|
14178
15327
|
dd.acroField.dict.set(
|
|
14179
|
-
|
|
15328
|
+
import_pdf_lib4.PDFName.of("YudaoMeta"),
|
|
14180
15329
|
pdfDoc.context.obj({
|
|
14181
|
-
ElementType:
|
|
14182
|
-
...selEl.placeholder ? { Placeholder:
|
|
15330
|
+
ElementType: import_pdf_lib4.PDFName.of("select"),
|
|
15331
|
+
...selEl.placeholder ? { Placeholder: import_pdf_lib4.PDFHexString.fromText(selEl.placeholder) } : {},
|
|
14183
15332
|
Left: left,
|
|
14184
15333
|
Top: top,
|
|
14185
15334
|
Width: width,
|
|
@@ -14199,10 +15348,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14199
15348
|
txtCol
|
|
14200
15349
|
});
|
|
14201
15350
|
const daStr = `/FCjk ${fmtPdfNum(fsVal)} Tf ${fmtPdfNum(txtCol.r)} ${fmtPdfNum(txtCol.g)} ${fmtPdfNum(txtCol.b)} rg`;
|
|
14202
|
-
dd.acroField.dict.set(
|
|
15351
|
+
dd.acroField.dict.set(import_pdf_lib4.PDFName.of("DA"), import_pdf_lib4.PDFString.of(daStr));
|
|
14203
15352
|
for (const w of dd.acroField.getWidgets()) {
|
|
14204
|
-
w.dict.set(
|
|
14205
|
-
w.dict.set(
|
|
15353
|
+
w.dict.set(import_pdf_lib4.PDFName.of("AP"), pdfDoc.context.obj({ N: apRef }));
|
|
15354
|
+
w.dict.set(import_pdf_lib4.PDFName.of("DA"), import_pdf_lib4.PDFString.of(daStr));
|
|
14206
15355
|
}
|
|
14207
15356
|
} else {
|
|
14208
15357
|
dd.defaultUpdateAppearances(await ensureAcroHelvetica());
|
|
@@ -14242,8 +15391,8 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14242
15391
|
Type: "Annot",
|
|
14243
15392
|
Subtype: "Widget",
|
|
14244
15393
|
FT: "Sig",
|
|
14245
|
-
T:
|
|
14246
|
-
TU:
|
|
15394
|
+
T: import_pdf_lib4.PDFHexString.fromText(fieldName),
|
|
15395
|
+
TU: import_pdf_lib4.PDFHexString.fromText(sigEl.label || fieldName),
|
|
14247
15396
|
Rect: [left, pdfY, left + width, pdfY + height],
|
|
14248
15397
|
P: pdfPage.ref,
|
|
14249
15398
|
F: 4,
|
|
@@ -14251,12 +15400,12 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14251
15400
|
AP: { N: sigApRef },
|
|
14252
15401
|
MK: { R: rotDeg },
|
|
14253
15402
|
YudaoMeta: {
|
|
14254
|
-
ElementType:
|
|
14255
|
-
Label:
|
|
14256
|
-
...sigEl.signerName ? { SignerName:
|
|
14257
|
-
...sigEl.signedAt ? { SignedAt:
|
|
14258
|
-
...sigEl.reason ? { Reason:
|
|
14259
|
-
...sigEl.signatureDataUri ? { SignatureDataUri:
|
|
15403
|
+
ElementType: import_pdf_lib4.PDFName.of("signature"),
|
|
15404
|
+
Label: import_pdf_lib4.PDFHexString.fromText(sigEl.label || "Signature"),
|
|
15405
|
+
...sigEl.signerName ? { SignerName: import_pdf_lib4.PDFHexString.fromText(sigEl.signerName) } : {},
|
|
15406
|
+
...sigEl.signedAt ? { SignedAt: import_pdf_lib4.PDFString.of(sigEl.signedAt) } : {},
|
|
15407
|
+
...sigEl.reason ? { Reason: import_pdf_lib4.PDFHexString.fromText(sigEl.reason) } : {},
|
|
15408
|
+
...sigEl.signatureDataUri ? { SignatureDataUri: import_pdf_lib4.PDFString.of(sigEl.signatureDataUri) } : {},
|
|
14260
15409
|
Left: left,
|
|
14261
15410
|
Top: top,
|
|
14262
15411
|
Width: width,
|
|
@@ -14267,11 +15416,11 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14267
15416
|
if (sigEl.signerName || sigEl.signatureDataUri) {
|
|
14268
15417
|
sigWidgetObj.V = pdfDoc.context.obj({
|
|
14269
15418
|
Type: "Sig",
|
|
14270
|
-
Filter:
|
|
14271
|
-
SubFilter:
|
|
14272
|
-
Name:
|
|
14273
|
-
...sigEl.signedAt ? { M:
|
|
14274
|
-
...sigEl.reason ? { Reason:
|
|
15419
|
+
Filter: import_pdf_lib4.PDFName.of("Adobe.PPKLite"),
|
|
15420
|
+
SubFilter: import_pdf_lib4.PDFName.of("adbe.pkcs7.detached"),
|
|
15421
|
+
Name: import_pdf_lib4.PDFHexString.fromText(sigEl.signerName || sigEl.label || "Signed"),
|
|
15422
|
+
...sigEl.signedAt ? { M: import_pdf_lib4.PDFString.of(sigEl.signedAt) } : {},
|
|
15423
|
+
...sigEl.reason ? { Reason: import_pdf_lib4.PDFHexString.fromText(sigEl.reason) } : {}
|
|
14275
15424
|
});
|
|
14276
15425
|
}
|
|
14277
15426
|
const sigRef = pdfDoc.context.register(pdfDoc.context.obj(sigWidgetObj));
|
|
@@ -14283,8 +15432,8 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14283
15432
|
y: pdfY,
|
|
14284
15433
|
width,
|
|
14285
15434
|
height,
|
|
14286
|
-
color: (0,
|
|
14287
|
-
borderColor: (0,
|
|
15435
|
+
color: (0, import_pdf_lib4.rgb)(0.98, 0.985, 0.995),
|
|
15436
|
+
borderColor: (0, import_pdf_lib4.rgb)(0.55, 0.62, 0.72),
|
|
14288
15437
|
borderWidth: 0.9,
|
|
14289
15438
|
borderDashArray: sigEl.signerName || sigEl.signatureDataUri ? void 0 : [3, 2]
|
|
14290
15439
|
});
|
|
@@ -14292,7 +15441,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14292
15441
|
start: { x: left + 6, y: pdfY + 8 },
|
|
14293
15442
|
end: { x: left + Math.max(12, width - 6), y: pdfY + 8 },
|
|
14294
15443
|
thickness: 0.65,
|
|
14295
|
-
color: (0,
|
|
15444
|
+
color: (0, import_pdf_lib4.rgb)(0.45, 0.52, 0.62)
|
|
14296
15445
|
});
|
|
14297
15446
|
if (sigEl.signatureDataUri) {
|
|
14298
15447
|
const sigImgEntry = await embedImageWithMetaFromSrc(pdfDoc, sigEl.signatureDataUri);
|
|
@@ -14364,13 +15513,13 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14364
15513
|
drawH
|
|
14365
15514
|
);
|
|
14366
15515
|
pdfPage.pushOperators(
|
|
14367
|
-
(0,
|
|
14368
|
-
(0,
|
|
14369
|
-
(0,
|
|
14370
|
-
(0,
|
|
14371
|
-
(0,
|
|
14372
|
-
(0,
|
|
14373
|
-
(0,
|
|
15516
|
+
(0, import_pdf_lib4.pushGraphicsState)(),
|
|
15517
|
+
(0, import_pdf_lib4.rectangle)(clipX, clipY, clipW, clipH),
|
|
15518
|
+
(0, import_pdf_lib4.clip)(),
|
|
15519
|
+
(0, import_pdf_lib4.endPath)(),
|
|
15520
|
+
(0, import_pdf_lib4.concatTransformationMatrix)(ma, mb, mc, md, me, mf),
|
|
15521
|
+
(0, import_pdf_lib4.drawObject)(imgKey),
|
|
15522
|
+
(0, import_pdf_lib4.popGraphicsState)()
|
|
14374
15523
|
);
|
|
14375
15524
|
} else if (img && exifOrientation !== 1) {
|
|
14376
15525
|
const fitMode = el.fit ?? "contain";
|
|
@@ -14394,20 +15543,20 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14394
15543
|
);
|
|
14395
15544
|
if (placement2.needsClip) {
|
|
14396
15545
|
pdfPage.pushOperators(
|
|
14397
|
-
(0,
|
|
14398
|
-
(0,
|
|
14399
|
-
(0,
|
|
14400
|
-
(0,
|
|
14401
|
-
(0,
|
|
14402
|
-
(0,
|
|
14403
|
-
(0,
|
|
15546
|
+
(0, import_pdf_lib4.pushGraphicsState)(),
|
|
15547
|
+
(0, import_pdf_lib4.rectangle)(placement2.clipX, placement2.clipY, placement2.clipWidth, placement2.clipHeight),
|
|
15548
|
+
(0, import_pdf_lib4.clip)(),
|
|
15549
|
+
(0, import_pdf_lib4.endPath)(),
|
|
15550
|
+
(0, import_pdf_lib4.concatTransformationMatrix)(ma, mb, mc, md, me, mf),
|
|
15551
|
+
(0, import_pdf_lib4.drawObject)(imgKey),
|
|
15552
|
+
(0, import_pdf_lib4.popGraphicsState)()
|
|
14404
15553
|
);
|
|
14405
15554
|
} else {
|
|
14406
15555
|
pdfPage.pushOperators(
|
|
14407
|
-
(0,
|
|
14408
|
-
(0,
|
|
14409
|
-
(0,
|
|
14410
|
-
(0,
|
|
15556
|
+
(0, import_pdf_lib4.pushGraphicsState)(),
|
|
15557
|
+
(0, import_pdf_lib4.concatTransformationMatrix)(ma, mb, mc, md, me, mf),
|
|
15558
|
+
(0, import_pdf_lib4.drawObject)(imgKey),
|
|
15559
|
+
(0, import_pdf_lib4.popGraphicsState)()
|
|
14411
15560
|
);
|
|
14412
15561
|
}
|
|
14413
15562
|
} else if (img) {
|
|
@@ -14421,10 +15570,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14421
15570
|
);
|
|
14422
15571
|
if (placement2.needsClip) {
|
|
14423
15572
|
pdfPage.pushOperators(
|
|
14424
|
-
(0,
|
|
14425
|
-
(0,
|
|
14426
|
-
(0,
|
|
14427
|
-
(0,
|
|
15573
|
+
(0, import_pdf_lib4.pushGraphicsState)(),
|
|
15574
|
+
(0, import_pdf_lib4.rectangle)(placement2.clipX, placement2.clipY, placement2.clipWidth, placement2.clipHeight),
|
|
15575
|
+
(0, import_pdf_lib4.clip)(),
|
|
15576
|
+
(0, import_pdf_lib4.endPath)()
|
|
14428
15577
|
);
|
|
14429
15578
|
pdfPage.drawImage(img, {
|
|
14430
15579
|
x: placement2.drawX,
|
|
@@ -14433,7 +15582,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14433
15582
|
height: placement2.drawHeight,
|
|
14434
15583
|
opacity: el.opacity
|
|
14435
15584
|
});
|
|
14436
|
-
pdfPage.pushOperators((0,
|
|
15585
|
+
pdfPage.pushOperators((0, import_pdf_lib4.popGraphicsState)());
|
|
14437
15586
|
} else {
|
|
14438
15587
|
pdfPage.drawImage(img, {
|
|
14439
15588
|
x: placement2.drawX,
|
|
@@ -14523,7 +15672,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14523
15672
|
y: pdfY,
|
|
14524
15673
|
width,
|
|
14525
15674
|
height,
|
|
14526
|
-
color: (0,
|
|
15675
|
+
color: (0, import_pdf_lib4.rgb)(col.r, col.g, col.b),
|
|
14527
15676
|
opacity: op,
|
|
14528
15677
|
borderWidth: 0
|
|
14529
15678
|
});
|
|
@@ -14532,7 +15681,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14532
15681
|
start: { x: left, y: pdfY + 1.5 },
|
|
14533
15682
|
end: { x: left + width, y: pdfY + 1.5 },
|
|
14534
15683
|
thickness: 1.5,
|
|
14535
|
-
color: (0,
|
|
15684
|
+
color: (0, import_pdf_lib4.rgb)(col.r, col.g, col.b),
|
|
14536
15685
|
opacity: op
|
|
14537
15686
|
});
|
|
14538
15687
|
} else if (annotType === "strikeout") {
|
|
@@ -14540,7 +15689,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14540
15689
|
start: { x: left, y: pdfY + height / 2 },
|
|
14541
15690
|
end: { x: left + width, y: pdfY + height / 2 },
|
|
14542
15691
|
thickness: 1.5,
|
|
14543
|
-
color: (0,
|
|
15692
|
+
color: (0, import_pdf_lib4.rgb)(col.r, col.g, col.b),
|
|
14544
15693
|
opacity: op
|
|
14545
15694
|
});
|
|
14546
15695
|
} else if (annotType === "squiggly") {
|
|
@@ -14558,7 +15707,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14558
15707
|
pdfPage.drawSvgPath(segments.join(" "), {
|
|
14559
15708
|
x: left,
|
|
14560
15709
|
y: pageHeight - top,
|
|
14561
|
-
borderColor: (0,
|
|
15710
|
+
borderColor: (0, import_pdf_lib4.rgb)(col.r, col.g, col.b),
|
|
14562
15711
|
borderWidth: 1.3,
|
|
14563
15712
|
borderOpacity: op
|
|
14564
15713
|
});
|
|
@@ -14569,8 +15718,8 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14569
15718
|
y: pdfY,
|
|
14570
15719
|
width,
|
|
14571
15720
|
height,
|
|
14572
|
-
color: (0,
|
|
14573
|
-
borderColor: (0,
|
|
15721
|
+
color: (0, import_pdf_lib4.rgb)(1, 0.97, 0.86),
|
|
15722
|
+
borderColor: (0, import_pdf_lib4.rgb)(col.r, col.g, col.b),
|
|
14574
15723
|
borderWidth: 1.2,
|
|
14575
15724
|
opacity: op
|
|
14576
15725
|
});
|
|
@@ -14580,13 +15729,13 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14580
15729
|
start: { x: lineLeft, y: pdfY + height * 0.65 },
|
|
14581
15730
|
end: { x: lineRight, y: pdfY + height * 0.65 },
|
|
14582
15731
|
thickness: 1,
|
|
14583
|
-
color: (0,
|
|
15732
|
+
color: (0, import_pdf_lib4.rgb)(col.r, col.g, col.b)
|
|
14584
15733
|
});
|
|
14585
15734
|
pdfPage.drawLine({
|
|
14586
15735
|
start: { x: lineLeft, y: pdfY + height * 0.4 },
|
|
14587
15736
|
end: { x: lineLeft + (lineRight - lineLeft) * 0.72, y: pdfY + height * 0.4 },
|
|
14588
15737
|
thickness: 1,
|
|
14589
|
-
color: (0,
|
|
15738
|
+
color: (0, import_pdf_lib4.rgb)(col.r, col.g, col.b)
|
|
14590
15739
|
});
|
|
14591
15740
|
}
|
|
14592
15741
|
const pdfSubtype = annotType === "highlight" ? "Highlight" : annotType === "underline" ? "Underline" : annotType === "strikeout" ? "StrikeOut" : annotType === "squiggly" ? "Squiggly" : "Text";
|
|
@@ -14601,8 +15750,8 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14601
15750
|
Rect: [left, pdfY, left + width, pdfY + height],
|
|
14602
15751
|
C: [col.r, col.g, col.b],
|
|
14603
15752
|
CA: op,
|
|
14604
|
-
T:
|
|
14605
|
-
Contents:
|
|
15753
|
+
T: import_pdf_lib4.PDFHexString.fromText(annotEl.author || "Reviewer"),
|
|
15754
|
+
Contents: import_pdf_lib4.PDFHexString.fromText(threadSummary)
|
|
14606
15755
|
};
|
|
14607
15756
|
if (pdfSubtype !== "Text") {
|
|
14608
15757
|
annotDictEntries.QuadPoints = [
|
|
@@ -14625,7 +15774,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14625
15774
|
y: pdfY,
|
|
14626
15775
|
width,
|
|
14627
15776
|
height,
|
|
14628
|
-
color: (0,
|
|
15777
|
+
color: (0, import_pdf_lib4.rgb)(fill.r, fill.g, fill.b),
|
|
14629
15778
|
opacity: 1,
|
|
14630
15779
|
borderWidth: 0
|
|
14631
15780
|
});
|
|
@@ -14658,10 +15807,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14658
15807
|
}
|
|
14659
15808
|
} finally {
|
|
14660
15809
|
if (hasOpenCenterTransform) {
|
|
14661
|
-
pdfPage.pushOperators((0,
|
|
15810
|
+
pdfPage.pushOperators((0, import_pdf_lib4.popGraphicsState)());
|
|
14662
15811
|
}
|
|
14663
15812
|
while (openBdcCount > 0) {
|
|
14664
|
-
pdfPage.pushOperators(
|
|
15813
|
+
pdfPage.pushOperators(import_pdf_lib4.PDFOperator.of("EMC"));
|
|
14665
15814
|
openBdcCount--;
|
|
14666
15815
|
}
|
|
14667
15816
|
}
|
|
@@ -14691,7 +15840,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14691
15840
|
const batesFs = 8.5;
|
|
14692
15841
|
const marginX = 18;
|
|
14693
15842
|
if (!hasNonAscii(batesStr) && cjkState?.mode !== "subset-ttf") {
|
|
14694
|
-
const batesFont = await pdfDoc.embedFont(
|
|
15843
|
+
const batesFont = await pdfDoc.embedFont(import_pdf_lib4.StandardFonts.HelveticaBold);
|
|
14695
15844
|
const textW = batesFont.widthOfTextAtSize(batesStr, batesFs);
|
|
14696
15845
|
const bx = pos === "topLeft" || pos === "bottomLeft" ? marginX : Math.max(marginX, pageWidth - marginX - textW);
|
|
14697
15846
|
const by = pos === "bottomLeft" || pos === "bottomRight" ? 14 : Math.max(14, pageHeight - 14 - batesFs);
|
|
@@ -14700,7 +15849,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14700
15849
|
y: by,
|
|
14701
15850
|
size: batesFs,
|
|
14702
15851
|
font: batesFont,
|
|
14703
|
-
color: (0,
|
|
15852
|
+
color: (0, import_pdf_lib4.rgb)(0.18, 0.22, 0.3)
|
|
14704
15853
|
});
|
|
14705
15854
|
} else {
|
|
14706
15855
|
const boxW = Math.min(220, pageWidth - marginX * 2);
|
|
@@ -14736,7 +15885,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14736
15885
|
const wmRgb = parseHexColor(wmCfg?.color) ?? { r: 0.4, g: 0.45, b: 0.55 };
|
|
14737
15886
|
const isTiled = wmCfg?.tiled !== false;
|
|
14738
15887
|
if (!hasNonAscii(watermarkText)) {
|
|
14739
|
-
const wmFont = await pdfDoc.embedFont(
|
|
15888
|
+
const wmFont = await pdfDoc.embedFont(import_pdf_lib4.StandardFonts.HelveticaBold);
|
|
14740
15889
|
if (isTiled) {
|
|
14741
15890
|
for (let wy = 90; wy < pageHeight - 40; wy += 180) {
|
|
14742
15891
|
for (let wx = 50; wx < pageWidth2 - 40; wx += 220) {
|
|
@@ -14745,9 +15894,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14745
15894
|
y: wy,
|
|
14746
15895
|
size: wmSize,
|
|
14747
15896
|
font: wmFont,
|
|
14748
|
-
color: (0,
|
|
15897
|
+
color: (0, import_pdf_lib4.rgb)(wmRgb.r, wmRgb.g, wmRgb.b),
|
|
14749
15898
|
opacity: wmOpacity,
|
|
14750
|
-
rotate: (0,
|
|
15899
|
+
rotate: (0, import_pdf_lib4.degrees)(wmAngle)
|
|
14751
15900
|
});
|
|
14752
15901
|
}
|
|
14753
15902
|
}
|
|
@@ -14757,9 +15906,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14757
15906
|
y: Math.max(40, pageHeight * 0.45),
|
|
14758
15907
|
size: wmSize * 1.5,
|
|
14759
15908
|
font: wmFont,
|
|
14760
|
-
color: (0,
|
|
15909
|
+
color: (0, import_pdf_lib4.rgb)(wmRgb.r, wmRgb.g, wmRgb.b),
|
|
14761
15910
|
opacity: wmOpacity,
|
|
14762
|
-
rotate: (0,
|
|
15911
|
+
rotate: (0, import_pdf_lib4.degrees)(wmAngle)
|
|
14763
15912
|
});
|
|
14764
15913
|
}
|
|
14765
15914
|
} else if (cjkState) {
|
|
@@ -14768,14 +15917,14 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14768
15917
|
for (let wy = 90; wy < pageHeight - 40; wy += isTiled ? 185 : pageHeight) {
|
|
14769
15918
|
for (let wx = 45; wx < pageWidth2 - 50; wx += isTiled ? 225 : pageWidth2) {
|
|
14770
15919
|
pdfPage.pushOperators(
|
|
14771
|
-
(0,
|
|
14772
|
-
(0,
|
|
14773
|
-
(0,
|
|
14774
|
-
(0,
|
|
14775
|
-
(0,
|
|
14776
|
-
(0,
|
|
14777
|
-
(0,
|
|
14778
|
-
(0,
|
|
15920
|
+
(0, import_pdf_lib4.pushGraphicsState)(),
|
|
15921
|
+
(0, import_pdf_lib4.beginText)(),
|
|
15922
|
+
(0, import_pdf_lib4.setFillingRgbColor)(0.78, 0.81, 0.86),
|
|
15923
|
+
(0, import_pdf_lib4.setFontAndSize)(fontKey, wmSize),
|
|
15924
|
+
(0, import_pdf_lib4.rotateAndSkewTextDegreesAndTranslate)(wmAngle, 0, 0, wx, wy),
|
|
15925
|
+
(0, import_pdf_lib4.showText)(import_pdf_lib4.PDFHexString.of(hexWm)),
|
|
15926
|
+
(0, import_pdf_lib4.endText)(),
|
|
15927
|
+
(0, import_pdf_lib4.popGraphicsState)()
|
|
14779
15928
|
);
|
|
14780
15929
|
}
|
|
14781
15930
|
}
|
|
@@ -14797,7 +15946,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14797
15946
|
width: 170,
|
|
14798
15947
|
height: 30,
|
|
14799
15948
|
opacity: 0.15,
|
|
14800
|
-
rotate: (0,
|
|
15949
|
+
rotate: (0, import_pdf_lib4.degrees)(26)
|
|
14801
15950
|
});
|
|
14802
15951
|
}
|
|
14803
15952
|
}
|
|
@@ -14821,7 +15970,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14821
15970
|
}
|
|
14822
15971
|
return void 0;
|
|
14823
15972
|
};
|
|
14824
|
-
return walk(snapshot.metadata?.bookmarks);
|
|
15973
|
+
return walk(snapshot.bookmarks ?? snapshot.metadata?.bookmarks);
|
|
14825
15974
|
};
|
|
14826
15975
|
for (const linkItem of deferredLinkAnnotations) {
|
|
14827
15976
|
const hostPage = allPages[linkItem.hostPageIndex];
|
|
@@ -14836,9 +15985,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14836
15985
|
const targetPage = allPages[clampedIdx];
|
|
14837
15986
|
const destArr = pdfDoc.context.obj([
|
|
14838
15987
|
targetPage.ref,
|
|
14839
|
-
|
|
14840
|
-
|
|
14841
|
-
|
|
15988
|
+
import_pdf_lib4.PDFName.of("XYZ"),
|
|
15989
|
+
import_pdf_lib4.PDFNumber.of(elDest.x),
|
|
15990
|
+
import_pdf_lib4.PDFNumber.of(elDest.topY),
|
|
14842
15991
|
null
|
|
14843
15992
|
]);
|
|
14844
15993
|
const actionDict = pdfDoc.context.obj({
|
|
@@ -14867,9 +16016,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14867
16016
|
const targetPage = allPages[clampedIdx];
|
|
14868
16017
|
const destArr = pdfDoc.context.obj([
|
|
14869
16018
|
targetPage.ref,
|
|
14870
|
-
|
|
14871
|
-
|
|
14872
|
-
|
|
16019
|
+
import_pdf_lib4.PDFName.of("XYZ"),
|
|
16020
|
+
import_pdf_lib4.PDFNumber.of(0),
|
|
16021
|
+
import_pdf_lib4.PDFNumber.of(targetPage.getHeight()),
|
|
14873
16022
|
null
|
|
14874
16023
|
]);
|
|
14875
16024
|
const actionDict = pdfDoc.context.obj({
|
|
@@ -14897,7 +16046,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14897
16046
|
const actionDict = pdfDoc.context.obj({
|
|
14898
16047
|
Type: "Action",
|
|
14899
16048
|
S: "URI",
|
|
14900
|
-
URI:
|
|
16049
|
+
URI: import_pdf_lib4.PDFString.of(trimmedUrl)
|
|
14901
16050
|
});
|
|
14902
16051
|
const linkAnnot = pdfDoc.context.obj({
|
|
14903
16052
|
Type: "Annot",
|
|
@@ -14910,7 +16059,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14910
16059
|
} else if (typeof linkItem.linkPageIndex === "number" && linkItem.linkPageIndex >= 0 && allPages.length > 0) {
|
|
14911
16060
|
const clampedIdx = Math.min(allPages.length - 1, Math.floor(linkItem.linkPageIndex));
|
|
14912
16061
|
const targetPage = allPages[clampedIdx];
|
|
14913
|
-
const destArr = pdfDoc.context.obj([targetPage.ref,
|
|
16062
|
+
const destArr = pdfDoc.context.obj([targetPage.ref, import_pdf_lib4.PDFName.of("XYZ"), null, null, null]);
|
|
14914
16063
|
const linkAnnot = pdfDoc.context.obj({
|
|
14915
16064
|
Type: "Annot",
|
|
14916
16065
|
Subtype: "Link",
|
|
@@ -14922,8 +16071,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14922
16071
|
}
|
|
14923
16072
|
}
|
|
14924
16073
|
}
|
|
14925
|
-
|
|
14926
|
-
|
|
16074
|
+
const effectiveBookmarks = snapshot.bookmarks ?? snapshot.metadata?.bookmarks;
|
|
16075
|
+
if (effectiveBookmarks && effectiveBookmarks.length > 0) {
|
|
16076
|
+
attachPdfOutlinesTree(pdfDoc, effectiveBookmarks);
|
|
14927
16077
|
}
|
|
14928
16078
|
const attachments = snapshot.attachments ?? snapshot.metadata?.attachments ?? [];
|
|
14929
16079
|
if (attachments.length > 0) {
|
|
@@ -14935,28 +16085,28 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14935
16085
|
const pieceDict = {};
|
|
14936
16086
|
if (sigEnv) {
|
|
14937
16087
|
pieceDict.UniverSignature = {
|
|
14938
|
-
LastModified:
|
|
16088
|
+
LastModified: import_pdf_lib4.PDFString.of(sigEnv.signedAt || (/* @__PURE__ */ new Date()).toISOString()),
|
|
14939
16089
|
Private: pdfDoc.context.obj({
|
|
14940
|
-
Algorithm:
|
|
14941
|
-
Signer:
|
|
14942
|
-
CertificateSubject:
|
|
14943
|
-
ContentDigest:
|
|
14944
|
-
EnvelopeDigest:
|
|
16090
|
+
Algorithm: import_pdf_lib4.PDFName.of("SHA-256"),
|
|
16091
|
+
Signer: import_pdf_lib4.PDFHexString.fromText(sigEnv.signerName),
|
|
16092
|
+
CertificateSubject: import_pdf_lib4.PDFHexString.fromText(sigEnv.certificateSubject),
|
|
16093
|
+
ContentDigest: import_pdf_lib4.PDFString.of(sigEnv.contentDigestHex),
|
|
16094
|
+
EnvelopeDigest: import_pdf_lib4.PDFString.of(sigEnv.envelopeDigestHex)
|
|
14945
16095
|
})
|
|
14946
16096
|
};
|
|
14947
16097
|
}
|
|
14948
16098
|
if (secPerms) {
|
|
14949
16099
|
pieceDict.UniverSecurity = {
|
|
14950
|
-
LastModified:
|
|
16100
|
+
LastModified: import_pdf_lib4.PDFString.of((/* @__PURE__ */ new Date()).toISOString()),
|
|
14951
16101
|
Private: pdfDoc.context.obj({
|
|
14952
|
-
AllowPrint: secPerms.allowPrint !== false ?
|
|
14953
|
-
AllowCopy: secPerms.allowCopy !== false ?
|
|
14954
|
-
AllowModify: secPerms.allowModify !== false ?
|
|
14955
|
-
...secPerms.openPasswordHash ? { OpenPasswordHash:
|
|
16102
|
+
AllowPrint: secPerms.allowPrint !== false ? import_pdf_lib4.PDFBool.True : import_pdf_lib4.PDFBool.False,
|
|
16103
|
+
AllowCopy: secPerms.allowCopy !== false ? import_pdf_lib4.PDFBool.True : import_pdf_lib4.PDFBool.False,
|
|
16104
|
+
AllowModify: secPerms.allowModify !== false ? import_pdf_lib4.PDFBool.True : import_pdf_lib4.PDFBool.False,
|
|
16105
|
+
...secPerms.openPasswordHash ? { OpenPasswordHash: import_pdf_lib4.PDFString.of(secPerms.openPasswordHash) } : {}
|
|
14956
16106
|
})
|
|
14957
16107
|
};
|
|
14958
16108
|
}
|
|
14959
|
-
pdfDoc.catalog.set(
|
|
16109
|
+
pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("PieceInfo"), pdfDoc.context.obj(pieceDict));
|
|
14960
16110
|
}
|
|
14961
16111
|
if (accessibilityTagged) {
|
|
14962
16112
|
attachTaggedStructTreeRoot(pdfDoc, snapshot, taggedStructItems, totalPhysicalPages);
|
|
@@ -14967,85 +16117,95 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
14967
16117
|
if (interactiveForm && hasAnyAcroWidget) {
|
|
14968
16118
|
const acroDict = pdfDoc.getForm().acroForm.dict;
|
|
14969
16119
|
const helv = await ensureAcroHelvetica();
|
|
14970
|
-
let drDict = pdfDoc.context.lookupMaybe(acroDict.get(
|
|
16120
|
+
let drDict = pdfDoc.context.lookupMaybe(acroDict.get(import_pdf_lib4.PDFName.of("DR")), import_pdf_lib4.PDFDict);
|
|
14971
16121
|
if (!drDict) {
|
|
14972
16122
|
drDict = pdfDoc.context.obj({});
|
|
14973
|
-
acroDict.set(
|
|
16123
|
+
acroDict.set(import_pdf_lib4.PDFName.of("DR"), drDict);
|
|
14974
16124
|
}
|
|
14975
|
-
let fontDict = pdfDoc.context.lookupMaybe(drDict.get(
|
|
16125
|
+
let fontDict = pdfDoc.context.lookupMaybe(drDict.get(import_pdf_lib4.PDFName.of("Font")), import_pdf_lib4.PDFDict);
|
|
14976
16126
|
if (!fontDict) {
|
|
14977
16127
|
fontDict = pdfDoc.context.obj({});
|
|
14978
|
-
drDict.set(
|
|
16128
|
+
drDict.set(import_pdf_lib4.PDFName.of("Font"), fontDict);
|
|
14979
16129
|
}
|
|
14980
|
-
fontDict.set(
|
|
16130
|
+
fontDict.set(import_pdf_lib4.PDFName.of("Helv"), helv.ref);
|
|
14981
16131
|
if (acroCjkState) {
|
|
14982
|
-
fontDict.set(
|
|
16132
|
+
fontDict.set(import_pdf_lib4.PDFName.of("FCjk"), acroCjkState.type0FontRef);
|
|
14983
16133
|
}
|
|
14984
16134
|
acroDict.set(
|
|
14985
|
-
|
|
14986
|
-
|
|
16135
|
+
import_pdf_lib4.PDFName.of("DA"),
|
|
16136
|
+
import_pdf_lib4.PDFString.of(acroCjkState ? "/FCjk 11 Tf 0 0 0 rg" : "/Helv 11 Tf 0 0 0 rg")
|
|
14987
16137
|
);
|
|
14988
|
-
acroDict.delete(
|
|
16138
|
+
acroDict.delete(import_pdf_lib4.PDFName.of("NeedAppearances"));
|
|
14989
16139
|
}
|
|
14990
16140
|
if (optimizeSize) {
|
|
14991
16141
|
pruneUnreferencedObjectsAndCompressStreams(pdfDoc);
|
|
14992
16142
|
}
|
|
16143
|
+
const effectiveSecurity = options?.security ?? snapshot.security ?? snapshot.metadata?.security;
|
|
16144
|
+
const shouldEncrypt = isPdfSecurityActive(effectiveSecurity);
|
|
14993
16145
|
throwIfExportAborted();
|
|
16146
|
+
if (shouldEncrypt && !options?.diagnosticGridOverlay) {
|
|
16147
|
+
await applyPdfSecurityToDocument(pdfDoc, effectiveSecurity);
|
|
16148
|
+
const encryptedSavedBytes = interactiveForm && hasAnyAcroWidget ? await pdfDoc.save({ useObjectStreams: false, updateFieldAppearances: false }) : await pdfDoc.save({ useObjectStreams: false });
|
|
16149
|
+
throwIfExportAborted();
|
|
16150
|
+
return encryptedSavedBytes;
|
|
16151
|
+
}
|
|
14994
16152
|
const savedPdfBytes = interactiveForm && hasAnyAcroWidget ? await pdfDoc.save({ updateFieldAppearances: false }) : await pdfDoc.save();
|
|
14995
16153
|
throwIfExportAborted();
|
|
14996
16154
|
if (options?.diagnosticGridOverlay) {
|
|
14997
16155
|
const gridOpts = typeof options.diagnosticGridOverlay === "object" ? options.diagnosticGridOverlay : void 0;
|
|
14998
|
-
|
|
16156
|
+
const overlaidBytes = await overlayDiagnosticGridOnPdfBytes(savedPdfBytes, snapshot, gridOpts);
|
|
16157
|
+
return shouldEncrypt ? await encryptPdfBytes(overlaidBytes, effectiveSecurity) : overlaidBytes;
|
|
14999
16158
|
}
|
|
15000
16159
|
return savedPdfBytes;
|
|
15001
16160
|
}
|
|
16161
|
+
var exportPdfUnitToBytes = exportPdfBytes;
|
|
15002
16162
|
function decodePdfObjAsString(obj) {
|
|
15003
16163
|
if (!obj) return "";
|
|
15004
|
-
if (obj instanceof
|
|
16164
|
+
if (obj instanceof import_pdf_lib4.PDFHexString || obj instanceof import_pdf_lib4.PDFString || obj instanceof import_pdf_lib4.PDFName) {
|
|
15005
16165
|
return obj.decodeText();
|
|
15006
16166
|
}
|
|
15007
16167
|
return "";
|
|
15008
16168
|
}
|
|
15009
16169
|
function extractSigDictValue(doc, fieldOrWidgetDict) {
|
|
15010
|
-
const metaDict = doc.context.lookupMaybe(fieldOrWidgetDict.get(
|
|
16170
|
+
const metaDict = doc.context.lookupMaybe(fieldOrWidgetDict.get(import_pdf_lib4.PDFName.of("YudaoMeta")), import_pdf_lib4.PDFDict);
|
|
15011
16171
|
if (metaDict) {
|
|
15012
|
-
const dataUri = decodePdfObjAsString(metaDict.get(
|
|
16172
|
+
const dataUri = decodePdfObjAsString(metaDict.get(import_pdf_lib4.PDFName.of("SignatureDataUri")));
|
|
15013
16173
|
if (dataUri) return dataUri;
|
|
15014
|
-
const signer = decodePdfObjAsString(metaDict.get(
|
|
16174
|
+
const signer = decodePdfObjAsString(metaDict.get(import_pdf_lib4.PDFName.of("SignerName")));
|
|
15015
16175
|
if (signer) return signer;
|
|
15016
16176
|
}
|
|
15017
|
-
const vDict = doc.context.lookupMaybe(fieldOrWidgetDict.get(
|
|
16177
|
+
const vDict = doc.context.lookupMaybe(fieldOrWidgetDict.get(import_pdf_lib4.PDFName.of("V")), import_pdf_lib4.PDFDict);
|
|
15018
16178
|
if (vDict) {
|
|
15019
|
-
const signerName = decodePdfObjAsString(vDict.get(
|
|
16179
|
+
const signerName = decodePdfObjAsString(vDict.get(import_pdf_lib4.PDFName.of("Name")));
|
|
15020
16180
|
if (signerName) return signerName;
|
|
15021
|
-
if (vDict.get(
|
|
16181
|
+
if (vDict.get(import_pdf_lib4.PDFName.of("Contents")) || vDict.get(import_pdf_lib4.PDFName.of("Type"))) {
|
|
15022
16182
|
return "signed";
|
|
15023
16183
|
}
|
|
15024
16184
|
}
|
|
15025
|
-
const vStr = decodePdfObjAsString(fieldOrWidgetDict.get(
|
|
16185
|
+
const vStr = decodePdfObjAsString(fieldOrWidgetDict.get(import_pdf_lib4.PDFName.of("V")));
|
|
15026
16186
|
return vStr || "";
|
|
15027
16187
|
}
|
|
15028
16188
|
async function extractAcroFormValuesFromPdfBytes(pdfBytes) {
|
|
15029
|
-
const doc = await
|
|
16189
|
+
const doc = await import_pdf_lib4.PDFDocument.load(pdfBytes, { ignoreEncryption: true });
|
|
15030
16190
|
const form = doc.getForm();
|
|
15031
16191
|
const fields = form.getFields();
|
|
15032
16192
|
const values = {};
|
|
15033
16193
|
for (const field of fields) {
|
|
15034
16194
|
const name = field.getName();
|
|
15035
|
-
if (field instanceof
|
|
16195
|
+
if (field instanceof import_pdf_lib4.PDFCheckBox) {
|
|
15036
16196
|
values[name] = field.isChecked();
|
|
15037
|
-
} else if (field instanceof
|
|
16197
|
+
} else if (field instanceof import_pdf_lib4.PDFTextField) {
|
|
15038
16198
|
values[name] = field.getText() ?? "";
|
|
15039
|
-
} else if (field instanceof
|
|
16199
|
+
} else if (field instanceof import_pdf_lib4.PDFDropdown) {
|
|
15040
16200
|
const selected = field.getSelected();
|
|
15041
16201
|
values[name] = selected[0] ?? "";
|
|
15042
|
-
} else if (field instanceof
|
|
16202
|
+
} else if (field instanceof import_pdf_lib4.PDFOptionList) {
|
|
15043
16203
|
const selected = field.getSelected();
|
|
15044
16204
|
values[name] = selected.length > 1 ? selected.join(", ") : selected[0] ?? "";
|
|
15045
|
-
} else if (field instanceof
|
|
16205
|
+
} else if (field instanceof import_pdf_lib4.PDFRadioGroup) {
|
|
15046
16206
|
values[name] = field.getSelected() ?? "";
|
|
15047
16207
|
} else {
|
|
15048
|
-
const ft = decodePdfObjAsString(field.acroField.dict.get(
|
|
16208
|
+
const ft = decodePdfObjAsString(field.acroField.dict.get(import_pdf_lib4.PDFName.of("FT")));
|
|
15049
16209
|
if (ft === "Sig") {
|
|
15050
16210
|
values[name] = extractSigDictValue(doc, field.acroField.dict);
|
|
15051
16211
|
}
|
|
@@ -15055,17 +16215,17 @@ async function extractAcroFormValuesFromPdfBytes(pdfBytes) {
|
|
|
15055
16215
|
const annots = page.node.Annots();
|
|
15056
16216
|
if (!annots) continue;
|
|
15057
16217
|
for (let i = 0; i < annots.size(); i++) {
|
|
15058
|
-
const wDict = doc.context.lookupMaybe(annots.get(i),
|
|
16218
|
+
const wDict = doc.context.lookupMaybe(annots.get(i), import_pdf_lib4.PDFDict);
|
|
15059
16219
|
if (!wDict) continue;
|
|
15060
|
-
if (decodePdfObjAsString(wDict.get(
|
|
15061
|
-
const tName = decodePdfObjAsString(wDict.get(
|
|
16220
|
+
if (decodePdfObjAsString(wDict.get(import_pdf_lib4.PDFName.of("Subtype"))) !== "Widget") continue;
|
|
16221
|
+
const tName = decodePdfObjAsString(wDict.get(import_pdf_lib4.PDFName.of("T")));
|
|
15062
16222
|
if (!tName || Object.prototype.hasOwnProperty.call(values, tName)) continue;
|
|
15063
|
-
const ft = decodePdfObjAsString(wDict.get(
|
|
16223
|
+
const ft = decodePdfObjAsString(wDict.get(import_pdf_lib4.PDFName.of("FT")));
|
|
15064
16224
|
if (ft === "Sig") {
|
|
15065
16225
|
values[tName] = extractSigDictValue(doc, wDict);
|
|
15066
16226
|
} else if (ft === "Ch") {
|
|
15067
|
-
const vObj = wDict.get(
|
|
15068
|
-
const vArr = doc.context.lookupMaybe(vObj,
|
|
16227
|
+
const vObj = wDict.get(import_pdf_lib4.PDFName.of("V"));
|
|
16228
|
+
const vArr = doc.context.lookupMaybe(vObj, import_pdf_lib4.PDFArray);
|
|
15069
16229
|
if (vArr) {
|
|
15070
16230
|
const items = [];
|
|
15071
16231
|
for (let k = 0; k < vArr.size(); k++) {
|
|
@@ -15151,14 +16311,18 @@ async function exportBatchPdfBytes(snapshot, records, options) {
|
|
|
15151
16311
|
if (records.length === 1) {
|
|
15152
16312
|
return exportPdfBytes(snapshot, records[0], options);
|
|
15153
16313
|
}
|
|
15154
|
-
const mergedPdf = await
|
|
16314
|
+
const mergedPdf = await import_pdf_lib4.PDFDocument.create();
|
|
15155
16315
|
let runningStartPage = Math.max(1, Number(snapshot.metadata?.startPageNumber ?? 1) || 1);
|
|
15156
16316
|
let runningBatesNumber = Math.max(0, Math.floor(snapshot.metadata?.batesConfig?.startNumber ?? 1));
|
|
16317
|
+
const effectiveSecurity = options?.security ?? snapshot.security ?? snapshot.metadata?.security;
|
|
16318
|
+
const recordOptions = isPdfSecurityActive(effectiveSecurity) ? { ...options ?? {}, security: { enabled: false } } : options;
|
|
15157
16319
|
for (let i = 0; i < records.length; i++) {
|
|
15158
16320
|
const recordSnap = {
|
|
15159
16321
|
...snapshot,
|
|
16322
|
+
...isPdfSecurityActive(effectiveSecurity) ? { security: { enabled: false } } : {},
|
|
15160
16323
|
metadata: {
|
|
15161
16324
|
...snapshot.metadata ?? {},
|
|
16325
|
+
...isPdfSecurityActive(effectiveSecurity) ? { security: { enabled: false } } : {},
|
|
15162
16326
|
startPageNumber: runningStartPage,
|
|
15163
16327
|
...snapshot.metadata?.batesConfig ? {
|
|
15164
16328
|
batesConfig: {
|
|
@@ -15168,8 +16332,8 @@ async function exportBatchPdfBytes(snapshot, records, options) {
|
|
|
15168
16332
|
} : {}
|
|
15169
16333
|
}
|
|
15170
16334
|
};
|
|
15171
|
-
const subBytes = await exportPdfBytes(recordSnap, records[i],
|
|
15172
|
-
const subDoc = await
|
|
16335
|
+
const subBytes = await exportPdfBytes(recordSnap, records[i], recordOptions);
|
|
16336
|
+
const subDoc = await import_pdf_lib4.PDFDocument.load(subBytes);
|
|
15173
16337
|
const copiedPages = await mergedPdf.copyPages(subDoc, subDoc.getPageIndices());
|
|
15174
16338
|
for (const page of copiedPages) {
|
|
15175
16339
|
mergedPdf.addPage(page);
|
|
@@ -15178,23 +16342,27 @@ async function exportBatchPdfBytes(snapshot, records, options) {
|
|
|
15178
16342
|
runningStartPage += subPageCount;
|
|
15179
16343
|
runningBatesNumber += subPageCount;
|
|
15180
16344
|
}
|
|
16345
|
+
if (isPdfSecurityActive(effectiveSecurity)) {
|
|
16346
|
+
await applyPdfSecurityToDocument(mergedPdf, effectiveSecurity);
|
|
16347
|
+
return await mergedPdf.save({ useObjectStreams: false });
|
|
16348
|
+
}
|
|
15181
16349
|
return await mergedPdf.save();
|
|
15182
16350
|
}
|
|
15183
16351
|
async function exportCalibrationGridPdfBytes(pageSize) {
|
|
15184
16352
|
const sz = pageSize ?? PDF_PAGE_PRESETS.A4;
|
|
15185
|
-
const pdfDoc = await
|
|
16353
|
+
const pdfDoc = await import_pdf_lib4.PDFDocument.create();
|
|
15186
16354
|
const page = pdfDoc.addPage([sz.width, sz.height]);
|
|
15187
|
-
const fontRegular = await pdfDoc.embedFont(
|
|
15188
|
-
const fontBold = await pdfDoc.embedFont(
|
|
16355
|
+
const fontRegular = await pdfDoc.embedFont(import_pdf_lib4.StandardFonts.Helvetica);
|
|
16356
|
+
const fontBold = await pdfDoc.embedFont(import_pdf_lib4.StandardFonts.HelveticaBold);
|
|
15189
16357
|
const widthPt = sz.width;
|
|
15190
16358
|
const heightPt = sz.height;
|
|
15191
16359
|
const maxXMm = Math.floor(ptToMm(widthPt));
|
|
15192
16360
|
const maxYMm = Math.floor(ptToMm(heightPt));
|
|
15193
|
-
const fineColor = (0,
|
|
15194
|
-
const midColor = (0,
|
|
15195
|
-
const majorColor = (0,
|
|
15196
|
-
const crossColor = (0,
|
|
15197
|
-
const labelColor = (0,
|
|
16361
|
+
const fineColor = (0, import_pdf_lib4.rgb)(0.75, 0.8, 0.86);
|
|
16362
|
+
const midColor = (0, import_pdf_lib4.rgb)(0.55, 0.65, 0.78);
|
|
16363
|
+
const majorColor = (0, import_pdf_lib4.rgb)(0.15, 0.39, 0.92);
|
|
16364
|
+
const crossColor = (0, import_pdf_lib4.rgb)(0.86, 0.15, 0.15);
|
|
16365
|
+
const labelColor = (0, import_pdf_lib4.rgb)(0.1, 0.16, 0.28);
|
|
15198
16366
|
for (let mm = 0; mm <= maxXMm; mm += 1) {
|
|
15199
16367
|
const x = mmToPt(mm);
|
|
15200
16368
|
const isMajor10 = mm % 10 === 0;
|
|
@@ -15313,7 +16481,7 @@ async function exportCalibrationGridPdfBytes(pageSize) {
|
|
|
15313
16481
|
y: cardY,
|
|
15314
16482
|
width: cardW,
|
|
15315
16483
|
height: cardH,
|
|
15316
|
-
color: (0,
|
|
16484
|
+
color: (0, import_pdf_lib4.rgb)(1, 1, 1),
|
|
15317
16485
|
borderColor: majorColor,
|
|
15318
16486
|
borderWidth: 0.9,
|
|
15319
16487
|
opacity: 0.94
|
|
@@ -15349,7 +16517,7 @@ async function exportCalibrationGridPdfBytes(pageSize) {
|
|
|
15349
16517
|
return await pdfDoc.save();
|
|
15350
16518
|
}
|
|
15351
16519
|
async function overlayDiagnosticGridOnPdfBytes(pdfBytes, snapshot, options) {
|
|
15352
|
-
const pdfDoc = await
|
|
16520
|
+
const pdfDoc = await import_pdf_lib4.PDFDocument.load(pdfBytes, { ignoreEncryption: true });
|
|
15353
16521
|
const pages = pdfDoc.getPages();
|
|
15354
16522
|
if (pages.length === 0) {
|
|
15355
16523
|
return await pdfDoc.save({ updateFieldAppearances: false });
|
|
@@ -15361,14 +16529,14 @@ async function overlayDiagnosticGridOnPdfBytes(pdfBytes, snapshot, options) {
|
|
|
15361
16529
|
const showElementBounds = options?.showElementBounds !== false;
|
|
15362
16530
|
const showElementLabels = options?.showElementLabels !== false;
|
|
15363
16531
|
const gridOpacity = Math.max(0.05, Math.min(1, options?.gridOpacity ?? 0.35));
|
|
15364
|
-
const fontRegular = await pdfDoc.embedFont(
|
|
15365
|
-
const fontBold = await pdfDoc.embedFont(
|
|
16532
|
+
const fontRegular = await pdfDoc.embedFont(import_pdf_lib4.StandardFonts.Helvetica);
|
|
16533
|
+
const fontBold = await pdfDoc.embedFont(import_pdf_lib4.StandardFonts.HelveticaBold);
|
|
15366
16534
|
let lazyCjkState = null;
|
|
15367
|
-
const minorCol = (0,
|
|
15368
|
-
const majorCol = (0,
|
|
15369
|
-
const rulerTextCol = (0,
|
|
15370
|
-
const boxCol = (0,
|
|
15371
|
-
const badgeBgCol = (0,
|
|
16535
|
+
const minorCol = (0, import_pdf_lib4.rgb)(0.49, 0.525, 0.596);
|
|
16536
|
+
const majorCol = (0, import_pdf_lib4.rgb)(0.173, 0.325, 0.945);
|
|
16537
|
+
const rulerTextCol = (0, import_pdf_lib4.rgb)(0.192, 0.212, 0.247);
|
|
16538
|
+
const boxCol = (0, import_pdf_lib4.rgb)(0.173, 0.325, 0.945);
|
|
16539
|
+
const badgeBgCol = (0, import_pdf_lib4.rgb)(0.953, 0.961, 1);
|
|
15372
16540
|
const staticEls = unitSnapshot?.document?.metadata?.staticSchemaElements ?? unitSnapshot?.metadata?.staticSchemaElements ?? [];
|
|
15373
16541
|
for (let pIdx = 0; pIdx < pages.length; pIdx++) {
|
|
15374
16542
|
const page = pages[pIdx];
|
|
@@ -18086,7 +19254,7 @@ function diagnosePdfFonts(unitOrTemplate, options) {
|
|
|
18086
19254
|
|
|
18087
19255
|
// src/exporter/pdf-advanced-tools.ts
|
|
18088
19256
|
var import_core8 = require("@univerjs/core");
|
|
18089
|
-
var
|
|
19257
|
+
var import_pdf_lib5 = require("pdf-lib");
|
|
18090
19258
|
var PDF_DIFF_COLORS = {
|
|
18091
19259
|
added: "#16A34A",
|
|
18092
19260
|
removed: "#DC2626",
|
|
@@ -18420,10 +19588,10 @@ async function comparePdfBytes(beforePdfBytes, afterPdfBytes) {
|
|
|
18420
19588
|
}
|
|
18421
19589
|
function decodePdfNameOrText(obj) {
|
|
18422
19590
|
if (!obj) return "";
|
|
18423
|
-
if (obj instanceof
|
|
19591
|
+
if (obj instanceof import_pdf_lib5.PDFHexString || obj instanceof import_pdf_lib5.PDFString) {
|
|
18424
19592
|
return obj.decodeText();
|
|
18425
19593
|
}
|
|
18426
|
-
if (obj instanceof
|
|
19594
|
+
if (obj instanceof import_pdf_lib5.PDFName) {
|
|
18427
19595
|
return obj.decodeText();
|
|
18428
19596
|
}
|
|
18429
19597
|
return String(obj);
|
|
@@ -18432,9 +19600,9 @@ function lookupInheritedDictEntry(doc, dict, key) {
|
|
|
18432
19600
|
let cur = dict;
|
|
18433
19601
|
let guard = 0;
|
|
18434
19602
|
while (cur && guard < 12) {
|
|
18435
|
-
const val = cur.get(
|
|
19603
|
+
const val = cur.get(import_pdf_lib5.PDFName.of(key));
|
|
18436
19604
|
if (val !== void 0) return val;
|
|
18437
|
-
cur = doc.context.lookupMaybe(cur.get(
|
|
19605
|
+
cur = doc.context.lookupMaybe(cur.get(import_pdf_lib5.PDFName.of("Parent")), import_pdf_lib5.PDFDict);
|
|
18438
19606
|
guard++;
|
|
18439
19607
|
}
|
|
18440
19608
|
return void 0;
|
|
@@ -18444,10 +19612,10 @@ function resolveFullFieldName(doc, dict) {
|
|
|
18444
19612
|
let cur = dict;
|
|
18445
19613
|
let guard = 0;
|
|
18446
19614
|
while (cur && guard < 12) {
|
|
18447
|
-
const tObj = cur.get(
|
|
19615
|
+
const tObj = cur.get(import_pdf_lib5.PDFName.of("T"));
|
|
18448
19616
|
const part = decodePdfNameOrText(tObj).trim();
|
|
18449
19617
|
if (part) parts.unshift(part);
|
|
18450
|
-
cur = doc.context.lookupMaybe(cur.get(
|
|
19618
|
+
cur = doc.context.lookupMaybe(cur.get(import_pdf_lib5.PDFName.of("Parent")), import_pdf_lib5.PDFDict);
|
|
18451
19619
|
guard++;
|
|
18452
19620
|
}
|
|
18453
19621
|
return parts.join(".");
|
|
@@ -18457,7 +19625,7 @@ function parseRectBottomUpToTopDownMm(rectArr, mediaBox) {
|
|
|
18457
19625
|
const nums = [];
|
|
18458
19626
|
for (let i = 0; i < 4; i++) {
|
|
18459
19627
|
const item = rectArr.get(i);
|
|
18460
|
-
nums.push(item instanceof
|
|
19628
|
+
nums.push(item instanceof import_pdf_lib5.PDFNumber ? item.asNumber() : Number(String(item)) || 0);
|
|
18461
19629
|
}
|
|
18462
19630
|
const x1 = Math.min(nums[0], nums[2]) - mediaBox.x;
|
|
18463
19631
|
const y1 = Math.min(nums[1], nums[3]) - mediaBox.y;
|
|
@@ -18481,7 +19649,7 @@ function parseRectBottomUpToTopDownMm(rectArr, mediaBox) {
|
|
|
18481
19649
|
};
|
|
18482
19650
|
}
|
|
18483
19651
|
async function importAcroFormPdfToUnit(pdfBytes, options) {
|
|
18484
|
-
const doc = await
|
|
19652
|
+
const doc = await import_pdf_lib5.PDFDocument.load(pdfBytes, { ignoreEncryption: true });
|
|
18485
19653
|
const rawPages = doc.getPages();
|
|
18486
19654
|
const pageCount = Math.max(1, rawPages.length);
|
|
18487
19655
|
const dataUri = `data:application/pdf;base64,${bytesToBase64(pdfBytes)}`;
|
|
@@ -18506,7 +19674,7 @@ async function importAcroFormPdfToUnit(pdfBytes, options) {
|
|
|
18506
19674
|
if (annots) {
|
|
18507
19675
|
for (let ai = 0; ai < annots.size(); ai++) {
|
|
18508
19676
|
const item = annots.get(ai);
|
|
18509
|
-
if (item instanceof
|
|
19677
|
+
if (item instanceof import_pdf_lib5.PDFRef) {
|
|
18510
19678
|
annotRefToPageIndex.set(refKey(item), i);
|
|
18511
19679
|
}
|
|
18512
19680
|
}
|
|
@@ -18532,8 +19700,8 @@ async function importAcroFormPdfToUnit(pdfBytes, options) {
|
|
|
18532
19700
|
const handledWidgetRefs = /* @__PURE__ */ new Set();
|
|
18533
19701
|
const handledFieldNames = /* @__PURE__ */ new Set();
|
|
18534
19702
|
const resolveWidgetPageIndex = (widgetDict, widgetRef) => {
|
|
18535
|
-
const pRef = widgetDict.get(
|
|
18536
|
-
if (pRef instanceof
|
|
19703
|
+
const pRef = widgetDict.get(import_pdf_lib5.PDFName.of("P"));
|
|
19704
|
+
if (pRef instanceof import_pdf_lib5.PDFRef && pageRefToIndex.has(refKey(pRef))) {
|
|
18537
19705
|
return pageRefToIndex.get(refKey(pRef));
|
|
18538
19706
|
}
|
|
18539
19707
|
if (widgetRef && annotRefToPageIndex.has(refKey(widgetRef))) {
|
|
@@ -18549,21 +19717,21 @@ async function importAcroFormPdfToUnit(pdfBytes, options) {
|
|
|
18549
19717
|
const readWidgetRotationDeg = (fieldOrWidgetDict, altWidgetDict) => {
|
|
18550
19718
|
for (const d of [fieldOrWidgetDict, altWidgetDict]) {
|
|
18551
19719
|
if (!d) continue;
|
|
18552
|
-
const meta = doc.context.lookupMaybe(d.get(
|
|
18553
|
-
const metaAngle = meta?.get(
|
|
18554
|
-
if (metaAngle instanceof
|
|
18555
|
-
const mkDict = doc.context.lookupMaybe(d.get(
|
|
18556
|
-
const mkR = mkDict?.get(
|
|
18557
|
-
if (mkR instanceof
|
|
19720
|
+
const meta = doc.context.lookupMaybe(d.get(import_pdf_lib5.PDFName.of("YudaoMeta")), import_pdf_lib5.PDFDict);
|
|
19721
|
+
const metaAngle = meta?.get(import_pdf_lib5.PDFName.of("Angle"));
|
|
19722
|
+
if (metaAngle instanceof import_pdf_lib5.PDFNumber) return metaAngle.asNumber();
|
|
19723
|
+
const mkDict = doc.context.lookupMaybe(d.get(import_pdf_lib5.PDFName.of("MK")), import_pdf_lib5.PDFDict);
|
|
19724
|
+
const mkR = mkDict?.get(import_pdf_lib5.PDFName.of("R"));
|
|
19725
|
+
if (mkR instanceof import_pdf_lib5.PDFNumber) return mkR.asNumber();
|
|
18558
19726
|
}
|
|
18559
19727
|
return 0;
|
|
18560
19728
|
};
|
|
18561
19729
|
const readYudaoMetaDict = (fieldOrWidgetDict, altWidgetDict) => {
|
|
18562
|
-
return doc.context.lookupMaybe(fieldOrWidgetDict.get(
|
|
19730
|
+
return doc.context.lookupMaybe(fieldOrWidgetDict.get(import_pdf_lib5.PDFName.of("YudaoMeta")), import_pdf_lib5.PDFDict) ?? (altWidgetDict ? doc.context.lookupMaybe(altWidgetDict.get(import_pdf_lib5.PDFName.of("YudaoMeta")), import_pdf_lib5.PDFDict) : void 0);
|
|
18563
19731
|
};
|
|
18564
19732
|
const readMetaNumber = (meta, key) => {
|
|
18565
|
-
const v = meta?.get(
|
|
18566
|
-
return v instanceof
|
|
19733
|
+
const v = meta?.get(import_pdf_lib5.PDFName.of(key));
|
|
19734
|
+
return v instanceof import_pdf_lib5.PDFNumber ? v.asNumber() : void 0;
|
|
18567
19735
|
};
|
|
18568
19736
|
try {
|
|
18569
19737
|
const form = doc.getForm();
|
|
@@ -18571,10 +19739,10 @@ async function importAcroFormPdfToUnit(pdfBytes, options) {
|
|
|
18571
19739
|
const name = field.getName() || `field_${(0, import_core8.generateRandomId)(4)}`;
|
|
18572
19740
|
const widgets = field.acroField.getWidgets();
|
|
18573
19741
|
const ffObj = lookupInheritedDictEntry(doc, field.acroField.dict, "Ff");
|
|
18574
|
-
const ff = ffObj instanceof
|
|
19742
|
+
const ff = ffObj instanceof import_pdf_lib5.PDFNumber ? ffObj.asNumber() : 0;
|
|
18575
19743
|
const isReadOnly = Boolean(ff & 1) || field.isReadOnly();
|
|
18576
19744
|
const isRequired = Boolean(ff & 2) || field.isRequired();
|
|
18577
|
-
if (field instanceof
|
|
19745
|
+
if (field instanceof import_pdf_lib5.PDFRadioGroup && widgets.length > 0) {
|
|
18578
19746
|
handledFieldNames.add(name);
|
|
18579
19747
|
const firstWidget = widgets[0];
|
|
18580
19748
|
const pIdx2 = resolveWidgetPageIndex(firstWidget.dict);
|
|
@@ -18590,16 +19758,16 @@ async function importAcroFormPdfToUnit(pdfBytes, options) {
|
|
|
18590
19758
|
maxX2 = Math.max(maxX2, r.x + r.width);
|
|
18591
19759
|
maxY2 = Math.max(maxY2, r.y + r.height);
|
|
18592
19760
|
}
|
|
18593
|
-
const kidsArr = doc.context.lookupMaybe(field.acroField.dict.get(
|
|
19761
|
+
const kidsArr = doc.context.lookupMaybe(field.acroField.dict.get(import_pdf_lib5.PDFName.of("Kids")), import_pdf_lib5.PDFArray);
|
|
18594
19762
|
if (kidsArr) {
|
|
18595
19763
|
for (let k = 0; k < kidsArr.size(); k++) {
|
|
18596
19764
|
const kr = kidsArr.get(k);
|
|
18597
|
-
if (kr instanceof
|
|
19765
|
+
if (kr instanceof import_pdf_lib5.PDFRef) handledWidgetRefs.add(refKey(kr));
|
|
18598
19766
|
}
|
|
18599
19767
|
}
|
|
18600
19768
|
const rgMeta = readYudaoMetaDict(field.acroField.dict, firstWidget.dict);
|
|
18601
19769
|
const rgAngle = readWidgetRotationDeg(field.acroField.dict, firstWidget.dict);
|
|
18602
|
-
const metaDir = rgMeta ? decodePdfNameOrText(rgMeta.get(
|
|
19770
|
+
const metaDir = rgMeta ? decodePdfNameOrText(rgMeta.get(import_pdf_lib5.PDFName.of("Direction"))) : "";
|
|
18603
19771
|
const spanX = Math.max(24, maxX2 - minX1);
|
|
18604
19772
|
const spanY = Math.max(16, maxY2 - minY1);
|
|
18605
19773
|
const direction = metaDir === "vertical" || metaDir === "horizontal" ? metaDir : widgets.length > 1 && spanY > spanX ? "vertical" : "horizontal";
|
|
@@ -18656,19 +19824,19 @@ async function importAcroFormPdfToUnit(pdfBytes, options) {
|
|
|
18656
19824
|
height: mmToPt(heightMm),
|
|
18657
19825
|
angle: rotAngle
|
|
18658
19826
|
};
|
|
18659
|
-
const metaElemType = yMeta ? decodePdfNameOrText(yMeta.get(
|
|
19827
|
+
const metaElemType = yMeta ? decodePdfNameOrText(yMeta.get(import_pdf_lib5.PDFName.of("ElementType"))) : "";
|
|
18660
19828
|
const tuTooltip = decodePdfNameOrText(lookupInheritedDictEntry(doc, field.acroField.dict, "TU"));
|
|
18661
|
-
if (field instanceof
|
|
19829
|
+
if (field instanceof import_pdf_lib5.PDFTextField) {
|
|
18662
19830
|
handledFieldNames.add(name);
|
|
18663
19831
|
if (metaElemType === "dateTime" || tuTooltip.startsWith("dateTime:")) {
|
|
18664
19832
|
let dateKind = "date";
|
|
18665
19833
|
let dtFormat = "YYYY-MM-DD";
|
|
18666
19834
|
let dtLocale;
|
|
18667
19835
|
if (metaElemType === "dateTime" && yMeta) {
|
|
18668
|
-
const dk = decodePdfNameOrText(yMeta.get(
|
|
19836
|
+
const dk = decodePdfNameOrText(yMeta.get(import_pdf_lib5.PDFName.of("DateKind")));
|
|
18669
19837
|
if (dk === "date" || dk === "time" || dk === "dateTime") dateKind = dk;
|
|
18670
|
-
dtFormat = decodePdfNameOrText(yMeta.get(
|
|
18671
|
-
const loc = decodePdfNameOrText(yMeta.get(
|
|
19838
|
+
dtFormat = decodePdfNameOrText(yMeta.get(import_pdf_lib5.PDFName.of("Format"))) || "YYYY-MM-DD";
|
|
19839
|
+
const loc = decodePdfNameOrText(yMeta.get(import_pdf_lib5.PDFName.of("Locale")));
|
|
18672
19840
|
if (loc) dtLocale = loc;
|
|
18673
19841
|
} else if (tuTooltip.startsWith("dateTime:")) {
|
|
18674
19842
|
const parts = tuTooltip.slice("dateTime:".length).split("|");
|
|
@@ -18678,9 +19846,9 @@ async function importAcroFormPdfToUnit(pdfBytes, options) {
|
|
|
18678
19846
|
if (parts[1]) dtFormat = parts[1];
|
|
18679
19847
|
if (parts[2]) dtLocale = parts[2];
|
|
18680
19848
|
}
|
|
18681
|
-
const rawMetaVal = yMeta ? decodePdfNameOrText(yMeta.get(
|
|
19849
|
+
const rawMetaVal = yMeta ? decodePdfNameOrText(yMeta.get(import_pdf_lib5.PDFName.of("RawValue"))) : "";
|
|
18682
19850
|
const dtVal = rawMetaVal || field.getText() || "";
|
|
18683
|
-
const metaAlign = yMeta ? decodePdfNameOrText(yMeta.get(
|
|
19851
|
+
const metaAlign = yMeta ? decodePdfNameOrText(yMeta.get(import_pdf_lib5.PDFName.of("Align"))) : "";
|
|
18684
19852
|
const metaFs = readMetaNumber(yMeta, "FontSize");
|
|
18685
19853
|
const metaTc = readMetaNumber(yMeta, "CharacterSpacing");
|
|
18686
19854
|
pushElement(pIdx, {
|
|
@@ -18723,9 +19891,9 @@ async function importAcroFormPdfToUnit(pdfBytes, options) {
|
|
|
18723
19891
|
transform: baseTransform
|
|
18724
19892
|
});
|
|
18725
19893
|
}
|
|
18726
|
-
} else if (field instanceof
|
|
19894
|
+
} else if (field instanceof import_pdf_lib5.PDFCheckBox) {
|
|
18727
19895
|
handledFieldNames.add(name);
|
|
18728
|
-
const restoredLabel = yMeta ? decodePdfNameOrText(yMeta.get(
|
|
19896
|
+
const restoredLabel = yMeta ? decodePdfNameOrText(yMeta.get(import_pdf_lib5.PDFName.of("Label"))) : tuTooltip || name;
|
|
18729
19897
|
const boxWidthPt = readMetaNumber(yMeta, "BoxWidth") ?? Math.max(8, rect.width);
|
|
18730
19898
|
pushElement(pIdx, {
|
|
18731
19899
|
id: `el-${(0, import_core8.generateRandomId)(6)}`,
|
|
@@ -18751,11 +19919,11 @@ async function importAcroFormPdfToUnit(pdfBytes, options) {
|
|
|
18751
19919
|
width: yMeta ? baseTransform.width : Math.max(baseTransform.width, mmToPt(12))
|
|
18752
19920
|
}
|
|
18753
19921
|
});
|
|
18754
|
-
} else if (field instanceof
|
|
19922
|
+
} else if (field instanceof import_pdf_lib5.PDFDropdown || field instanceof import_pdf_lib5.PDFOptionList) {
|
|
18755
19923
|
handledFieldNames.add(name);
|
|
18756
19924
|
const opts = field.getOptions();
|
|
18757
19925
|
const sel = field.getSelected();
|
|
18758
|
-
const placeholder = yMeta ? decodePdfNameOrText(yMeta.get(
|
|
19926
|
+
const placeholder = yMeta ? decodePdfNameOrText(yMeta.get(import_pdf_lib5.PDFName.of("Placeholder"))) : "";
|
|
18759
19927
|
pushElement(pIdx, {
|
|
18760
19928
|
id: `el-${(0, import_core8.generateRandomId)(6)}`,
|
|
18761
19929
|
type: "select" /* SELECT */,
|
|
@@ -18780,21 +19948,21 @@ async function importAcroFormPdfToUnit(pdfBytes, options) {
|
|
|
18780
19948
|
const mb = pageMediaBoxes[pIdx];
|
|
18781
19949
|
for (let ai = 0; ai < annots.size(); ai++) {
|
|
18782
19950
|
const entry = annots.get(ai);
|
|
18783
|
-
if (entry instanceof
|
|
18784
|
-
const wDict = doc.context.lookupMaybe(entry,
|
|
19951
|
+
if (entry instanceof import_pdf_lib5.PDFRef && handledWidgetRefs.has(refKey(entry))) continue;
|
|
19952
|
+
const wDict = doc.context.lookupMaybe(entry, import_pdf_lib5.PDFDict);
|
|
18785
19953
|
if (!wDict) continue;
|
|
18786
|
-
const subtype = decodePdfNameOrText(wDict.get(
|
|
19954
|
+
const subtype = decodePdfNameOrText(wDict.get(import_pdf_lib5.PDFName.of("Subtype")));
|
|
18787
19955
|
if (subtype !== "Widget") continue;
|
|
18788
19956
|
const fieldName = resolveFullFieldName(doc, wDict) || `widget_${pIdx + 1}_${ai + 1}`;
|
|
18789
19957
|
if (handledFieldNames.has(fieldName)) continue;
|
|
18790
19958
|
const ft = decodePdfNameOrText(lookupInheritedDictEntry(doc, wDict, "FT"));
|
|
18791
|
-
const rectArr = doc.context.lookupMaybe(wDict.get(
|
|
19959
|
+
const rectArr = doc.context.lookupMaybe(wDict.get(import_pdf_lib5.PDFName.of("Rect")), import_pdf_lib5.PDFArray);
|
|
18792
19960
|
const geom = parseRectBottomUpToTopDownMm(rectArr, mb);
|
|
18793
19961
|
if (!geom) continue;
|
|
18794
19962
|
const yMeta = readYudaoMetaDict(wDict);
|
|
18795
19963
|
const rotAngle = readWidgetRotationDeg(wDict);
|
|
18796
19964
|
const ffObj = lookupInheritedDictEntry(doc, wDict, "Ff");
|
|
18797
|
-
const ff = ffObj instanceof
|
|
19965
|
+
const ff = ffObj instanceof import_pdf_lib5.PDFNumber ? ffObj.asNumber() : 0;
|
|
18798
19966
|
const isReadOnly = Boolean(ff & 1);
|
|
18799
19967
|
const isRequired = Boolean(ff & 2);
|
|
18800
19968
|
const rawVal = lookupInheritedDictEntry(doc, wDict, "V");
|
|
@@ -18818,16 +19986,16 @@ async function importAcroFormPdfToUnit(pdfBytes, options) {
|
|
|
18818
19986
|
};
|
|
18819
19987
|
if (ft === "Sig") {
|
|
18820
19988
|
handledFieldNames.add(fieldName);
|
|
18821
|
-
let signerName = yMeta ? decodePdfNameOrText(yMeta.get(
|
|
18822
|
-
let signedAt = yMeta ? decodePdfNameOrText(yMeta.get(
|
|
18823
|
-
let reason = yMeta ? decodePdfNameOrText(yMeta.get(
|
|
18824
|
-
const sigDataUri = yMeta ? decodePdfNameOrText(yMeta.get(
|
|
18825
|
-
const sigLabel = yMeta ? decodePdfNameOrText(yMeta.get(
|
|
18826
|
-
const sigDict = doc.context.lookupMaybe(rawVal,
|
|
19989
|
+
let signerName = yMeta ? decodePdfNameOrText(yMeta.get(import_pdf_lib5.PDFName.of("SignerName"))) : "";
|
|
19990
|
+
let signedAt = yMeta ? decodePdfNameOrText(yMeta.get(import_pdf_lib5.PDFName.of("SignedAt"))) : "";
|
|
19991
|
+
let reason = yMeta ? decodePdfNameOrText(yMeta.get(import_pdf_lib5.PDFName.of("Reason"))) : "";
|
|
19992
|
+
const sigDataUri = yMeta ? decodePdfNameOrText(yMeta.get(import_pdf_lib5.PDFName.of("SignatureDataUri"))) : "";
|
|
19993
|
+
const sigLabel = yMeta ? decodePdfNameOrText(yMeta.get(import_pdf_lib5.PDFName.of("Label"))) || fieldName : decodePdfNameOrText(wDict.get(import_pdf_lib5.PDFName.of("TU"))) || fieldName;
|
|
19994
|
+
const sigDict = doc.context.lookupMaybe(rawVal, import_pdf_lib5.PDFDict);
|
|
18827
19995
|
if (sigDict) {
|
|
18828
|
-
if (!signerName) signerName = decodePdfNameOrText(sigDict.get(
|
|
18829
|
-
if (!signedAt) signedAt = decodePdfNameOrText(sigDict.get(
|
|
18830
|
-
if (!reason) reason = decodePdfNameOrText(sigDict.get(
|
|
19996
|
+
if (!signerName) signerName = decodePdfNameOrText(sigDict.get(import_pdf_lib5.PDFName.of("Name")));
|
|
19997
|
+
if (!signedAt) signedAt = decodePdfNameOrText(sigDict.get(import_pdf_lib5.PDFName.of("M")));
|
|
19998
|
+
if (!reason) reason = decodePdfNameOrText(sigDict.get(import_pdf_lib5.PDFName.of("Reason")));
|
|
18831
19999
|
}
|
|
18832
20000
|
pushElement(pIdx, {
|
|
18833
20001
|
id: `el-${(0, import_core8.generateRandomId)(6)}`,
|
|
@@ -18880,12 +20048,12 @@ async function importAcroFormPdfToUnit(pdfBytes, options) {
|
|
|
18880
20048
|
}
|
|
18881
20049
|
} else if (ft === "Ch") {
|
|
18882
20050
|
handledFieldNames.add(fieldName);
|
|
18883
|
-
const optArr = doc.context.lookupMaybe(lookupInheritedDictEntry(doc, wDict, "Opt"),
|
|
20051
|
+
const optArr = doc.context.lookupMaybe(lookupInheritedDictEntry(doc, wDict, "Opt"), import_pdf_lib5.PDFArray);
|
|
18884
20052
|
const opts = [];
|
|
18885
20053
|
if (optArr) {
|
|
18886
20054
|
for (let oi = 0; oi < optArr.size(); oi++) {
|
|
18887
20055
|
const item = optArr.get(oi);
|
|
18888
|
-
const subArr = doc.context.lookupMaybe(item,
|
|
20056
|
+
const subArr = doc.context.lookupMaybe(item, import_pdf_lib5.PDFArray);
|
|
18889
20057
|
if (subArr && subArr.size() > 0) {
|
|
18890
20058
|
opts.push(decodePdfNameOrText(subArr.get(subArr.size() - 1)));
|
|
18891
20059
|
} else {
|
|
@@ -19607,7 +20775,7 @@ function importFormDataFromFdf(unit, fdfContent) {
|
|
|
19607
20775
|
}
|
|
19608
20776
|
|
|
19609
20777
|
// src/exporter/pdf-audit-seal.ts
|
|
19610
|
-
var
|
|
20778
|
+
var import_pdf_lib6 = require("pdf-lib");
|
|
19611
20779
|
var SHA256_K = new Uint32Array([
|
|
19612
20780
|
1116352408,
|
|
19613
20781
|
1899447441,
|
|
@@ -19681,7 +20849,7 @@ function toUtf8Bytes(input) {
|
|
|
19681
20849
|
if (input instanceof Uint8Array) return input;
|
|
19682
20850
|
return new TextEncoder().encode(input);
|
|
19683
20851
|
}
|
|
19684
|
-
function
|
|
20852
|
+
function bytesToHex2(bytes) {
|
|
19685
20853
|
let hex = "";
|
|
19686
20854
|
for (let i = 0; i < bytes.length; i++) {
|
|
19687
20855
|
hex += bytes[i].toString(16).padStart(2, "0");
|
|
@@ -19764,7 +20932,7 @@ function sha256BytesSync(input) {
|
|
|
19764
20932
|
return out;
|
|
19765
20933
|
}
|
|
19766
20934
|
function sha256HexSync(input) {
|
|
19767
|
-
return
|
|
20935
|
+
return bytesToHex2(sha256BytesSync(input));
|
|
19768
20936
|
}
|
|
19769
20937
|
async function sha256Hex(input) {
|
|
19770
20938
|
const bytes = toUtf8Bytes(input);
|
|
@@ -19774,7 +20942,7 @@ async function sha256Hex(input) {
|
|
|
19774
20942
|
const copy = new Uint8Array(bytes.byteLength);
|
|
19775
20943
|
copy.set(bytes);
|
|
19776
20944
|
const digestBuf = await subtle.digest("SHA-256", copy.buffer);
|
|
19777
|
-
return
|
|
20945
|
+
return bytesToHex2(new Uint8Array(digestBuf));
|
|
19778
20946
|
} catch {
|
|
19779
20947
|
return sha256HexSync(bytes);
|
|
19780
20948
|
}
|
|
@@ -19788,7 +20956,7 @@ function canonicalJsonStringify(value) {
|
|
|
19788
20956
|
}
|
|
19789
20957
|
if (typeof value === "string") return JSON.stringify(value);
|
|
19790
20958
|
if (value instanceof Uint8Array) {
|
|
19791
|
-
return JSON.stringify(`uint8:${
|
|
20959
|
+
return JSON.stringify(`uint8:${bytesToHex2(value)}`);
|
|
19792
20960
|
}
|
|
19793
20961
|
if (Array.isArray(value)) {
|
|
19794
20962
|
return `[${value.map((item) => canonicalJsonStringify(item)).join(",")}]`;
|
|
@@ -19814,12 +20982,12 @@ function computePdfPageStreamsDigestHex(pdfDoc) {
|
|
|
19814
20982
|
const p = pages[i];
|
|
19815
20983
|
const { width, height } = p.getSize();
|
|
19816
20984
|
pushChunk(toUtf8Bytes(`P${i}:${Math.round(width * 100)}x${Math.round(height * 100)}|`));
|
|
19817
|
-
const contentsObj = p.node.get(
|
|
20985
|
+
const contentsObj = p.node.get(import_pdf_lib6.PDFName.of("Contents"));
|
|
19818
20986
|
const appendStreamRef = (obj) => {
|
|
19819
|
-
const resolved = obj instanceof
|
|
19820
|
-
if (resolved instanceof
|
|
20987
|
+
const resolved = obj instanceof import_pdf_lib6.PDFRef ? pdfDoc.context.lookup(obj) : obj;
|
|
20988
|
+
if (resolved instanceof import_pdf_lib6.PDFRawStream) {
|
|
19821
20989
|
pushChunk(resolved.contents);
|
|
19822
|
-
} else if (resolved instanceof
|
|
20990
|
+
} else if (resolved instanceof import_pdf_lib6.PDFArray) {
|
|
19823
20991
|
for (let idx = 0; idx < resolved.size(); idx++) {
|
|
19824
20992
|
appendStreamRef(resolved.get(idx));
|
|
19825
20993
|
}
|
|
@@ -19874,10 +21042,10 @@ async function exportSignedPdfWithAuditSeal(unitData, data, sealOptions) {
|
|
|
19874
21042
|
});
|
|
19875
21043
|
const payloadDigestHex = await sha256Hex(canonicalPayload);
|
|
19876
21044
|
const basePdfBytes = await exportPdfBytes(unitData, data, sealOptions.exportOptions);
|
|
19877
|
-
const workingDoc = await
|
|
21045
|
+
const workingDoc = await import_pdf_lib6.PDFDocument.load(basePdfBytes);
|
|
19878
21046
|
if (sealOptions.stampAuditFooter !== false) {
|
|
19879
|
-
const fontBold = await workingDoc.embedFont(
|
|
19880
|
-
const fontReg = await workingDoc.embedFont(
|
|
21047
|
+
const fontBold = await workingDoc.embedFont(import_pdf_lib6.StandardFonts.HelveticaBold);
|
|
21048
|
+
const fontReg = await workingDoc.embedFont(import_pdf_lib6.StandardFonts.Helvetica);
|
|
19881
21049
|
const pages = workingDoc.getPages();
|
|
19882
21050
|
const asciiSigner = signer.replace(/[^\x20-\x7E]/g, "").trim();
|
|
19883
21051
|
const signerTag = asciiSigner || `ID#${sha256HexSync(signer).slice(0, 8)}`;
|
|
@@ -19891,8 +21059,8 @@ async function exportSignedPdfWithAuditSeal(unitData, data, sealOptions) {
|
|
|
19891
21059
|
y: 3.5,
|
|
19892
21060
|
width: barWidth,
|
|
19893
21061
|
height: 10.5,
|
|
19894
|
-
color: (0,
|
|
19895
|
-
borderColor: (0,
|
|
21062
|
+
color: (0, import_pdf_lib6.rgb)(0.97, 0.98, 0.99),
|
|
21063
|
+
borderColor: (0, import_pdf_lib6.rgb)(0.76, 0.82, 0.9),
|
|
19896
21064
|
borderWidth: 0.45,
|
|
19897
21065
|
opacity: 0.94
|
|
19898
21066
|
});
|
|
@@ -19901,7 +21069,7 @@ async function exportSignedPdfWithAuditSeal(unitData, data, sealOptions) {
|
|
|
19901
21069
|
y: 6.4,
|
|
19902
21070
|
size: 5.5,
|
|
19903
21071
|
font: fontBold,
|
|
19904
|
-
color: (0,
|
|
21072
|
+
color: (0, import_pdf_lib6.rgb)(0.11, 0.25, 0.68)
|
|
19905
21073
|
});
|
|
19906
21074
|
const detailText = `Signer: ${signerTag} | ${signedAt} | Payload SHA-256: ${payloadDigestHex.slice(0, 24)}...`;
|
|
19907
21075
|
page.drawText(detailText, {
|
|
@@ -19909,13 +21077,13 @@ async function exportSignedPdfWithAuditSeal(unitData, data, sealOptions) {
|
|
|
19909
21077
|
y: 6.4,
|
|
19910
21078
|
size: 5.3,
|
|
19911
21079
|
font: fontReg,
|
|
19912
|
-
color: (0,
|
|
21080
|
+
color: (0, import_pdf_lib6.rgb)(0.28, 0.34, 0.42),
|
|
19913
21081
|
maxWidth: Math.max(40, barWidth - 52)
|
|
19914
21082
|
});
|
|
19915
21083
|
}
|
|
19916
21084
|
}
|
|
19917
21085
|
const preSealBytes = await workingDoc.save({ updateFieldAppearances: false });
|
|
19918
|
-
const finalizedDoc = await
|
|
21086
|
+
const finalizedDoc = await import_pdf_lib6.PDFDocument.load(preSealBytes);
|
|
19919
21087
|
const pageCount = finalizedDoc.getPageCount();
|
|
19920
21088
|
const contentDigestHex = computePdfPageStreamsDigestHex(finalizedDoc);
|
|
19921
21089
|
const digestHex = computeCanonicalEnvelopeDigestHex({
|
|
@@ -19953,8 +21121,8 @@ async function exportSignedPdfWithAuditSeal(unitData, data, sealOptions) {
|
|
|
19953
21121
|
]);
|
|
19954
21122
|
const infoRef = finalizedDoc.context.trailerInfo.Info;
|
|
19955
21123
|
if (infoRef) {
|
|
19956
|
-
const infoDict = finalizedDoc.context.lookup(infoRef,
|
|
19957
|
-
infoDict.set(
|
|
21124
|
+
const infoDict = finalizedDoc.context.lookup(infoRef, import_pdf_lib6.PDFDict);
|
|
21125
|
+
infoDict.set(import_pdf_lib6.PDFName.of(AUDIT_INFO_KEY), import_pdf_lib6.PDFHexString.fromText(JSON.stringify(record)));
|
|
19958
21126
|
}
|
|
19959
21127
|
const signedPdfBytes = await finalizedDoc.save({ updateFieldAppearances: false });
|
|
19960
21128
|
return {
|
|
@@ -19965,14 +21133,14 @@ async function exportSignedPdfWithAuditSeal(unitData, data, sealOptions) {
|
|
|
19965
21133
|
}
|
|
19966
21134
|
async function verifyPdfAuditSeal(pdfBytes) {
|
|
19967
21135
|
try {
|
|
19968
|
-
const doc = await
|
|
21136
|
+
const doc = await import_pdf_lib6.PDFDocument.load(pdfBytes, { ignoreEncryption: true });
|
|
19969
21137
|
const subject = doc.getSubject() ?? "";
|
|
19970
21138
|
const infoRef = doc.context.trailerInfo.Info;
|
|
19971
21139
|
let rawSealJson = null;
|
|
19972
21140
|
if (infoRef) {
|
|
19973
|
-
const infoDict = doc.context.lookupMaybe(infoRef,
|
|
19974
|
-
const customEntry = infoDict?.get(
|
|
19975
|
-
if (customEntry instanceof
|
|
21141
|
+
const infoDict = doc.context.lookupMaybe(infoRef, import_pdf_lib6.PDFDict);
|
|
21142
|
+
const customEntry = infoDict?.get(import_pdf_lib6.PDFName.of(AUDIT_INFO_KEY));
|
|
21143
|
+
if (customEntry instanceof import_pdf_lib6.PDFHexString || customEntry instanceof import_pdf_lib6.PDFString) {
|
|
19976
21144
|
rawSealJson = customEntry.decodeText();
|
|
19977
21145
|
}
|
|
19978
21146
|
}
|
|
@@ -20045,7 +21213,7 @@ async function verifyPdfAuditSeal(pdfBytes) {
|
|
|
20045
21213
|
|
|
20046
21214
|
// src/exporter/pdf-convert-and-compliance.ts
|
|
20047
21215
|
var import_core9 = require("@univerjs/core");
|
|
20048
|
-
var
|
|
21216
|
+
var import_pdf_lib7 = require("pdf-lib");
|
|
20049
21217
|
function collectOrderedPageFragments(unit, pageId, pageIndex) {
|
|
20050
21218
|
const suppressed = new Set(unit.editState.suppressedSourceIds ?? []);
|
|
20051
21219
|
const layersById = new Map((unit.layers ?? []).map((l) => [l.id, l]));
|
|
@@ -21090,37 +22258,37 @@ function bytesToBase64Pure(bytes) {
|
|
|
21090
22258
|
return btoa(bin);
|
|
21091
22259
|
}
|
|
21092
22260
|
async function extractAttachmentsFromPdfBytes(pdfBytes) {
|
|
21093
|
-
const doc = await
|
|
21094
|
-
const namesDict = doc.context.lookupMaybe(doc.catalog.get(
|
|
22261
|
+
const doc = await import_pdf_lib7.PDFDocument.load(pdfBytes, { ignoreEncryption: true });
|
|
22262
|
+
const namesDict = doc.context.lookupMaybe(doc.catalog.get(import_pdf_lib7.PDFName.of("Names")), import_pdf_lib7.PDFDict);
|
|
21095
22263
|
if (!namesDict) return [];
|
|
21096
|
-
const efTree = doc.context.lookupMaybe(namesDict.get(
|
|
22264
|
+
const efTree = doc.context.lookupMaybe(namesDict.get(import_pdf_lib7.PDFName.of("EmbeddedFiles")), import_pdf_lib7.PDFDict);
|
|
21097
22265
|
if (!efTree) return [];
|
|
21098
22266
|
const out = [];
|
|
21099
22267
|
const collectFromNode = (node) => {
|
|
21100
|
-
const namesArr = doc.context.lookupMaybe(node.get(
|
|
22268
|
+
const namesArr = doc.context.lookupMaybe(node.get(import_pdf_lib7.PDFName.of("Names")), import_pdf_lib7.PDFArray);
|
|
21101
22269
|
if (namesArr) {
|
|
21102
22270
|
for (let i = 0; i + 1 < namesArr.size(); i += 2) {
|
|
21103
22271
|
const keyObj = namesArr.get(i);
|
|
21104
|
-
const fsDict = doc.context.lookupMaybe(namesArr.get(i + 1),
|
|
22272
|
+
const fsDict = doc.context.lookupMaybe(namesArr.get(i + 1), import_pdf_lib7.PDFDict);
|
|
21105
22273
|
if (!fsDict) continue;
|
|
21106
|
-
const ufObj = fsDict.get(
|
|
21107
|
-
const fileName = ufObj instanceof
|
|
21108
|
-
const descObj = fsDict.get(
|
|
21109
|
-
const description = descObj instanceof
|
|
21110
|
-
const efDict = doc.context.lookupMaybe(fsDict.get(
|
|
21111
|
-
const streamEntry = efDict?.get(
|
|
21112
|
-
const resolvedStream = streamEntry instanceof
|
|
21113
|
-
if (!(resolvedStream instanceof
|
|
22274
|
+
const ufObj = fsDict.get(import_pdf_lib7.PDFName.of("UF")) ?? fsDict.get(import_pdf_lib7.PDFName.of("F")) ?? keyObj;
|
|
22275
|
+
const fileName = ufObj instanceof import_pdf_lib7.PDFHexString || ufObj instanceof import_pdf_lib7.PDFString ? ufObj.decodeText() : String(ufObj);
|
|
22276
|
+
const descObj = fsDict.get(import_pdf_lib7.PDFName.of("Desc"));
|
|
22277
|
+
const description = descObj instanceof import_pdf_lib7.PDFHexString || descObj instanceof import_pdf_lib7.PDFString ? descObj.decodeText() : void 0;
|
|
22278
|
+
const efDict = doc.context.lookupMaybe(fsDict.get(import_pdf_lib7.PDFName.of("EF")), import_pdf_lib7.PDFDict);
|
|
22279
|
+
const streamEntry = efDict?.get(import_pdf_lib7.PDFName.of("UF")) ?? efDict?.get(import_pdf_lib7.PDFName.of("F"));
|
|
22280
|
+
const resolvedStream = streamEntry instanceof import_pdf_lib7.PDFRef ? doc.context.lookup(streamEntry) : streamEntry;
|
|
22281
|
+
if (!(resolvedStream instanceof import_pdf_lib7.PDFRawStream)) continue;
|
|
21114
22282
|
const rawStream = resolvedStream;
|
|
21115
22283
|
let decoded;
|
|
21116
22284
|
try {
|
|
21117
|
-
const res = (0,
|
|
22285
|
+
const res = (0, import_pdf_lib7.decodePDFRawStream)(rawStream).decode();
|
|
21118
22286
|
decoded = res instanceof Uint8Array ? res : new Uint8Array(res);
|
|
21119
22287
|
} catch {
|
|
21120
22288
|
decoded = rawStream.contents;
|
|
21121
22289
|
}
|
|
21122
|
-
const subObj = rawStream.dict.get(
|
|
21123
|
-
const mimeType = subObj instanceof
|
|
22290
|
+
const subObj = rawStream.dict.get(import_pdf_lib7.PDFName.of("Subtype"));
|
|
22291
|
+
const mimeType = subObj instanceof import_pdf_lib7.PDFName ? subObj.decodeText().replace(/#2F/gi, "/") : "application/octet-stream";
|
|
21124
22292
|
out.push({
|
|
21125
22293
|
id: `att-${(0, import_core9.generateRandomId)(6)}`,
|
|
21126
22294
|
fileName,
|
|
@@ -21130,10 +22298,10 @@ async function extractAttachmentsFromPdfBytes(pdfBytes) {
|
|
|
21130
22298
|
});
|
|
21131
22299
|
}
|
|
21132
22300
|
}
|
|
21133
|
-
const kidsArr = doc.context.lookupMaybe(node.get(
|
|
22301
|
+
const kidsArr = doc.context.lookupMaybe(node.get(import_pdf_lib7.PDFName.of("Kids")), import_pdf_lib7.PDFArray);
|
|
21134
22302
|
if (kidsArr) {
|
|
21135
22303
|
for (let k = 0; k < kidsArr.size(); k++) {
|
|
21136
|
-
const child = doc.context.lookupMaybe(kidsArr.get(k),
|
|
22304
|
+
const child = doc.context.lookupMaybe(kidsArr.get(k), import_pdf_lib7.PDFDict);
|
|
21137
22305
|
if (child) collectFromNode(child);
|
|
21138
22306
|
}
|
|
21139
22307
|
}
|
|
@@ -21264,7 +22432,7 @@ function matchPaperPresetMm(wMm, hMm, tolMm = 1.5) {
|
|
|
21264
22432
|
}
|
|
21265
22433
|
async function inspectPdfBytePageSizes(pdfBytes, options) {
|
|
21266
22434
|
const loadOpts = options?.password ? { password: options.password } : { ignoreEncryption: true };
|
|
21267
|
-
const doc = await
|
|
22435
|
+
const doc = await import_pdf_lib7.PDFDocument.load(pdfBytes, loadOpts);
|
|
21268
22436
|
const pages = doc.getPages();
|
|
21269
22437
|
return pages.map((page, pageIndex) => {
|
|
21270
22438
|
const sz = page.getSize();
|
|
@@ -21492,7 +22660,7 @@ function isPngSignature(bytes) {
|
|
|
21492
22660
|
return bytes.length >= 8 && bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71;
|
|
21493
22661
|
}
|
|
21494
22662
|
async function convertImagesToPdfBytes(images, options) {
|
|
21495
|
-
const pdfDoc = await
|
|
22663
|
+
const pdfDoc = await import_pdf_lib7.PDFDocument.create();
|
|
21496
22664
|
const sizeSpec = resolveConverterPageSizePt(options?.pageSize ?? "A4");
|
|
21497
22665
|
const marginPt = mmToPt(Math.max(0, options?.marginMm ?? 0));
|
|
21498
22666
|
if (!images.length) {
|
|
@@ -21548,28 +22716,28 @@ async function convertImagesToPdfBytes(images, options) {
|
|
|
21548
22716
|
);
|
|
21549
22717
|
if (placement.needsClip) {
|
|
21550
22718
|
page.pushOperators(
|
|
21551
|
-
(0,
|
|
21552
|
-
(0,
|
|
21553
|
-
(0,
|
|
21554
|
-
(0,
|
|
21555
|
-
(0,
|
|
21556
|
-
(0,
|
|
21557
|
-
(0,
|
|
22719
|
+
(0, import_pdf_lib7.pushGraphicsState)(),
|
|
22720
|
+
(0, import_pdf_lib7.rectangle)(placement.clipX, placement.clipY, placement.clipWidth, placement.clipHeight),
|
|
22721
|
+
(0, import_pdf_lib7.clip)(),
|
|
22722
|
+
(0, import_pdf_lib7.endPath)(),
|
|
22723
|
+
(0, import_pdf_lib7.concatTransformationMatrix)(ma, mb, mc, md, me, mf),
|
|
22724
|
+
(0, import_pdf_lib7.drawObject)(imgKey),
|
|
22725
|
+
(0, import_pdf_lib7.popGraphicsState)()
|
|
21558
22726
|
);
|
|
21559
22727
|
} else {
|
|
21560
22728
|
page.pushOperators(
|
|
21561
|
-
(0,
|
|
21562
|
-
(0,
|
|
21563
|
-
(0,
|
|
21564
|
-
(0,
|
|
22729
|
+
(0, import_pdf_lib7.pushGraphicsState)(),
|
|
22730
|
+
(0, import_pdf_lib7.concatTransformationMatrix)(ma, mb, mc, md, me, mf),
|
|
22731
|
+
(0, import_pdf_lib7.drawObject)(imgKey),
|
|
22732
|
+
(0, import_pdf_lib7.popGraphicsState)()
|
|
21565
22733
|
);
|
|
21566
22734
|
}
|
|
21567
22735
|
} else if (placement.needsClip) {
|
|
21568
22736
|
page.pushOperators(
|
|
21569
|
-
(0,
|
|
21570
|
-
(0,
|
|
21571
|
-
(0,
|
|
21572
|
-
(0,
|
|
22737
|
+
(0, import_pdf_lib7.pushGraphicsState)(),
|
|
22738
|
+
(0, import_pdf_lib7.rectangle)(placement.clipX, placement.clipY, placement.clipWidth, placement.clipHeight),
|
|
22739
|
+
(0, import_pdf_lib7.clip)(),
|
|
22740
|
+
(0, import_pdf_lib7.endPath)()
|
|
21573
22741
|
);
|
|
21574
22742
|
page.drawImage(embedded, {
|
|
21575
22743
|
x: placement.drawX,
|
|
@@ -21577,7 +22745,7 @@ async function convertImagesToPdfBytes(images, options) {
|
|
|
21577
22745
|
width: placement.drawWidth,
|
|
21578
22746
|
height: placement.drawHeight
|
|
21579
22747
|
});
|
|
21580
|
-
page.pushOperators((0,
|
|
22748
|
+
page.pushOperators((0, import_pdf_lib7.popGraphicsState)());
|
|
21581
22749
|
} else {
|
|
21582
22750
|
page.drawImage(embedded, {
|
|
21583
22751
|
x: placement.drawX,
|
|
@@ -22668,6 +23836,240 @@ function createPdfBrowserFidelityExpectations() {
|
|
|
22668
23836
|
}
|
|
22669
23837
|
var PDF_S1_S7_FIDELITY_EXPECTATIONS = Object.freeze(createPdfBrowserFidelityExpectations());
|
|
22670
23838
|
|
|
23839
|
+
// src/exporter/pdf-importer.ts
|
|
23840
|
+
var import_core11 = require("@univerjs/core");
|
|
23841
|
+
var import_pdf_lib8 = require("pdf-lib");
|
|
23842
|
+
function hasPdfMagicHeader(bytes) {
|
|
23843
|
+
if (!bytes || bytes.byteLength < 5) return false;
|
|
23844
|
+
const maxScan = Math.min(bytes.byteLength - 5, 1024);
|
|
23845
|
+
for (let i = 0; i <= maxScan; i++) {
|
|
23846
|
+
if (bytes[i] === 37 && bytes[i + 1] === 80 && bytes[i + 2] === 68 && bytes[i + 3] === 70 && bytes[i + 4] === 45) {
|
|
23847
|
+
return true;
|
|
23848
|
+
}
|
|
23849
|
+
}
|
|
23850
|
+
return false;
|
|
23851
|
+
}
|
|
23852
|
+
function decodePdfTextValue(obj) {
|
|
23853
|
+
if (obj instanceof import_pdf_lib8.PDFHexString || obj instanceof import_pdf_lib8.PDFString || obj instanceof import_pdf_lib8.PDFName) {
|
|
23854
|
+
return obj.decodeText();
|
|
23855
|
+
}
|
|
23856
|
+
return "";
|
|
23857
|
+
}
|
|
23858
|
+
function extractOutlinesBookmarksFromDoc(doc) {
|
|
23859
|
+
const outlinesRef = doc.catalog.get(import_pdf_lib8.PDFName.of("Outlines"));
|
|
23860
|
+
const outlinesDict = doc.context.lookupMaybe(outlinesRef, import_pdf_lib8.PDFDict);
|
|
23861
|
+
if (!outlinesDict) return [];
|
|
23862
|
+
const pages = doc.getPages();
|
|
23863
|
+
const pageRefKeyToIdx = /* @__PURE__ */ new Map();
|
|
23864
|
+
pages.forEach((p, idx) => {
|
|
23865
|
+
pageRefKeyToIdx.set(`${p.ref.objectNumber}:${p.ref.generationNumber}`, idx);
|
|
23866
|
+
});
|
|
23867
|
+
const resolveDest = (itemDict) => {
|
|
23868
|
+
let destObj = itemDict.get(import_pdf_lib8.PDFName.of("Dest"));
|
|
23869
|
+
if (!destObj) {
|
|
23870
|
+
const actionDict = doc.context.lookupMaybe(itemDict.get(import_pdf_lib8.PDFName.of("A")), import_pdf_lib8.PDFDict);
|
|
23871
|
+
if (actionDict) {
|
|
23872
|
+
destObj = actionDict.get(import_pdf_lib8.PDFName.of("D"));
|
|
23873
|
+
}
|
|
23874
|
+
}
|
|
23875
|
+
const destArr = doc.context.lookupMaybe(destObj, import_pdf_lib8.PDFArray);
|
|
23876
|
+
if (!destArr || destArr.size() === 0) return { pageIndex: 0 };
|
|
23877
|
+
const pRef = destArr.get(0);
|
|
23878
|
+
let pageIndex = 0;
|
|
23879
|
+
if (pRef instanceof import_pdf_lib8.PDFRef) {
|
|
23880
|
+
pageIndex = pageRefKeyToIdx.get(`${pRef.objectNumber}:${pRef.generationNumber}`) ?? 0;
|
|
23881
|
+
} else if (pRef instanceof import_pdf_lib8.PDFNumber) {
|
|
23882
|
+
pageIndex = Math.max(0, Math.min(pages.length - 1, Math.floor(pRef.asNumber())));
|
|
23883
|
+
}
|
|
23884
|
+
let topPt;
|
|
23885
|
+
if (destArr.size() >= 4) {
|
|
23886
|
+
const yObj = destArr.get(3);
|
|
23887
|
+
if (yObj instanceof import_pdf_lib8.PDFNumber && pages[pageIndex]) {
|
|
23888
|
+
const pageHeight = pages[pageIndex].getHeight();
|
|
23889
|
+
topPt = Math.round(Math.max(0, pageHeight - yObj.asNumber()) * 100) / 100;
|
|
23890
|
+
}
|
|
23891
|
+
}
|
|
23892
|
+
return { pageIndex, topPt };
|
|
23893
|
+
};
|
|
23894
|
+
const visited = /* @__PURE__ */ new Set();
|
|
23895
|
+
const walkLevel = (firstRef) => {
|
|
23896
|
+
const list = [];
|
|
23897
|
+
let cur = firstRef;
|
|
23898
|
+
while (cur) {
|
|
23899
|
+
if (cur instanceof import_pdf_lib8.PDFRef) {
|
|
23900
|
+
const key = `${cur.objectNumber}:${cur.generationNumber}`;
|
|
23901
|
+
if (visited.has(key)) break;
|
|
23902
|
+
visited.add(key);
|
|
23903
|
+
}
|
|
23904
|
+
const itemDict = cur instanceof import_pdf_lib8.PDFDict ? cur : doc.context.lookupMaybe(cur, import_pdf_lib8.PDFDict);
|
|
23905
|
+
if (!itemDict) break;
|
|
23906
|
+
const title = decodePdfTextValue(itemDict.get(import_pdf_lib8.PDFName.of("Title"))) || "Bookmark";
|
|
23907
|
+
const { pageIndex, topPt } = resolveDest(itemDict);
|
|
23908
|
+
const childFirst = itemDict.get(import_pdf_lib8.PDFName.of("First"));
|
|
23909
|
+
const children = childFirst ? walkLevel(childFirst) : [];
|
|
23910
|
+
const bm = {
|
|
23911
|
+
id: `bm-${(0, import_core11.generateRandomId)(6)}`,
|
|
23912
|
+
title,
|
|
23913
|
+
pageIndex,
|
|
23914
|
+
...topPt !== void 0 ? { topOffsetPt: topPt, topPt } : {},
|
|
23915
|
+
...children.length > 0 ? { children } : {}
|
|
23916
|
+
};
|
|
23917
|
+
list.push(bm);
|
|
23918
|
+
const nextRef = itemDict.get(import_pdf_lib8.PDFName.of("Next"));
|
|
23919
|
+
if (!nextRef || nextRef === cur) break;
|
|
23920
|
+
cur = nextRef;
|
|
23921
|
+
}
|
|
23922
|
+
return list;
|
|
23923
|
+
};
|
|
23924
|
+
return walkLevel(outlinesDict.get(import_pdf_lib8.PDFName.of("First")));
|
|
23925
|
+
}
|
|
23926
|
+
function extractLayersFromDoc(doc) {
|
|
23927
|
+
const ocProps = doc.context.lookupMaybe(doc.catalog.get(import_pdf_lib8.PDFName.of("OCProperties")), import_pdf_lib8.PDFDict);
|
|
23928
|
+
if (!ocProps) return [];
|
|
23929
|
+
const ocgsArr = doc.context.lookupMaybe(ocProps.get(import_pdf_lib8.PDFName.of("OCGs")), import_pdf_lib8.PDFArray);
|
|
23930
|
+
if (!ocgsArr || ocgsArr.size() === 0) return [];
|
|
23931
|
+
const defaultCfg = doc.context.lookupMaybe(ocProps.get(import_pdf_lib8.PDFName.of("D")), import_pdf_lib8.PDFDict);
|
|
23932
|
+
const offRefKeys = /* @__PURE__ */ new Set();
|
|
23933
|
+
const lockedRefKeys = /* @__PURE__ */ new Set();
|
|
23934
|
+
if (defaultCfg) {
|
|
23935
|
+
const offArr = doc.context.lookupMaybe(defaultCfg.get(import_pdf_lib8.PDFName.of("OFF")), import_pdf_lib8.PDFArray);
|
|
23936
|
+
if (offArr) {
|
|
23937
|
+
for (let i = 0; i < offArr.size(); i++) {
|
|
23938
|
+
const r = offArr.get(i);
|
|
23939
|
+
if (r instanceof import_pdf_lib8.PDFRef) offRefKeys.add(`${r.objectNumber}:${r.generationNumber}`);
|
|
23940
|
+
}
|
|
23941
|
+
}
|
|
23942
|
+
const lockedArr = doc.context.lookupMaybe(defaultCfg.get(import_pdf_lib8.PDFName.of("Locked")), import_pdf_lib8.PDFArray);
|
|
23943
|
+
if (lockedArr) {
|
|
23944
|
+
for (let i = 0; i < lockedArr.size(); i++) {
|
|
23945
|
+
const r = lockedArr.get(i);
|
|
23946
|
+
if (r instanceof import_pdf_lib8.PDFRef) lockedRefKeys.add(`${r.objectNumber}:${r.generationNumber}`);
|
|
23947
|
+
}
|
|
23948
|
+
}
|
|
23949
|
+
}
|
|
23950
|
+
const out = [];
|
|
23951
|
+
for (let i = 0; i < ocgsArr.size(); i++) {
|
|
23952
|
+
const entry = ocgsArr.get(i);
|
|
23953
|
+
const key = entry instanceof import_pdf_lib8.PDFRef ? `${entry.objectNumber}:${entry.generationNumber}` : "";
|
|
23954
|
+
const dict = entry instanceof import_pdf_lib8.PDFDict ? entry : doc.context.lookupMaybe(entry, import_pdf_lib8.PDFDict);
|
|
23955
|
+
if (!dict) continue;
|
|
23956
|
+
const name = decodePdfTextValue(dict.get(import_pdf_lib8.PDFName.of("Name"))) || `Layer ${i + 1}`;
|
|
23957
|
+
let printable = true;
|
|
23958
|
+
const usage = doc.context.lookupMaybe(dict.get(import_pdf_lib8.PDFName.of("Usage")), import_pdf_lib8.PDFDict);
|
|
23959
|
+
if (usage) {
|
|
23960
|
+
const printDict = doc.context.lookupMaybe(usage.get(import_pdf_lib8.PDFName.of("Print")), import_pdf_lib8.PDFDict);
|
|
23961
|
+
if (printDict && decodePdfTextValue(printDict.get(import_pdf_lib8.PDFName.of("PrintState"))) === "OFF") {
|
|
23962
|
+
printable = false;
|
|
23963
|
+
}
|
|
23964
|
+
}
|
|
23965
|
+
out.push({
|
|
23966
|
+
id: `layer-${(0, import_core11.generateRandomId)(6)}`,
|
|
23967
|
+
name,
|
|
23968
|
+
visible: key ? !offRefKeys.has(key) : true,
|
|
23969
|
+
locked: key ? lockedRefKeys.has(key) : false,
|
|
23970
|
+
printable
|
|
23971
|
+
});
|
|
23972
|
+
}
|
|
23973
|
+
return out;
|
|
23974
|
+
}
|
|
23975
|
+
async function importPdfBytesToUnit(pdfBytes, options) {
|
|
23976
|
+
if (!hasPdfMagicHeader(pdfBytes)) {
|
|
23977
|
+
throw new Error("Invalid PDF binary: missing %PDF- header signature.");
|
|
23978
|
+
}
|
|
23979
|
+
const encryptionInspection = inspectPdfEncryption(pdfBytes);
|
|
23980
|
+
const decryptedBytes = await verifyAndDecryptPdfBytes(pdfBytes, options?.password);
|
|
23981
|
+
const unitTitle = options?.name ?? options?.title;
|
|
23982
|
+
const unit = await importAcroFormPdfToUnit(decryptedBytes, {
|
|
23983
|
+
unitId: options?.unitId,
|
|
23984
|
+
title: unitTitle
|
|
23985
|
+
});
|
|
23986
|
+
if (options?.fileName && unit.sourceDocumentRef) {
|
|
23987
|
+
unit.sourceDocumentRef.fileName = options.fileName;
|
|
23988
|
+
}
|
|
23989
|
+
try {
|
|
23990
|
+
const doc = await import_pdf_lib8.PDFDocument.load(decryptedBytes, { updateMetadata: false });
|
|
23991
|
+
const parsedBookmarks = extractOutlinesBookmarksFromDoc(doc);
|
|
23992
|
+
if (parsedBookmarks.length > 0) {
|
|
23993
|
+
unit.bookmarks = import_core11.Tools.deepClone(parsedBookmarks);
|
|
23994
|
+
unit.metadata = {
|
|
23995
|
+
...unit.metadata ?? {},
|
|
23996
|
+
bookmarks: import_core11.Tools.deepClone(parsedBookmarks)
|
|
23997
|
+
};
|
|
23998
|
+
}
|
|
23999
|
+
const parsedLayers = extractLayersFromDoc(doc);
|
|
24000
|
+
if (parsedLayers.length > 0) {
|
|
24001
|
+
unit.layers = import_core11.Tools.deepClone(parsedLayers);
|
|
24002
|
+
}
|
|
24003
|
+
if (unitTitle === void 0) {
|
|
24004
|
+
const docTitle = doc.getTitle();
|
|
24005
|
+
if (docTitle) {
|
|
24006
|
+
unit.name = docTitle;
|
|
24007
|
+
} else if (options?.fileName) {
|
|
24008
|
+
unit.name = options.fileName.replace(/\.pdf$/i, "");
|
|
24009
|
+
}
|
|
24010
|
+
}
|
|
24011
|
+
} catch {
|
|
24012
|
+
}
|
|
24013
|
+
if (encryptionInspection.encrypted) {
|
|
24014
|
+
unit.metadata = {
|
|
24015
|
+
...unit.metadata ?? {},
|
|
24016
|
+
importedEncryptionInfo: {
|
|
24017
|
+
encrypted: true,
|
|
24018
|
+
requiresOpenPassword: encryptionInspection.requiresOpenPassword,
|
|
24019
|
+
keyLength: encryptionInspection.keyLength,
|
|
24020
|
+
permissions: { ...encryptionInspection.permissions }
|
|
24021
|
+
}
|
|
24022
|
+
};
|
|
24023
|
+
}
|
|
24024
|
+
if (options?.promoteNativeTextToElements) {
|
|
24025
|
+
const spansByPage = unit.editState.nativeTextSpansByPage ?? {};
|
|
24026
|
+
for (const pageId of unit.document.pageOrder) {
|
|
24027
|
+
const pageSpans = spansByPage[pageId] ?? [];
|
|
24028
|
+
if (!unit.editState.elementsByPage[pageId]) {
|
|
24029
|
+
unit.editState.elementsByPage[pageId] = {};
|
|
24030
|
+
}
|
|
24031
|
+
if (!unit.editState.elementOrderByPage[pageId]) {
|
|
24032
|
+
unit.editState.elementOrderByPage[pageId] = [];
|
|
24033
|
+
}
|
|
24034
|
+
for (const span of pageSpans) {
|
|
24035
|
+
if (span.suppressed) continue;
|
|
24036
|
+
span.suppressed = true;
|
|
24037
|
+
const elId = `el-${(0, import_core11.generateRandomId)(6)}`;
|
|
24038
|
+
const textEl = {
|
|
24039
|
+
id: elId,
|
|
24040
|
+
type: "text" /* TEXT */,
|
|
24041
|
+
name: "Imported Text",
|
|
24042
|
+
content: span.text,
|
|
24043
|
+
metadata: { promotedFromNativeSpanId: span.id },
|
|
24044
|
+
transform: {
|
|
24045
|
+
left: span.left,
|
|
24046
|
+
top: span.top,
|
|
24047
|
+
width: span.width,
|
|
24048
|
+
height: span.height,
|
|
24049
|
+
angle: 0
|
|
24050
|
+
},
|
|
24051
|
+
style: {
|
|
24052
|
+
fontFamily: "Inter, PingFang SC, Microsoft YaHei, sans-serif",
|
|
24053
|
+
fontSize: span.fontSize,
|
|
24054
|
+
fontWeight: "normal",
|
|
24055
|
+
color: "#1B1C1F",
|
|
24056
|
+
textAlign: "left",
|
|
24057
|
+
verticalAlign: "middle",
|
|
24058
|
+
lineHeight: 1.2,
|
|
24059
|
+
padding: 0
|
|
24060
|
+
}
|
|
24061
|
+
};
|
|
24062
|
+
unit.editState.elementsByPage[pageId][elId] = textEl;
|
|
24063
|
+
unit.editState.elementOrderByPage[pageId].push(elId);
|
|
24064
|
+
}
|
|
24065
|
+
}
|
|
24066
|
+
if (unit.metadata?.nativeTextSpansByPage) {
|
|
24067
|
+
unit.metadata.nativeTextSpansByPage = import_core11.Tools.deepClone(spansByPage);
|
|
24068
|
+
}
|
|
24069
|
+
}
|
|
24070
|
+
return unit;
|
|
24071
|
+
}
|
|
24072
|
+
|
|
22671
24073
|
// src/jsx/types.ts
|
|
22672
24074
|
var PDF_JSX_ELEMENT_SYMBOL = /* @__PURE__ */ Symbol.for("univer.pdfs.jsx.element");
|
|
22673
24075
|
var PDF_JSX_FRAGMENT_SYMBOL = /* @__PURE__ */ Symbol.for("univer.pdfs.jsx.fragment");
|
|
@@ -23914,10 +25316,10 @@ async function exportJsxToPdfBytes(root, runtimeData, options) {
|
|
|
23914
25316
|
}
|
|
23915
25317
|
|
|
23916
25318
|
// src/plugin.ts
|
|
23917
|
-
var
|
|
25319
|
+
var import_core13 = require("@univerjs/core");
|
|
23918
25320
|
|
|
23919
25321
|
// src/services/pdf-io.service.ts
|
|
23920
|
-
var
|
|
25322
|
+
var import_core12 = require("@univerjs/core");
|
|
23921
25323
|
var import_rxjs3 = require("rxjs");
|
|
23922
25324
|
function uint8ToBase64(bytes) {
|
|
23923
25325
|
let binary = "";
|
|
@@ -23971,7 +25373,7 @@ function createHttpSilentPrintAdapter(config) {
|
|
|
23971
25373
|
payload = null;
|
|
23972
25374
|
}
|
|
23973
25375
|
return {
|
|
23974
|
-
jobId: String(payload?.jobId || payload?.id || `print-${(0,
|
|
25376
|
+
jobId: String(payload?.jobId || payload?.id || `print-${(0, import_core12.generateRandomId)(8)}`),
|
|
23975
25377
|
driver: String(payload?.driver || driver),
|
|
23976
25378
|
byteLength: pdfBytes.byteLength,
|
|
23977
25379
|
printedAt: Number(payload?.printedAt || Date.now())
|
|
@@ -24027,7 +25429,7 @@ function computePdfPayloadDigest(input) {
|
|
|
24027
25429
|
const d2 = (h2 >>> 0).toString(16).padStart(8, "0");
|
|
24028
25430
|
return `fnv64:${d1}${d2}:${approxBytes}:${len}`;
|
|
24029
25431
|
}
|
|
24030
|
-
var IPdfIoService = (0,
|
|
25432
|
+
var IPdfIoService = (0, import_core12.createIdentifier)("yudao.univer-pdfs.io.service");
|
|
24031
25433
|
async function normalizeBinaryToUint8Array(output) {
|
|
24032
25434
|
if (output instanceof Uint8Array) {
|
|
24033
25435
|
return output;
|
|
@@ -24054,7 +25456,7 @@ function decodeBase64Strict(b64Input) {
|
|
|
24054
25456
|
}
|
|
24055
25457
|
return out;
|
|
24056
25458
|
}
|
|
24057
|
-
function
|
|
25459
|
+
function hasPdfMagicHeader2(bytes) {
|
|
24058
25460
|
if (bytes.byteLength < 8) return false;
|
|
24059
25461
|
const scanLimit = Math.min(1024, bytes.byteLength - 5);
|
|
24060
25462
|
for (let i = 0; i <= scanLimit; i++) {
|
|
@@ -24091,74 +25493,74 @@ function countJsInActionDict(actionDict, doc, PDFArrayCtor, PDFDictCtor, PDFName
|
|
|
24091
25493
|
return count;
|
|
24092
25494
|
}
|
|
24093
25495
|
function inspectPdfDocumentImportWarnings(doc, pdfLib) {
|
|
24094
|
-
const { PDFArray:
|
|
25496
|
+
const { PDFArray: PDFArray8, PDFDict: PDFDict8, PDFName: PDFName8 } = pdfLib;
|
|
24095
25497
|
const warnings = [];
|
|
24096
25498
|
let acroFieldCount = 0;
|
|
24097
|
-
const acroFormDict = doc.catalog.lookupMaybe(
|
|
25499
|
+
const acroFormDict = doc.catalog.lookupMaybe(PDFName8.of("AcroForm"), PDFDict8);
|
|
24098
25500
|
if (acroFormDict) {
|
|
24099
25501
|
try {
|
|
24100
25502
|
acroFieldCount = doc.getForm().getFields().length;
|
|
24101
25503
|
} catch {
|
|
24102
|
-
const fieldsArr = acroFormDict.lookupMaybe(
|
|
25504
|
+
const fieldsArr = acroFormDict.lookupMaybe(PDFName8.of("Fields"), PDFArray8);
|
|
24103
25505
|
if (fieldsArr) {
|
|
24104
25506
|
acroFieldCount = fieldsArr.size();
|
|
24105
25507
|
}
|
|
24106
25508
|
}
|
|
24107
25509
|
}
|
|
24108
25510
|
let jsCount = 0;
|
|
24109
|
-
const namesDict = doc.catalog.lookupMaybe(
|
|
24110
|
-
const jsNameTree = namesDict?.lookupMaybe(
|
|
25511
|
+
const namesDict = doc.catalog.lookupMaybe(PDFName8.of("Names"), PDFDict8);
|
|
25512
|
+
const jsNameTree = namesDict?.lookupMaybe(PDFName8.of("JavaScript"), PDFDict8);
|
|
24111
25513
|
if (jsNameTree) {
|
|
24112
|
-
const namesArr = jsNameTree.lookupMaybe(
|
|
25514
|
+
const namesArr = jsNameTree.lookupMaybe(PDFName8.of("Names"), PDFArray8);
|
|
24113
25515
|
jsCount += namesArr ? Math.max(1, Math.floor(namesArr.size() / 2)) : 1;
|
|
24114
25516
|
}
|
|
24115
|
-
const openAction = doc.catalog.lookupMaybe(
|
|
25517
|
+
const openAction = doc.catalog.lookupMaybe(PDFName8.of("OpenAction"), PDFDict8);
|
|
24116
25518
|
if (openAction) {
|
|
24117
|
-
jsCount += countJsInActionDict(openAction, doc,
|
|
25519
|
+
jsCount += countJsInActionDict(openAction, doc, PDFArray8, PDFDict8, PDFName8);
|
|
24118
25520
|
}
|
|
24119
|
-
const catalogAA = doc.catalog.lookupMaybe(
|
|
25521
|
+
const catalogAA = doc.catalog.lookupMaybe(PDFName8.of("AA"), PDFDict8);
|
|
24120
25522
|
if (catalogAA) {
|
|
24121
25523
|
for (const [, actionRef] of catalogAA.entries()) {
|
|
24122
|
-
const act = doc.context.lookupMaybe(actionRef,
|
|
25524
|
+
const act = doc.context.lookupMaybe(actionRef, PDFDict8);
|
|
24123
25525
|
if (act) {
|
|
24124
|
-
jsCount += countJsInActionDict(act, doc,
|
|
25526
|
+
jsCount += countJsInActionDict(act, doc, PDFArray8, PDFDict8, PDFName8);
|
|
24125
25527
|
}
|
|
24126
25528
|
}
|
|
24127
25529
|
}
|
|
24128
25530
|
let activeAnnotationCount = 0;
|
|
24129
25531
|
let orphanWidgetCount = 0;
|
|
24130
25532
|
for (const page of doc.getPages()) {
|
|
24131
|
-
const pageAA = page.node.lookupMaybe(
|
|
25533
|
+
const pageAA = page.node.lookupMaybe(PDFName8.of("AA"), PDFDict8);
|
|
24132
25534
|
if (pageAA) {
|
|
24133
25535
|
for (const [, actionRef] of pageAA.entries()) {
|
|
24134
|
-
const act = doc.context.lookupMaybe(actionRef,
|
|
25536
|
+
const act = doc.context.lookupMaybe(actionRef, PDFDict8);
|
|
24135
25537
|
if (act) {
|
|
24136
|
-
jsCount += countJsInActionDict(act, doc,
|
|
25538
|
+
jsCount += countJsInActionDict(act, doc, PDFArray8, PDFDict8, PDFName8);
|
|
24137
25539
|
}
|
|
24138
25540
|
}
|
|
24139
25541
|
}
|
|
24140
25542
|
const annots = page.node.Annots();
|
|
24141
|
-
if (annots instanceof
|
|
25543
|
+
if (annots instanceof PDFArray8) {
|
|
24142
25544
|
for (let i = 0; i < annots.size(); i++) {
|
|
24143
|
-
const annot = annots.lookupMaybe(i,
|
|
25545
|
+
const annot = annots.lookupMaybe(i, PDFDict8);
|
|
24144
25546
|
if (!annot) continue;
|
|
24145
|
-
const subtypeObj = annot.get(
|
|
25547
|
+
const subtypeObj = annot.get(PDFName8.of("Subtype"));
|
|
24146
25548
|
const subtype = subtypeObj ? subtypeObj.toString() : "";
|
|
24147
25549
|
if (subtype === "/Widget") {
|
|
24148
25550
|
orphanWidgetCount += 1;
|
|
24149
25551
|
} else if (subtype !== "/Popup") {
|
|
24150
25552
|
activeAnnotationCount += 1;
|
|
24151
25553
|
}
|
|
24152
|
-
const annotAction = annot.lookupMaybe(
|
|
25554
|
+
const annotAction = annot.lookupMaybe(PDFName8.of("A"), PDFDict8);
|
|
24153
25555
|
if (annotAction) {
|
|
24154
|
-
jsCount += countJsInActionDict(annotAction, doc,
|
|
25556
|
+
jsCount += countJsInActionDict(annotAction, doc, PDFArray8, PDFDict8, PDFName8);
|
|
24155
25557
|
}
|
|
24156
|
-
const annotAA = annot.lookupMaybe(
|
|
25558
|
+
const annotAA = annot.lookupMaybe(PDFName8.of("AA"), PDFDict8);
|
|
24157
25559
|
if (annotAA) {
|
|
24158
25560
|
for (const [, actionRef] of annotAA.entries()) {
|
|
24159
|
-
const act = doc.context.lookupMaybe(actionRef,
|
|
25561
|
+
const act = doc.context.lookupMaybe(actionRef, PDFDict8);
|
|
24160
25562
|
if (act) {
|
|
24161
|
-
jsCount += countJsInActionDict(act, doc,
|
|
25563
|
+
jsCount += countJsInActionDict(act, doc, PDFArray8, PDFDict8, PDFName8);
|
|
24162
25564
|
}
|
|
24163
25565
|
}
|
|
24164
25566
|
}
|
|
@@ -24213,23 +25615,23 @@ function normalizePdfImportWarnings(raw) {
|
|
|
24213
25615
|
return normalized;
|
|
24214
25616
|
}
|
|
24215
25617
|
function buildOverlayImportCandidateSnapshot(baseSnapshot, outcome) {
|
|
24216
|
-
const prevSnapshot =
|
|
25618
|
+
const prevSnapshot = import_core12.Tools.deepClone(baseSnapshot);
|
|
24217
25619
|
const existingOrder = prevSnapshot.document?.pageOrder ?? [];
|
|
24218
25620
|
const pageSizes = outcome.pageSizes ?? [];
|
|
24219
25621
|
const totalPages = Math.max(1, pageSizes.length || outcome.sourceDocumentRef.pageCount || 1);
|
|
24220
25622
|
const nextPages = {};
|
|
24221
25623
|
const nextPageOrder = [];
|
|
24222
|
-
const nextElementsByPage =
|
|
24223
|
-
const nextElementOrderByPage =
|
|
25624
|
+
const nextElementsByPage = import_core12.Tools.deepClone(prevSnapshot.editState?.elementsByPage ?? {});
|
|
25625
|
+
const nextElementOrderByPage = import_core12.Tools.deepClone(prevSnapshot.editState?.elementOrderByPage ?? {});
|
|
24224
25626
|
for (let i = 0; i < totalPages; i++) {
|
|
24225
|
-
const pid = existingOrder[i] || `page-${(0,
|
|
25627
|
+
const pid = existingOrder[i] || `page-${(0, import_core12.generateRandomId)(6)}`;
|
|
24226
25628
|
nextPageOrder.push(pid);
|
|
24227
25629
|
const resolvedSize = pageSizes[i] ?? pageSizes[0] ?? prevSnapshot.document.pageSize;
|
|
24228
25630
|
nextPages[pid] = {
|
|
24229
25631
|
id: pid,
|
|
24230
25632
|
title: `Page ${i + 1}`,
|
|
24231
25633
|
sourcePageNumber: i + 1,
|
|
24232
|
-
pageSize:
|
|
25634
|
+
pageSize: import_core12.Tools.deepClone(resolvedSize),
|
|
24233
25635
|
backgroundColor: "#ffffff"
|
|
24234
25636
|
};
|
|
24235
25637
|
if (!nextElementsByPage[pid]) nextElementsByPage[pid] = {};
|
|
@@ -24237,10 +25639,10 @@ function buildOverlayImportCandidateSnapshot(baseSnapshot, outcome) {
|
|
|
24237
25639
|
}
|
|
24238
25640
|
return {
|
|
24239
25641
|
...prevSnapshot,
|
|
24240
|
-
sourceDocumentRef:
|
|
25642
|
+
sourceDocumentRef: import_core12.Tools.deepClone(outcome.sourceDocumentRef),
|
|
24241
25643
|
document: {
|
|
24242
25644
|
...prevSnapshot.document,
|
|
24243
|
-
pageSize:
|
|
25645
|
+
pageSize: import_core12.Tools.deepClone(pageSizes[0] ?? prevSnapshot.document.pageSize),
|
|
24244
25646
|
pages: nextPages,
|
|
24245
25647
|
pageOrder: nextPageOrder
|
|
24246
25648
|
},
|
|
@@ -24261,8 +25663,8 @@ function normalizeAdapterImportResult(raw) {
|
|
|
24261
25663
|
return {
|
|
24262
25664
|
outcome: {
|
|
24263
25665
|
mode: "overlay",
|
|
24264
|
-
sourceDocumentRef:
|
|
24265
|
-
pageSizes:
|
|
25666
|
+
sourceDocumentRef: import_core12.Tools.deepClone(record.sourceDocumentRef),
|
|
25667
|
+
pageSizes: import_core12.Tools.deepClone(record.pageSizes ?? []),
|
|
24266
25668
|
...warnings.length > 0 ? { warnings } : {}
|
|
24267
25669
|
},
|
|
24268
25670
|
warnings
|
|
@@ -24270,7 +25672,7 @@ function normalizeAdapterImportResult(raw) {
|
|
|
24270
25672
|
}
|
|
24271
25673
|
if (record.mode === "snapshot") {
|
|
24272
25674
|
const warnings = normalizePdfImportWarnings(record.warnings);
|
|
24273
|
-
const clonedSnapshot =
|
|
25675
|
+
const clonedSnapshot = import_core12.Tools.deepClone(record.snapshot);
|
|
24274
25676
|
return {
|
|
24275
25677
|
outcome: {
|
|
24276
25678
|
mode: "snapshot",
|
|
@@ -24282,7 +25684,7 @@ function normalizeAdapterImportResult(raw) {
|
|
|
24282
25684
|
}
|
|
24283
25685
|
if (record.snapshot && typeof record.snapshot === "object") {
|
|
24284
25686
|
const warnings = normalizePdfImportWarnings(record.warnings);
|
|
24285
|
-
const clonedSnapshot =
|
|
25687
|
+
const clonedSnapshot = import_core12.Tools.deepClone(record.snapshot);
|
|
24286
25688
|
return {
|
|
24287
25689
|
outcome: {
|
|
24288
25690
|
mode: "snapshot",
|
|
@@ -24294,7 +25696,7 @@ function normalizeAdapterImportResult(raw) {
|
|
|
24294
25696
|
}
|
|
24295
25697
|
if ("schema" in record || "document" in record) {
|
|
24296
25698
|
const warnings = normalizePdfImportWarnings(record.warnings);
|
|
24297
|
-
const clonedSnapshot =
|
|
25699
|
+
const clonedSnapshot = import_core12.Tools.deepClone(record);
|
|
24298
25700
|
delete clonedSnapshot.warnings;
|
|
24299
25701
|
return {
|
|
24300
25702
|
outcome: {
|
|
@@ -24415,19 +25817,31 @@ async function importPdfSource(source, options) {
|
|
|
24415
25817
|
} else {
|
|
24416
25818
|
throw new PdfImportError("INVALID_PDF_HEADER", "Unsupported PDF input source.");
|
|
24417
25819
|
}
|
|
24418
|
-
if (!
|
|
25820
|
+
if (!hasPdfMagicHeader2(bytes)) {
|
|
24419
25821
|
throw new PdfImportError(
|
|
24420
25822
|
"INVALID_PDF_HEADER",
|
|
24421
25823
|
"Invalid PDF binary: missing %PDF- header signature."
|
|
24422
25824
|
);
|
|
24423
25825
|
}
|
|
24424
25826
|
throwIfSignalAborted(options?.signal);
|
|
24425
|
-
const { PDFArray:
|
|
25827
|
+
const { PDFArray: PDFArray8, PDFDict: PDFDict8, PDFDocument: PDFDocument8, PDFName: PDFName8 } = await import("pdf-lib");
|
|
24426
25828
|
throwIfSignalAborted(options?.signal);
|
|
24427
25829
|
let pageSizes = [];
|
|
24428
25830
|
let warnings = [];
|
|
25831
|
+
const encInspection = inspectPdfEncryption(bytes);
|
|
25832
|
+
if (encInspection.encrypted) {
|
|
25833
|
+
try {
|
|
25834
|
+
bytes = await verifyAndDecryptPdfBytes(bytes, options?.password);
|
|
25835
|
+
} catch (secErr) {
|
|
25836
|
+
if (secErr instanceof PdfSecurityError) {
|
|
25837
|
+
if (secErr.code === "PDF_PASSWORD_REQUIRED" || secErr.code === "PDF_INVALID_PASSWORD") {
|
|
25838
|
+
throw new PdfImportError("ENCRYPTED_PDF_PASSWORD_REQUIRED", secErr.message);
|
|
25839
|
+
}
|
|
25840
|
+
}
|
|
25841
|
+
}
|
|
25842
|
+
}
|
|
24429
25843
|
try {
|
|
24430
|
-
const doc = await
|
|
25844
|
+
const doc = await PDFDocument8.load(bytes);
|
|
24431
25845
|
if (doc.isEncrypted && !options?.password) {
|
|
24432
25846
|
throw new PdfImportError(
|
|
24433
25847
|
"ENCRYPTED_PDF_PASSWORD_REQUIRED",
|
|
@@ -24442,7 +25856,7 @@ async function importPdfSource(source, options) {
|
|
|
24442
25856
|
const { width, height } = p.getSize();
|
|
24443
25857
|
return { width, height, preset: "CUSTOM" };
|
|
24444
25858
|
});
|
|
24445
|
-
warnings = inspectPdfDocumentImportWarnings(doc, { PDFArray:
|
|
25859
|
+
warnings = inspectPdfDocumentImportWarnings(doc, { PDFArray: PDFArray8, PDFDict: PDFDict8, PDFName: PDFName8 });
|
|
24446
25860
|
} catch (err) {
|
|
24447
25861
|
if (err instanceof PdfImportError) {
|
|
24448
25862
|
throw err;
|
|
@@ -24501,7 +25915,7 @@ async function importPdfSource(source, options) {
|
|
|
24501
25915
|
}
|
|
24502
25916
|
if (!verifiedByPdfjs) {
|
|
24503
25917
|
try {
|
|
24504
|
-
const doc = await
|
|
25918
|
+
const doc = await PDFDocument8.load(bytes, { ignoreEncryption: true });
|
|
24505
25919
|
const pages = doc.getPages();
|
|
24506
25920
|
if (pages.length === 0) {
|
|
24507
25921
|
throw new PdfImportError("CORRUPT_PDF", "PDF document contains zero pages.");
|
|
@@ -24510,7 +25924,7 @@ async function importPdfSource(source, options) {
|
|
|
24510
25924
|
const { width, height } = p.getSize();
|
|
24511
25925
|
return { width, height, preset: "CUSTOM" };
|
|
24512
25926
|
});
|
|
24513
|
-
warnings = inspectPdfDocumentImportWarnings(doc, { PDFArray:
|
|
25927
|
+
warnings = inspectPdfDocumentImportWarnings(doc, { PDFArray: PDFArray8, PDFDict: PDFDict8, PDFName: PDFName8 });
|
|
24514
25928
|
} catch (fallbackErr) {
|
|
24515
25929
|
if (fallbackErr instanceof PdfImportError) throw fallbackErr;
|
|
24516
25930
|
throw new PdfImportError(
|
|
@@ -24530,7 +25944,7 @@ async function importPdfSource(source, options) {
|
|
|
24530
25944
|
mode: "overlay",
|
|
24531
25945
|
bytes,
|
|
24532
25946
|
sourceDocumentRef: {
|
|
24533
|
-
id: `src-${(0,
|
|
25947
|
+
id: `src-${(0, import_core12.generateRandomId)(6)}`,
|
|
24534
25948
|
fileName,
|
|
24535
25949
|
mimeType: "application/pdf",
|
|
24536
25950
|
dataUri,
|
|
@@ -24592,7 +26006,7 @@ async function fallbackReadFileAsOutcome(file, baseSnapshot, password, signal, e
|
|
|
24592
26006
|
...imported.warnings?.length ? { warnings: imported.warnings } : {}
|
|
24593
26007
|
};
|
|
24594
26008
|
}
|
|
24595
|
-
var PdfIoService = class extends
|
|
26009
|
+
var PdfIoService = class extends import_core12.Disposable {
|
|
24596
26010
|
constructor(_univerInstanceService) {
|
|
24597
26011
|
super();
|
|
24598
26012
|
this._univerInstanceService = _univerInstanceService;
|
|
@@ -24781,7 +26195,7 @@ var PdfIoService = class extends import_core11.Disposable {
|
|
|
24781
26195
|
}
|
|
24782
26196
|
_resolveBaseSnapshotForImport(context) {
|
|
24783
26197
|
if (context?.snapshot) {
|
|
24784
|
-
const cloned =
|
|
26198
|
+
const cloned = import_core12.Tools.deepClone(context.snapshot);
|
|
24785
26199
|
return {
|
|
24786
26200
|
unitId: context.unitId || cloned.id,
|
|
24787
26201
|
baseSnapshot: cloned
|
|
@@ -24790,9 +26204,9 @@ var PdfIoService = class extends import_core11.Disposable {
|
|
|
24790
26204
|
if (this._univerInstanceService) {
|
|
24791
26205
|
const unit = context?.unitId ? this._univerInstanceService.getUnit(
|
|
24792
26206
|
context.unitId,
|
|
24793
|
-
|
|
26207
|
+
import_core12.UniverInstanceType.UNIVER_PDF
|
|
24794
26208
|
) : this._univerInstanceService.getCurrentUnitOfType(
|
|
24795
|
-
|
|
26209
|
+
import_core12.UniverInstanceType.UNIVER_PDF
|
|
24796
26210
|
);
|
|
24797
26211
|
if (unit) {
|
|
24798
26212
|
return {
|
|
@@ -24842,7 +26256,7 @@ var PdfIoService = class extends import_core11.Disposable {
|
|
|
24842
26256
|
rawResult = await raceWithAbortSignal(
|
|
24843
26257
|
adapter.importPdf(file, {
|
|
24844
26258
|
unitId,
|
|
24845
|
-
snapshot:
|
|
26259
|
+
snapshot: import_core12.Tools.deepClone(baseSnapshot),
|
|
24846
26260
|
...signal ? { signal } : {},
|
|
24847
26261
|
defaultImport
|
|
24848
26262
|
}),
|
|
@@ -24873,7 +26287,7 @@ var PdfIoService = class extends import_core11.Disposable {
|
|
|
24873
26287
|
}
|
|
24874
26288
|
throwIfSignalAborted(signal);
|
|
24875
26289
|
const { outcome, warnings } = normalizeAdapterImportResult(rawResult);
|
|
24876
|
-
const candidateSnapshot = outcome.mode === "snapshot" ?
|
|
26290
|
+
const candidateSnapshot = outcome.mode === "snapshot" ? import_core12.Tools.deepClone(outcome.snapshot) : buildOverlayImportCandidateSnapshot(baseSnapshot, outcome);
|
|
24877
26291
|
throwIfSignalAborted(signal);
|
|
24878
26292
|
return {
|
|
24879
26293
|
snapshot: candidateSnapshot,
|
|
@@ -24911,7 +26325,7 @@ var PdfIoService = class extends import_core11.Disposable {
|
|
|
24911
26325
|
cancel: false
|
|
24912
26326
|
};
|
|
24913
26327
|
if (this.runBeforeExportHooks(beforeEvent)) {
|
|
24914
|
-
throw new
|
|
26328
|
+
throw new import_core12.CanceledError();
|
|
24915
26329
|
}
|
|
24916
26330
|
throwIfSignalAborted(signal);
|
|
24917
26331
|
const defaultExport = () => raceWithAbortSignal(
|
|
@@ -24984,7 +26398,7 @@ var PdfIoService = class extends import_core11.Disposable {
|
|
|
24984
26398
|
options: params.options,
|
|
24985
26399
|
cancel: false
|
|
24986
26400
|
})) {
|
|
24987
|
-
throw new
|
|
26401
|
+
throw new import_core12.CanceledError();
|
|
24988
26402
|
}
|
|
24989
26403
|
const adapter = this._adapter$.getValue();
|
|
24990
26404
|
if (!adapter.onSilentPrint) {
|
|
@@ -25027,7 +26441,7 @@ var PdfIoService = class extends import_core11.Disposable {
|
|
|
25027
26441
|
}
|
|
25028
26442
|
};
|
|
25029
26443
|
PdfIoService = __decorateClass([
|
|
25030
|
-
__decorateParam(0, (0,
|
|
26444
|
+
__decorateParam(0, (0, import_core12.Optional)(import_core12.IUniverInstanceService))
|
|
25031
26445
|
], PdfIoService);
|
|
25032
26446
|
async function exportPdfWithTarget(arg1, arg2) {
|
|
25033
26447
|
if (arg1 && typeof arg1.exportPdfWithTarget === "function") {
|
|
@@ -25068,7 +26482,7 @@ async function exportPdfWithTarget(arg1, arg2) {
|
|
|
25068
26482
|
|
|
25069
26483
|
// src/plugin.ts
|
|
25070
26484
|
var UNIVER_PDFS_PLUGIN_NAME = "UNIVER_PDFS_PLUGIN";
|
|
25071
|
-
var UniverPdfsPlugin = class extends
|
|
26485
|
+
var UniverPdfsPlugin = class extends import_core13.Plugin {
|
|
25072
26486
|
constructor(_config = {}, _injector, _univerInstanceService, _commandService) {
|
|
25073
26487
|
super();
|
|
25074
26488
|
this._config = _config;
|
|
@@ -25084,9 +26498,9 @@ var UniverPdfsPlugin = class extends import_core12.Plugin {
|
|
|
25084
26498
|
}
|
|
25085
26499
|
onStarting() {
|
|
25086
26500
|
this.disposeWithMe(
|
|
25087
|
-
this._univerInstanceService.registerCtorForType(
|
|
26501
|
+
this._univerInstanceService.registerCtorForType(import_core13.UniverInstanceType.UNIVER_PDF, PdfUnitModel)
|
|
25088
26502
|
);
|
|
25089
|
-
const focusSub = this._univerInstanceService.getCurrentTypeOfUnit$(
|
|
26503
|
+
const focusSub = this._univerInstanceService.getCurrentTypeOfUnit$(import_core13.UniverInstanceType.UNIVER_PDF).subscribe((unit) => {
|
|
25090
26504
|
if (unit && this._univerInstanceService.getFocusedUnit()?.getUnitId() !== unit.getUnitId()) {
|
|
25091
26505
|
this._univerInstanceService.focusUnit(unit.getUnitId());
|
|
25092
26506
|
}
|
|
@@ -25148,6 +26562,7 @@ var UniverPdfsPlugin = class extends import_core12.Plugin {
|
|
|
25148
26562
|
SetPdfHeaderFooterConfigCommand,
|
|
25149
26563
|
SetPdfWatermarkConfigCommand,
|
|
25150
26564
|
SetPdfAttachmentsCommand,
|
|
26565
|
+
SetPdfSecurityConfigCommand,
|
|
25151
26566
|
AddPdfLayerCommand,
|
|
25152
26567
|
UpdatePdfLayerCommand,
|
|
25153
26568
|
RemovePdfLayerCommand,
|
|
@@ -25162,9 +26577,9 @@ var UniverPdfsPlugin = class extends import_core12.Plugin {
|
|
|
25162
26577
|
}
|
|
25163
26578
|
};
|
|
25164
26579
|
UniverPdfsPlugin = __decorateClass([
|
|
25165
|
-
__decorateParam(1, (0,
|
|
25166
|
-
__decorateParam(2,
|
|
25167
|
-
__decorateParam(3,
|
|
26580
|
+
__decorateParam(1, (0, import_core13.Inject)(import_core13.Injector)),
|
|
26581
|
+
__decorateParam(2, import_core13.IUniverInstanceService),
|
|
26582
|
+
__decorateParam(3, import_core13.ICommandService)
|
|
25168
26583
|
], UniverPdfsPlugin);
|
|
25169
26584
|
// Annotate the CommonJS export names for ESM import in node:
|
|
25170
26585
|
0 && (module.exports = {
|
|
@@ -25206,6 +26621,7 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
25206
26621
|
PDF_JSX_ELEMENT_SYMBOL,
|
|
25207
26622
|
PDF_JSX_FRAGMENT_SYMBOL,
|
|
25208
26623
|
PDF_PAGE_PRESETS,
|
|
26624
|
+
PDF_PASSWORD_PADDING,
|
|
25209
26625
|
PDF_S1_S7_FIDELITY_EXPECTATIONS,
|
|
25210
26626
|
PDF_TABLE_THEME_PRESETS,
|
|
25211
26627
|
PT_PER_MM,
|
|
@@ -25220,6 +26636,7 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
25220
26636
|
PdfListKind,
|
|
25221
26637
|
PdfListPresetId,
|
|
25222
26638
|
PdfRenderError,
|
|
26639
|
+
PdfSecurityError,
|
|
25223
26640
|
PdfSelectionService,
|
|
25224
26641
|
PdfTableBorderStyle,
|
|
25225
26642
|
PdfTableCellVerticalAlign,
|
|
@@ -25248,6 +26665,7 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
25248
26665
|
SetPdfNativeTextSpansCommand,
|
|
25249
26666
|
SetPdfPageCropBoxCommand,
|
|
25250
26667
|
SetPdfPageSizeCommand,
|
|
26668
|
+
SetPdfSecurityConfigCommand,
|
|
25251
26669
|
SetPdfWatermarkConfigCommand,
|
|
25252
26670
|
Spacer,
|
|
25253
26671
|
Stack,
|
|
@@ -25267,10 +26685,13 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
25267
26685
|
UpdatePdfUnitPropsCommand,
|
|
25268
26686
|
UpdatePdfUnitPropsMutation,
|
|
25269
26687
|
applyOcrToUnitPage,
|
|
26688
|
+
applyPdfSecurityToDocument,
|
|
25270
26689
|
autoDetectFormFieldsOnPage,
|
|
25271
26690
|
buildMinimalTestTrueTypeFont,
|
|
26691
|
+
buildObjectEncryptionKey,
|
|
25272
26692
|
buildOverlayImportCandidateSnapshot,
|
|
25273
26693
|
buildPdfTemplateFromOcrFields,
|
|
26694
|
+
bytesToHex,
|
|
25274
26695
|
calculatePdfTableRowCapacity,
|
|
25275
26696
|
canonicalJsonStringify,
|
|
25276
26697
|
clearPdfFontUrlCache,
|
|
@@ -25289,12 +26710,15 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
25289
26710
|
computeExifTransformMatrix,
|
|
25290
26711
|
computeExpandedTextHeightMm,
|
|
25291
26712
|
computeExpandedTextHeightPt,
|
|
26713
|
+
computeFileEncryptionKeyFromPadded,
|
|
25292
26714
|
computeFontUrlCacheKey,
|
|
25293
26715
|
computeImageFitPlacement,
|
|
26716
|
+
computeOwnerPasswordValue,
|
|
25294
26717
|
computePasteCascadeOffset,
|
|
25295
26718
|
computePdfPayloadDigest,
|
|
25296
26719
|
computePdfTableSummaryRow,
|
|
25297
26720
|
computeSmartSnapWithEqualGap,
|
|
26721
|
+
computeUserPasswordValue,
|
|
25298
26722
|
convertImagesToPdfBytes,
|
|
25299
26723
|
convertMarkdownToPdfBytes,
|
|
25300
26724
|
convertMarkdownToPdfUnit,
|
|
@@ -25311,6 +26735,8 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
25311
26735
|
createPdfBrowserFidelitySamples,
|
|
25312
26736
|
createPdfCjkFontSources,
|
|
25313
26737
|
createPdfJsxNode,
|
|
26738
|
+
decodePdfPermissionFlags,
|
|
26739
|
+
decryptPdfBytes,
|
|
25314
26740
|
detectCJKCharacters,
|
|
25315
26741
|
detectCJKInPdfInputs,
|
|
25316
26742
|
detectCJKInPdfTemplate,
|
|
@@ -25331,9 +26757,11 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
25331
26757
|
encodeJapanPost,
|
|
25332
26758
|
encodeNw7,
|
|
25333
26759
|
encodePdf417,
|
|
26760
|
+
encodePdfPermissionFlags,
|
|
25334
26761
|
encodeQrCodeMatrix,
|
|
25335
26762
|
encodeUpcA,
|
|
25336
26763
|
encodeUpcE,
|
|
26764
|
+
encryptPdfBytes,
|
|
25337
26765
|
evaluatePdfFormExpression,
|
|
25338
26766
|
evaluatePdfJsxElement,
|
|
25339
26767
|
evaluateSafeTemplateExpression,
|
|
@@ -25345,6 +26773,7 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
25345
26773
|
exportPdfBytes,
|
|
25346
26774
|
exportPdfToDocxSnapshot,
|
|
25347
26775
|
exportPdfToWorkbookSnapshot,
|
|
26776
|
+
exportPdfUnitToBytes,
|
|
25348
26777
|
exportPdfWithTarget,
|
|
25349
26778
|
exportSignedPdfWithAuditSeal,
|
|
25350
26779
|
exportToPdfmeTemplate,
|
|
@@ -25364,13 +26793,16 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
25364
26793
|
getDefaultDateTimeFormat,
|
|
25365
26794
|
getRegisteredOcrAdapter,
|
|
25366
26795
|
getTrueTypeMappedCodePoints,
|
|
26796
|
+
hexToBytes,
|
|
25367
26797
|
importAcroFormPdfToUnit,
|
|
25368
26798
|
importFormDataFromFdf,
|
|
25369
26799
|
importFormDataFromXfdf,
|
|
25370
26800
|
importFromPdfmeTemplate,
|
|
26801
|
+
importPdfBytesToUnit,
|
|
25371
26802
|
importPdfSource,
|
|
25372
26803
|
insertPdfPagesBytes,
|
|
25373
26804
|
inspectPdfBytePageSizes,
|
|
26805
|
+
inspectPdfEncryption,
|
|
25374
26806
|
inspectPdfExportCapabilities,
|
|
25375
26807
|
inspectTrueTypeFont,
|
|
25376
26808
|
isAspectRatioLockedBarcodeType,
|
|
@@ -25378,10 +26810,12 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
25378
26810
|
isExifDimensionsSwapped,
|
|
25379
26811
|
isFontUrlSafeToFetch,
|
|
25380
26812
|
isPdfJsxNode,
|
|
26813
|
+
isPdfSecurityActive,
|
|
25381
26814
|
jsx,
|
|
25382
26815
|
jsxDEV,
|
|
25383
26816
|
jsxs,
|
|
25384
26817
|
mayBeJson,
|
|
26818
|
+
md5Bytes,
|
|
25385
26819
|
mergePdfBytes,
|
|
25386
26820
|
mmToPt,
|
|
25387
26821
|
movePdfPageBytes,
|
|
@@ -25392,6 +26826,7 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
25392
26826
|
optimizePdfUnit,
|
|
25393
26827
|
organizePdfBytes,
|
|
25394
26828
|
overlayDiagnosticGridOnPdfBytes,
|
|
26829
|
+
padPdfPassword,
|
|
25395
26830
|
paginatePdfListItems,
|
|
25396
26831
|
paginatePdfTableRows,
|
|
25397
26832
|
parseGs1ApplicationIdentifiers,
|
|
@@ -25404,6 +26839,7 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
25404
26839
|
parseSvgToVectorCommands,
|
|
25405
26840
|
parseSvgTransformAttr,
|
|
25406
26841
|
ptToMm,
|
|
26842
|
+
rc4Bytes,
|
|
25407
26843
|
readJpegExifOrientation,
|
|
25408
26844
|
recalculatePdfFormFields,
|
|
25409
26845
|
rectsIntersect,
|
|
@@ -25454,6 +26890,7 @@ UniverPdfsPlugin = __decorateClass([
|
|
|
25454
26890
|
validatePdfInputContract,
|
|
25455
26891
|
validatePdfTemplateSchema,
|
|
25456
26892
|
validatePdfTemplateVariables,
|
|
26893
|
+
verifyAndDecryptPdfBytes,
|
|
25457
26894
|
verifyPdfAuditDigest,
|
|
25458
26895
|
verifyPdfAuditSeal,
|
|
25459
26896
|
verifyPdfUnitSignature,
|