reamkit 1.15.1 → 1.15.3
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/dist/esm/core/arc-to-bezier.d.ts +23 -0
- package/dist/esm/core/arc-to-bezier.js +23 -0
- package/dist/esm/core/bidi/algorithm.d.ts +26 -0
- package/dist/esm/core/bidi/algorithm.js +21 -0
- package/dist/esm/core/bidi/char-types.d.ts +17 -0
- package/dist/esm/core/bidi/char-types.js +10 -0
- package/dist/esm/core/bidi/index.d.ts +42 -0
- package/dist/esm/core/bidi/index.js +27 -0
- package/dist/esm/core/bidi/segments.d.ts +22 -0
- package/dist/esm/core/bidi/segments.js +14 -0
- package/dist/esm/core/bytes.d.ts +20 -0
- package/dist/esm/core/bytes.js +24 -1
- package/dist/esm/core/converter/facade.d.ts +38 -1
- package/dist/esm/core/converter/facade.js +25 -0
- package/dist/esm/core/converter/project.d.ts +12 -0
- package/dist/esm/core/converter/project.js +11 -0
- package/dist/esm/core/converter/ream.d.ts +107 -0
- package/dist/esm/core/converter/ream.js +76 -0
- package/dist/esm/core/crypto/asn1.d.ts +77 -0
- package/dist/esm/core/crypto/asn1.js +65 -0
- package/dist/esm/core/crypto/cms.d.ts +25 -0
- package/dist/esm/core/crypto/cms.js +8 -0
- package/dist/esm/core/document-model/index.d.ts +7 -0
- package/dist/esm/core/document-model/types.d.ts +328 -0
- package/dist/esm/core/drawingml/chart-geometry.d.ts +125 -0
- package/dist/esm/core/drawingml/chart-geometry.js +96 -0
- package/dist/esm/core/drawingml/chart-parser.d.ts +34 -0
- package/dist/esm/core/drawingml/chart-parser.js +34 -0
- package/dist/esm/core/drawingml/chart-serializer.d.ts +12 -0
- package/dist/esm/core/drawingml/chart-serializer.js +12 -0
- package/dist/esm/core/drawingml/colors.d.ts +53 -0
- package/dist/esm/core/drawingml/colors.js +41 -0
- package/dist/esm/core/drawingml/preset-geometry.d.ts +30 -0
- package/dist/esm/core/drawingml/preset-geometry.js +30 -0
- package/dist/esm/core/drawingml/shape-render.d.ts +54 -0
- package/dist/esm/core/drawingml/shape-render.js +54 -0
- package/dist/esm/core/drawingml/sparkline-geometry.d.ts +15 -0
- package/dist/esm/core/drawingml/sparkline-geometry.js +13 -0
- package/dist/esm/core/drawingml/theme-parser.d.ts +11 -0
- package/dist/esm/core/drawingml/theme-parser.js +11 -0
- package/dist/esm/core/font/arabic-joining.d.ts +21 -0
- package/dist/esm/core/font/arabic-joining.js +16 -0
- package/dist/esm/core/font/binary-reader.d.ts +17 -0
- package/dist/esm/core/font/binary-reader.js +17 -0
- package/dist/esm/core/font/font-registry.d.ts +37 -0
- package/dist/esm/core/font/font-registry.js +31 -0
- package/dist/esm/core/font/measure.d.ts +20 -0
- package/dist/esm/core/font/measure.js +11 -0
- package/dist/esm/core/font/opentype-layout.d.ts +49 -0
- package/dist/esm/core/font/opentype-layout.js +37 -0
- package/dist/esm/core/font/ttf-parser.d.ts +32 -0
- package/dist/esm/core/font/ttf-parser.js +7 -0
- package/dist/esm/core/font/ttf-subset.d.ts +21 -0
- package/dist/esm/core/font/ttf-subset.js +21 -0
- package/dist/esm/core/fonts/provider.d.ts +8 -1
- package/dist/esm/core/fonts/provider.js +1 -0
- package/dist/esm/core/fonts/remote-fonts.d.ts +22 -0
- package/dist/esm/core/fonts/remote-fonts.js +16 -0
- package/dist/esm/core/hyphenation/index.d.ts +25 -0
- package/dist/esm/core/hyphenation/index.js +17 -0
- package/dist/esm/core/hyphenation/liang.d.ts +27 -0
- package/dist/esm/core/hyphenation/liang.js +14 -0
- package/dist/esm/core/images.d.ts +32 -0
- package/dist/esm/core/images.js +12 -0
- package/dist/esm/core/ir/adapters.d.ts +23 -0
- package/dist/esm/core/ir/features.d.ts +8 -0
- package/dist/esm/core/ir/features.js +1 -0
- package/dist/esm/core/ir/flow.d.ts +20 -0
- package/dist/esm/core/ir/index.d.ts +7 -0
- package/dist/esm/core/ir/loss.d.ts +12 -0
- package/dist/esm/core/ir/loss.js +8 -0
- package/dist/esm/core/ir/resources.d.ts +12 -0
- package/dist/esm/core/ir/resources.js +11 -0
- package/dist/esm/core/ir/sheet.d.ts +81 -0
- package/dist/esm/core/ir/units.d.ts +9 -0
- package/dist/esm/core/ir/units.js +2 -0
- package/dist/esm/core/line-breaker/cjk.d.ts +26 -0
- package/dist/esm/core/line-breaker/cjk.js +60 -0
- package/dist/esm/core/line-breaker/greedy.d.ts +14 -0
- package/dist/esm/core/line-breaker/greedy.js +14 -0
- package/dist/esm/core/line-breaker/index.d.ts +1 -0
- package/dist/esm/core/line-breaker/index.js +3 -0
- package/dist/esm/core/line-breaker/knuth-plass.d.ts +29 -5
- package/dist/esm/core/line-breaker/knuth-plass.js +10 -5
- package/dist/esm/core/numbering/apply.d.ts +19 -0
- package/dist/esm/core/numbering/apply.js +19 -0
- package/dist/esm/core/numbering/state.d.ts +15 -0
- package/dist/esm/core/numbering/state.js +15 -0
- package/dist/esm/core/ole/cfb.d.ts +19 -0
- package/dist/esm/core/ole/cfb.js +16 -0
- package/dist/esm/core/opc/core-properties.d.ts +12 -0
- package/dist/esm/core/opc/core-properties.js +5 -0
- package/dist/esm/core/opc/opc-writer.d.ts +24 -4
- package/dist/esm/core/opc/opc-writer.js +12 -0
- package/dist/esm/core/opc/package.d.ts +55 -0
- package/dist/esm/core/opc/package.js +49 -1
- package/dist/esm/core/opc/relationship-types.d.ts +8 -0
- package/dist/esm/core/opc/relationship-types.js +5 -0
- package/dist/esm/core/opc/relationships.d.ts +12 -0
- package/dist/esm/core/opc/relationships.js +7 -0
- package/dist/esm/core/po-helpers.d.ts +38 -0
- package/dist/esm/core/po-helpers.js +33 -0
- package/dist/esm/core/spreadsheet-model/types.d.ts +302 -0
- package/dist/esm/core/style-cascade/resolver.d.ts +31 -0
- package/dist/esm/core/style-cascade/resolver.js +31 -0
- package/dist/esm/core/style-cascade/table.d.ts +7 -0
- package/dist/esm/core/style-cascade/table.js +7 -0
- package/dist/esm/core/style-cascade/types.d.ts +27 -0
- package/dist/esm/core/style-cascade/types.js +2 -0
- package/dist/esm/core/vector.d.ts +67 -0
- package/dist/esm/core/vector.js +23 -0
- package/dist/esm/excel/activex-parser.d.ts +31 -0
- package/dist/esm/excel/activex-parser.js +24 -0
- package/dist/esm/excel/cell-reference.d.ts +14 -0
- package/dist/esm/excel/cell-reference.js +9 -0
- package/dist/esm/excel/column-bands.d.ts +29 -0
- package/dist/esm/excel/column-bands.js +27 -7
- package/dist/esm/excel/comments-parser.d.ts +19 -0
- package/dist/esm/excel/comments-parser.js +19 -0
- package/dist/esm/excel/conditional-format.d.ts +38 -0
- package/dist/esm/excel/conditional-format.js +25 -0
- package/dist/esm/excel/defined-name-ref.d.ts +21 -0
- package/dist/esm/excel/defined-name-ref.js +20 -0
- package/dist/esm/excel/form-control-parser.d.ts +13 -0
- package/dist/esm/excel/form-control-parser.js +5 -0
- package/dist/esm/excel/formula/context.d.ts +37 -0
- package/dist/esm/excel/formula/dates.d.ts +23 -0
- package/dist/esm/excel/formula/dates.js +20 -0
- package/dist/esm/excel/formula/eval.d.ts +21 -0
- package/dist/esm/excel/formula/eval.js +11 -0
- package/dist/esm/excel/formula/functions.d.ts +12 -0
- package/dist/esm/excel/formula/functions.js +12 -0
- package/dist/esm/excel/formula/index.d.ts +21 -0
- package/dist/esm/excel/formula/index.js +16 -0
- package/dist/esm/excel/formula/lexer.d.ts +12 -0
- package/dist/esm/excel/formula/lexer.js +10 -0
- package/dist/esm/excel/formula/parser.d.ts +20 -0
- package/dist/esm/excel/formula/parser.js +53 -0
- package/dist/esm/excel/formula/value.d.ts +53 -0
- package/dist/esm/excel/formula/value.js +30 -0
- package/dist/esm/excel/header-footer.d.ts +9 -0
- package/dist/esm/excel/header-footer.js +9 -0
- package/dist/esm/excel/number-format.d.ts +34 -0
- package/dist/esm/excel/number-format.js +34 -0
- package/dist/esm/excel/pivot-table-parser.d.ts +8 -0
- package/dist/esm/excel/pivot-table-parser.js +8 -0
- package/dist/esm/excel/print-model.d.ts +77 -1
- package/dist/esm/excel/print-model.js +230 -26
- package/dist/esm/excel/shared-strings-parser.d.ts +13 -0
- package/dist/esm/excel/shared-strings-parser.js +5 -0
- package/dist/esm/excel/sheet-drawing.d.ts +34 -0
- package/dist/esm/excel/sheet-drawing.js +21 -0
- package/dist/esm/excel/sheet-shape-parser.d.ts +12 -0
- package/dist/esm/excel/sheet-shape-parser.js +12 -0
- package/dist/esm/excel/sheet-to-flow.d.ts +29 -0
- package/dist/esm/excel/sheet-to-flow.js +24 -7
- package/dist/esm/excel/slicer-parser.d.ts +23 -0
- package/dist/esm/excel/slicer-parser.js +10 -0
- package/dist/esm/excel/styles-parser.d.ts +8 -0
- package/dist/esm/excel/styles-parser.js +8 -0
- package/dist/esm/excel/table-parser.d.ts +24 -0
- package/dist/esm/excel/table-parser.js +5 -0
- package/dist/esm/excel/workbook-parser.d.ts +17 -0
- package/dist/esm/excel/workbook-parser.js +5 -0
- package/dist/esm/excel/worksheet-parser.d.ts +9 -0
- package/dist/esm/excel/worksheet-parser.js +39 -6
- package/dist/esm/excel/xls/biff-chart.d.ts +10 -0
- package/dist/esm/excel/xls/biff-chart.js +10 -0
- package/dist/esm/excel/xls/biff-reader.d.ts +27 -0
- package/dist/esm/excel/xls/biff-reader.js +44 -0
- package/dist/esm/excel/xls/biff-styles.d.ts +20 -0
- package/dist/esm/excel/xls/biff-styles.js +20 -0
- package/dist/esm/excel/xls/escher.d.ts +27 -0
- package/dist/esm/excel/xls/escher.js +18 -0
- package/dist/esm/excel/xls/xls-reader.d.ts +6 -0
- package/dist/esm/excel/xls/xls-reader.js +6 -0
- package/dist/esm/excel/xlsx-reader.d.ts +30 -0
- package/dist/esm/excel/xlsx-reader.js +38 -4
- package/dist/esm/excel/xlsx-to-pdf.d.ts +27 -0
- package/dist/esm/excel/xlsx-writer.d.ts +14 -0
- package/dist/esm/excel/xlsx-writer.js +13 -0
- package/dist/esm/html/html-writer.d.ts +18 -0
- package/dist/esm/html/html-writer.js +18 -0
- package/dist/esm/index.d.ts +23 -0
- package/dist/esm/layout/math-layout.d.ts +39 -0
- package/dist/esm/layout/math-layout.js +18 -0
- package/dist/esm/layout/page-doc.d.ts +91 -0
- package/dist/esm/layout/styled-layout.d.ts +175 -0
- package/dist/esm/layout/styled-layout.js +136 -4
- package/dist/esm/pdf/builtin-fonts.d.ts +5 -0
- package/dist/esm/pdf/cid-font.d.ts +22 -0
- package/dist/esm/pdf/cid-font.js +10 -0
- package/dist/esm/pdf/embedded-file.d.ts +16 -0
- package/dist/esm/pdf/embedded-file.js +9 -0
- package/dist/esm/pdf/encryption.d.ts +59 -0
- package/dist/esm/pdf/encryption.js +37 -0
- package/dist/esm/pdf/icc-profile.d.ts +8 -0
- package/dist/esm/pdf/icc-profile.js +8 -0
- package/dist/esm/pdf/image-xobject.d.ts +19 -0
- package/dist/esm/pdf/image-xobject.js +9 -0
- package/dist/esm/pdf/objects.d.ts +40 -0
- package/dist/esm/pdf/objects.js +36 -0
- package/dist/esm/pdf/serialize.d.ts +18 -0
- package/dist/esm/pdf/serialize.js +18 -0
- package/dist/esm/pdf/shading.d.ts +16 -0
- package/dist/esm/pdf/shading.js +16 -0
- package/dist/esm/pdf/signature.d.ts +36 -0
- package/dist/esm/pdf/signature.js +22 -0
- package/dist/esm/pdf/struct-tree.d.ts +64 -0
- package/dist/esm/pdf/struct-tree.js +60 -0
- package/dist/esm/pdf/styled-page-emitter.d.ts +33 -0
- package/dist/esm/pdf/styled-page-emitter.js +21 -0
- package/dist/esm/pdf/styled-page-renderer.d.ts +18 -0
- package/dist/esm/pdf/styled-page-renderer.js +18 -0
- package/dist/esm/pdf/text-encoding.d.ts +16 -0
- package/dist/esm/pdf/text-page-renderer.d.ts +11 -0
- package/dist/esm/pdf/vector-graphics.d.ts +12 -0
- package/dist/esm/pdf/vector-graphics.js +12 -0
- package/dist/esm/pdf/writer.d.ts +39 -0
- package/dist/esm/pdf/writer.js +27 -0
- package/dist/esm/pdf/xmp.d.ts +16 -0
- package/dist/esm/pdf/xmp.js +9 -0
- package/dist/esm/pdf-reader/ccitt.d.ts +25 -0
- package/dist/esm/pdf-reader/ccitt.js +15 -0
- package/dist/esm/pdf-reader/cmap.d.ts +12 -0
- package/dist/esm/pdf-reader/cmap.js +9 -0
- package/dist/esm/pdf-reader/content.d.ts +69 -0
- package/dist/esm/pdf-reader/content.js +16 -0
- package/dist/esm/pdf-reader/crypto.d.ts +5 -0
- package/dist/esm/pdf-reader/crypto.js +5 -0
- package/dist/esm/pdf-reader/decrypt.d.ts +17 -0
- package/dist/esm/pdf-reader/decrypt.js +12 -0
- package/dist/esm/pdf-reader/document.d.ts +53 -0
- package/dist/esm/pdf-reader/document.js +50 -0
- package/dist/esm/pdf-reader/flow-build.d.ts +47 -0
- package/dist/esm/pdf-reader/flow-build.js +42 -0
- package/dist/esm/pdf-reader/font.d.ts +12 -0
- package/dist/esm/pdf-reader/font.js +12 -0
- package/dist/esm/pdf-reader/image-decode.d.ts +21 -0
- package/dist/esm/pdf-reader/image-decode.js +14 -0
- package/dist/esm/pdf-reader/images.d.ts +19 -0
- package/dist/esm/pdf-reader/images.js +9 -0
- package/dist/esm/pdf-reader/layout.d.ts +15 -0
- package/dist/esm/pdf-reader/layout.js +15 -0
- package/dist/esm/pdf-reader/lexer.d.ts +43 -0
- package/dist/esm/pdf-reader/lexer.js +38 -0
- package/dist/esm/pdf-reader/parser.d.ts +15 -0
- package/dist/esm/pdf-reader/parser.js +8 -0
- package/dist/esm/pdf-reader/png-encode.d.ts +9 -0
- package/dist/esm/pdf-reader/png-encode.js +8 -0
- package/dist/esm/pdf-reader/predictor.d.ts +9 -0
- package/dist/esm/pdf-reader/predictor.js +8 -0
- package/dist/esm/pdf-reader/reader.d.ts +16 -0
- package/dist/esm/pdf-reader/reader.js +16 -0
- package/dist/esm/pdf-reader/shading.d.ts +10 -0
- package/dist/esm/pdf-reader/shading.js +10 -0
- package/dist/esm/pdf-reader/struct-tree.d.ts +24 -0
- package/dist/esm/pdf-reader/struct-tree.js +12 -0
- package/dist/esm/pdf-reader/tagged.d.ts +13 -0
- package/dist/esm/pdf-reader/tagged.js +13 -0
- package/dist/esm/pdf-reader/text.d.ts +11 -0
- package/dist/esm/pdf-reader/text.js +11 -0
- package/dist/esm/pdf-reader/vector.d.ts +19 -0
- package/dist/esm/pdf-reader/vector.js +9 -0
- package/dist/esm/pptx/placeholder-cascade.d.ts +21 -0
- package/dist/esm/pptx/placeholder-cascade.js +10 -0
- package/dist/esm/pptx/ppt/ppt-reader.d.ts +16 -0
- package/dist/esm/pptx/ppt/ppt-reader.js +16 -0
- package/dist/esm/pptx/ppt/ppt-text.d.ts +55 -0
- package/dist/esm/pptx/ppt/ppt-text.js +14 -0
- package/dist/esm/pptx/pptx-reader.d.ts +21 -0
- package/dist/esm/pptx/pptx-reader.js +23 -2
- package/dist/esm/pptx/slide-parser.d.ts +102 -0
- package/dist/esm/pptx/slide-parser.js +78 -0
- package/dist/esm/pptx/sp-helpers.d.ts +28 -0
- package/dist/esm/pptx/sp-helpers.js +22 -0
- package/dist/esm/svg/svg-writer.d.ts +17 -0
- package/dist/esm/svg/svg-writer.js +16 -0
- package/dist/esm/word/doc/doc-reader.d.ts +16 -0
- package/dist/esm/word/doc/doc-reader.js +16 -0
- package/dist/esm/word/doc/doc-text.d.ts +77 -0
- package/dist/esm/word/doc/doc-text.js +13 -0
- package/dist/esm/word/document-parser.d.ts +134 -0
- package/dist/esm/word/document-parser.js +86 -0
- package/dist/esm/word/docx-reader.d.ts +16 -0
- package/dist/esm/word/docx-reader.js +18 -2
- package/dist/esm/word/docx-to-pdf.d.ts +52 -0
- package/dist/esm/word/docx-to-pdf.js +21 -0
- package/dist/esm/word/docx-writer.d.ts +17 -0
- package/dist/esm/word/docx-writer.js +17 -0
- package/dist/esm/word/drawing-parser.d.ts +88 -0
- package/dist/esm/word/drawing-parser.js +68 -0
- package/dist/esm/word/font-table.d.ts +24 -0
- package/dist/esm/word/font-table.js +24 -0
- package/dist/esm/word/numbering-parser.d.ts +11 -0
- package/dist/esm/word/numbering-parser.js +11 -0
- package/dist/esm/word/omml-parser.d.ts +15 -0
- package/dist/esm/word/omml-parser.js +15 -0
- package/dist/esm/word/omml-serializer.d.ts +9 -0
- package/dist/esm/word/omml-serializer.js +9 -0
- package/dist/esm/word/paragraph-properties.d.ts +10 -0
- package/dist/esm/word/paragraph-properties.js +10 -0
- package/dist/esm/word/po-to-flat.d.ts +11 -0
- package/dist/esm/word/po-to-flat.js +11 -0
- package/dist/esm/word/run-properties.d.ts +10 -0
- package/dist/esm/word/run-properties.js +10 -0
- package/dist/esm/word/settings-parser.d.ts +13 -0
- package/dist/esm/word/settings-parser.js +8 -0
- package/dist/esm/word/styles-parser.d.ts +10 -0
- package/dist/esm/word/styles-parser.js +10 -0
- package/dist/esm/word/table-parser.d.ts +11 -0
- package/dist/esm/word/table-parser.js +11 -0
- package/dist/esm/word/text-extractor.d.ts +9 -0
- package/dist/esm/word/xml-helpers.d.ts +44 -0
- package/dist/esm/word/xml-helpers.js +38 -0
- package/package.json +5 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PdfValue } from './objects.js';
|
|
2
|
+
/** The user-access permission flags (`/P`, §7.6.4.4.7); each defaults to allowed. */
|
|
2
3
|
export interface PdfPermissions {
|
|
3
4
|
/** Bit 3 — print the document (default true). */
|
|
4
5
|
readonly printing?: boolean;
|
|
@@ -15,6 +16,7 @@ export interface PdfPermissions {
|
|
|
15
16
|
/** Bit 11 — assemble (insert/rotate/delete pages) (default true). */
|
|
16
17
|
readonly documentAssembly?: boolean;
|
|
17
18
|
}
|
|
19
|
+
/** Passwords and permissions for {@link preparePdfEncryption}. */
|
|
18
20
|
export interface PdfEncryptOptions {
|
|
19
21
|
/** Required to OPEN the document. Empty string = opens without a prompt. */
|
|
20
22
|
readonly userPassword?: string;
|
|
@@ -22,13 +24,70 @@ export interface PdfEncryptOptions {
|
|
|
22
24
|
readonly ownerPassword?: string;
|
|
23
25
|
readonly permissions?: PdfPermissions;
|
|
24
26
|
}
|
|
27
|
+
/** The output of {@link preparePdfEncryption}: the file key plus the `/Encrypt` dictionary. */
|
|
25
28
|
export interface PreparedEncryption {
|
|
29
|
+
/** 32-byte file encryption key (FEK) — encrypts every string/stream. */
|
|
26
30
|
readonly fileKey: Uint8Array;
|
|
27
31
|
readonly encryptDict: PdfValue;
|
|
28
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Compute the `/P` permission integer (§7.6.4.4.7) from the high-level flags:
|
|
35
|
+
* bits 1–2 are reserved 0 and undefined bits are 1, so all-permissions is
|
|
36
|
+
* `0xFFFFFFFC` (-4 as int32); each disabled flag clears its bit.
|
|
37
|
+
*
|
|
38
|
+
* @param p The permission flags, or `undefined` for all-allowed.
|
|
39
|
+
* @returns The signed 32-bit `/P` value.
|
|
40
|
+
*/
|
|
29
41
|
export declare function permissionBits(p: PdfPermissions | undefined): number;
|
|
42
|
+
/**
|
|
43
|
+
* AES-CBC decryption without padding, the inverse of the internal no-pad
|
|
44
|
+
* encrypt. Appends a crafted padding block so WebCrypto's PKCS7 unpad succeeds
|
|
45
|
+
* and returns exactly `data.length` plain bytes.
|
|
46
|
+
*
|
|
47
|
+
* @param key The 16-byte AES key.
|
|
48
|
+
* @param iv The initialization vector.
|
|
49
|
+
* @param data The ciphertext (a 16-byte multiple).
|
|
50
|
+
* @returns The decrypted bytes.
|
|
51
|
+
*/
|
|
30
52
|
export declare function aesCbcNoPadDecrypt(key: Uint8Array, iv: Uint8Array, data: Uint8Array): Promise<Uint8Array>;
|
|
53
|
+
/**
|
|
54
|
+
* The iterated hash hardening of Algorithm 2.B (§7.6.4.3.4): SHA-256/384/512
|
|
55
|
+
* rounds interleaved with AES-CBC, run to the spec's stopping condition.
|
|
56
|
+
*
|
|
57
|
+
* @param password The (truncated) password bytes.
|
|
58
|
+
* @param salt The validation or key salt.
|
|
59
|
+
* @param userData Additional hash input (the 48-byte `/U` for owner derivation,
|
|
60
|
+
* empty otherwise).
|
|
61
|
+
* @returns The derived 32-byte key.
|
|
62
|
+
*/
|
|
31
63
|
export declare function hardHash(password: Uint8Array, salt: Uint8Array, userData: Uint8Array): Promise<Uint8Array>;
|
|
64
|
+
/**
|
|
65
|
+
* Build the V5/R6 (AES-256) Standard-security-handler `/Encrypt` dictionary:
|
|
66
|
+
* derive `/U`, `/UE`, `/O`, `/OE` and `/Perms` (§7.6.4.4.8–.10, Algorithms
|
|
67
|
+
* 8–10) for a freshly-generated random file encryption key.
|
|
68
|
+
*
|
|
69
|
+
* @param options The passwords and permissions.
|
|
70
|
+
* @returns The file key and the `/Encrypt` dictionary ({@link PreparedEncryption}).
|
|
71
|
+
*/
|
|
32
72
|
export declare function preparePdfEncryption(options: PdfEncryptOptions): Promise<PreparedEncryption>;
|
|
73
|
+
/**
|
|
74
|
+
* Decrypt AESV3 content (§7.6.3.3): split the leading 16-byte IV and
|
|
75
|
+
* AES-256-CBC-decrypt the remainder.
|
|
76
|
+
*
|
|
77
|
+
* @param fileKey The 32-byte file encryption key.
|
|
78
|
+
* @param data The `IV ‖ ciphertext` bytes.
|
|
79
|
+
* @returns The decrypted plaintext.
|
|
80
|
+
*/
|
|
33
81
|
export declare function decryptBytes(fileKey: Uint8Array, data: Uint8Array): Promise<Uint8Array>;
|
|
82
|
+
/**
|
|
83
|
+
* Recursively encrypt every string and stream in an object graph (AESV3). The
|
|
84
|
+
* `/Encrypt` dictionary itself is added AFTER this pass and never encrypted, and
|
|
85
|
+
* trailer `/ID` strings live outside the body. Strings come back as hex strings,
|
|
86
|
+
* since the cipher bytes are binary; numbers, booleans, names, refs, null and
|
|
87
|
+
* raw tokens pass through unchanged.
|
|
88
|
+
*
|
|
89
|
+
* @param value The value to walk.
|
|
90
|
+
* @param fileKey The 32-byte file encryption key.
|
|
91
|
+
* @returns The value with its strings/streams replaced by their ciphertext.
|
|
92
|
+
*/
|
|
34
93
|
export declare function encryptObjectGraph(value: PdfValue, fileKey: Uint8Array): Promise<PdfValue>;
|
|
@@ -2,6 +2,14 @@ import { PdfHexString, PdfStream, dict, name } from "./objects.js";
|
|
|
2
2
|
//#region src/pdf/encryption.ts
|
|
3
3
|
var encoder = new TextEncoder();
|
|
4
4
|
var subtle = globalThis.crypto.subtle;
|
|
5
|
+
/**
|
|
6
|
+
* Compute the `/P` permission integer (§7.6.4.4.7) from the high-level flags:
|
|
7
|
+
* bits 1–2 are reserved 0 and undefined bits are 1, so all-permissions is
|
|
8
|
+
* `0xFFFFFFFC` (-4 as int32); each disabled flag clears its bit.
|
|
9
|
+
*
|
|
10
|
+
* @param p The permission flags, or `undefined` for all-allowed.
|
|
11
|
+
* @returns The signed 32-bit `/P` value.
|
|
12
|
+
*/
|
|
5
13
|
function permissionBits(p) {
|
|
6
14
|
let bits = -4;
|
|
7
15
|
const off = (bit) => bits &= ~(1 << bit - 1);
|
|
@@ -39,6 +47,16 @@ async function aesCbcNoPad(key, iv, data) {
|
|
|
39
47
|
iv
|
|
40
48
|
}, k, data)).slice(0, data.length);
|
|
41
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* The iterated hash hardening of Algorithm 2.B (§7.6.4.3.4): SHA-256/384/512
|
|
52
|
+
* rounds interleaved with AES-CBC, run to the spec's stopping condition.
|
|
53
|
+
*
|
|
54
|
+
* @param password The (truncated) password bytes.
|
|
55
|
+
* @param salt The validation or key salt.
|
|
56
|
+
* @param userData Additional hash input (the 48-byte `/U` for owner derivation,
|
|
57
|
+
* empty otherwise).
|
|
58
|
+
* @returns The derived 32-byte key.
|
|
59
|
+
*/
|
|
42
60
|
async function hardHash(password, salt, userData) {
|
|
43
61
|
let k = await sha("SHA-256", concat(password, salt, userData));
|
|
44
62
|
for (let round = 0;; round++) {
|
|
@@ -53,6 +71,14 @@ async function hardHash(password, salt, userData) {
|
|
|
53
71
|
}
|
|
54
72
|
return k.slice(0, 32);
|
|
55
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Build the V5/R6 (AES-256) Standard-security-handler `/Encrypt` dictionary:
|
|
76
|
+
* derive `/U`, `/UE`, `/O`, `/OE` and `/Perms` (§7.6.4.4.8–.10, Algorithms
|
|
77
|
+
* 8–10) for a freshly-generated random file encryption key.
|
|
78
|
+
*
|
|
79
|
+
* @param options The passwords and permissions.
|
|
80
|
+
* @returns The file key and the `/Encrypt` dictionary ({@link PreparedEncryption}).
|
|
81
|
+
*/
|
|
56
82
|
async function preparePdfEncryption(options) {
|
|
57
83
|
const user = passwordBytes(options.userPassword ?? "");
|
|
58
84
|
const owner = passwordBytes(options.ownerPassword ?? options.userPassword ?? "");
|
|
@@ -118,6 +144,17 @@ async function encryptBytes(fileKey, data) {
|
|
|
118
144
|
iv
|
|
119
145
|
}, k, data)));
|
|
120
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Recursively encrypt every string and stream in an object graph (AESV3). The
|
|
149
|
+
* `/Encrypt` dictionary itself is added AFTER this pass and never encrypted, and
|
|
150
|
+
* trailer `/ID` strings live outside the body. Strings come back as hex strings,
|
|
151
|
+
* since the cipher bytes are binary; numbers, booleans, names, refs, null and
|
|
152
|
+
* raw tokens pass through unchanged.
|
|
153
|
+
*
|
|
154
|
+
* @param value The value to walk.
|
|
155
|
+
* @param fileKey The 32-byte file encryption key.
|
|
156
|
+
* @returns The value with its strings/streams replaced by their ciphertext.
|
|
157
|
+
*/
|
|
121
158
|
async function encryptObjectGraph(value, fileKey) {
|
|
122
159
|
if (typeof value === "string") return new PdfHexString(await encryptBytes(fileKey, encoder.encode(value)));
|
|
123
160
|
if (value instanceof PdfHexString) return new PdfHexString(await encryptBytes(fileKey, value.bytes));
|
|
@@ -1 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synthesise a minimal valid ICC v2 matrix/TRC RGB display profile from scratch
|
|
3
|
+
* (no external `.icc` asset), for use as a PDF/A-1b `OutputIntent`'s
|
|
4
|
+
* `DestOutputProfile`. Colorimetrically "sRGB-ish"; PDF/A validators check
|
|
5
|
+
* structural validity (version, class, required tags) rather than exact colour.
|
|
6
|
+
*
|
|
7
|
+
* @returns The encoded ICC profile bytes.
|
|
8
|
+
*/
|
|
1
9
|
export declare function buildSrgbIccProfile(): Uint8Array;
|
|
@@ -74,6 +74,14 @@ function buildCurveGamma(gamma) {
|
|
|
74
74
|
function align4(n) {
|
|
75
75
|
return n + 3 & -4;
|
|
76
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Synthesise a minimal valid ICC v2 matrix/TRC RGB display profile from scratch
|
|
79
|
+
* (no external `.icc` asset), for use as a PDF/A-1b `OutputIntent`'s
|
|
80
|
+
* `DestOutputProfile`. Colorimetrically "sRGB-ish"; PDF/A validators check
|
|
81
|
+
* structural validity (version, class, required tags) rather than exact colour.
|
|
82
|
+
*
|
|
83
|
+
* @returns The encoded ICC profile bytes.
|
|
84
|
+
*/
|
|
77
85
|
function buildSrgbIccProfile() {
|
|
78
86
|
const desc = buildTextDescription(DESC);
|
|
79
87
|
const wtpt = buildXYZ(D50.x, D50.y, D50.z);
|
|
@@ -3,10 +3,29 @@ import { PdfDocument } from './writer.js';
|
|
|
3
3
|
import { EmbedImageOptions, PreparedImage } from '../core/images.js';
|
|
4
4
|
export { detectImageFormat, prepareImage } from '../core/images.js';
|
|
5
5
|
export type { EmbedImageOptions, ImageFormat, PreparedImage } from '../core/images.js';
|
|
6
|
+
/** A reference to an embedded image XObject plus its pixel dimensions. */
|
|
6
7
|
export interface EmbeddedImage {
|
|
8
|
+
/** Indirect reference to the image XObject, for a page's `/XObject` resources. */
|
|
7
9
|
readonly ref: PdfRef;
|
|
8
10
|
readonly widthPx: number;
|
|
9
11
|
readonly heightPx: number;
|
|
10
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Create the PDF image-XObject objects from an already-prepared image (ISO
|
|
15
|
+
* 32000-1 §8.9.5), emitting an `/SMask` soft-mask object first when present.
|
|
16
|
+
* The decode/validate work happens earlier in `prepareImage`; this only writes
|
|
17
|
+
* the objects.
|
|
18
|
+
*
|
|
19
|
+
* @param prepared The decoded, ready-to-emit image stream.
|
|
20
|
+
* @returns The image reference and its pixel dimensions.
|
|
21
|
+
*/
|
|
11
22
|
export declare function addImage(doc: PdfDocument, prepared: PreparedImage): EmbeddedImage;
|
|
23
|
+
/**
|
|
24
|
+
* Decode raw image `bytes` and embed them in one step — a convenience over
|
|
25
|
+
* `prepareImage` + {@link addImage}.
|
|
26
|
+
*
|
|
27
|
+
* @param bytes The raw image file bytes (PNG/JPEG/…).
|
|
28
|
+
* @param options Decode/embed options.
|
|
29
|
+
* @returns The image reference and its pixel dimensions.
|
|
30
|
+
*/
|
|
12
31
|
export declare function embedImage(doc: PdfDocument, bytes: Uint8Array, options?: EmbedImageOptions): EmbeddedImage;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { name, stream } from "./objects.js";
|
|
2
2
|
import "../core/images.js";
|
|
3
3
|
//#region src/pdf/image-xobject.ts
|
|
4
|
+
/**
|
|
5
|
+
* Create the PDF image-XObject objects from an already-prepared image (ISO
|
|
6
|
+
* 32000-1 §8.9.5), emitting an `/SMask` soft-mask object first when present.
|
|
7
|
+
* The decode/validate work happens earlier in `prepareImage`; this only writes
|
|
8
|
+
* the objects.
|
|
9
|
+
*
|
|
10
|
+
* @param prepared The decoded, ready-to-emit image stream.
|
|
11
|
+
* @returns The image reference and its pixel dimensions.
|
|
12
|
+
*/
|
|
4
13
|
function addImage(doc, prepared) {
|
|
5
14
|
let smaskRef;
|
|
6
15
|
if (prepared.smaskData) smaskRef = doc.add(stream({
|
|
@@ -1,32 +1,72 @@
|
|
|
1
|
+
/** The PDF `null` object (§7.3.9), modelled as a unique symbol. */
|
|
1
2
|
export declare const PDF_NULL: unique symbol;
|
|
3
|
+
/** The type of the PDF `null` object, {@link PDF_NULL}. */
|
|
2
4
|
export type PdfNull = typeof PDF_NULL;
|
|
5
|
+
/** A PDF name object (§7.3.5), e.g. `/Type` — the leading slash is added on serialization. */
|
|
3
6
|
export declare class PdfName {
|
|
4
7
|
readonly value: string;
|
|
8
|
+
/** @param value The name's text, without the leading `/`. */
|
|
5
9
|
constructor(value: string);
|
|
6
10
|
}
|
|
11
|
+
/** An indirect reference (§7.3.10), written `id gen R`. */
|
|
7
12
|
export declare class PdfRef {
|
|
8
13
|
readonly id: number;
|
|
9
14
|
readonly generation: number;
|
|
15
|
+
/**
|
|
16
|
+
* @param id The referenced object number.
|
|
17
|
+
* @param generation The generation number (0 for freshly written objects).
|
|
18
|
+
*/
|
|
10
19
|
constructor(id: number, generation?: number);
|
|
11
20
|
}
|
|
21
|
+
/** A PDF stream object (§7.3.8): a dictionary plus its raw byte payload. */
|
|
12
22
|
export declare class PdfStream {
|
|
13
23
|
readonly dict: PdfDict;
|
|
14
24
|
readonly data: Uint8Array;
|
|
25
|
+
/**
|
|
26
|
+
* @param dict The stream dictionary (`/Length` is filled in on serialization).
|
|
27
|
+
* @param data The raw stream bytes.
|
|
28
|
+
*/
|
|
15
29
|
constructor(dict: PdfDict, data: Uint8Array);
|
|
16
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* A PDF hex string (§7.3.4.3), written as `<HEXBYTES>` and decoding to raw
|
|
33
|
+
* bytes. Used for `/Info` entries containing non-ASCII text: the bytes are
|
|
34
|
+
* UTF-16BE with a leading BOM, the PDF-standard form for Unicode strings.
|
|
35
|
+
*/
|
|
17
36
|
export declare class PdfHexString {
|
|
18
37
|
readonly bytes: Uint8Array;
|
|
38
|
+
/** @param bytes The raw bytes to emit as hex. */
|
|
19
39
|
constructor(bytes: Uint8Array);
|
|
20
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* A verbatim token emitted exactly as given — no escaping, no quoting. Used for
|
|
43
|
+
* the signature `/ByteRange` placeholder, a fixed-width array overwritten in
|
|
44
|
+
* place after the byte offsets are known (ISO 32000 §12.8.1).
|
|
45
|
+
*/
|
|
21
46
|
export declare class PdfRawToken {
|
|
22
47
|
readonly token: string;
|
|
48
|
+
/** @param token The literal text to emit unchanged. */
|
|
23
49
|
constructor(token: string);
|
|
24
50
|
}
|
|
51
|
+
/** A PDF dictionary (§7.3.7): an ordered map from name keys to {@link PdfValue}s. */
|
|
25
52
|
export type PdfDict = Map<string, PdfValue>;
|
|
53
|
+
/** A PDF array (§7.3.6) of {@link PdfValue}s. */
|
|
26
54
|
export type PdfArray = Array<PdfValue>;
|
|
55
|
+
/** Any PDF object value (§7.3): the union of all the primitive and composite object types. */
|
|
27
56
|
export type PdfValue = PdfNull | boolean | number | string | PdfName | PdfHexString | PdfRawToken | PdfArray | PdfDict | PdfRef | PdfStream;
|
|
57
|
+
/** Construct a {@link PdfName} from its text (without the leading `/`). */
|
|
28
58
|
export declare const name: (v: string) => PdfName;
|
|
59
|
+
/** Construct a {@link PdfRef} to object `id` at generation `gen` (default 0). */
|
|
29
60
|
export declare const ref: (id: number, gen?: number) => PdfRef;
|
|
61
|
+
/** Construct a {@link PdfDict} from a plain object of name → value entries. */
|
|
30
62
|
export declare const dict: (entries: Record<string, PdfValue>) => PdfDict;
|
|
63
|
+
/** Construct a {@link PdfStream} from a dictionary literal plus its byte payload. */
|
|
31
64
|
export declare const stream: (entries: Record<string, PdfValue>, data: Uint8Array) => PdfStream;
|
|
65
|
+
/**
|
|
66
|
+
* Build a PDF Unicode string (UTF-16BE with BOM) suitable for `/Info` or
|
|
67
|
+
* document-level text metadata. Accepts arbitrary Unicode input.
|
|
68
|
+
*
|
|
69
|
+
* @param s The text to encode.
|
|
70
|
+
* @returns A {@link PdfHexString} holding the BOM-prefixed UTF-16BE bytes.
|
|
71
|
+
*/
|
|
32
72
|
export declare const unicodeString: (s: string) => PdfHexString;
|
package/dist/esm/pdf/objects.js
CHANGED
|
@@ -1,36 +1,72 @@
|
|
|
1
1
|
//#region src/pdf/objects.ts
|
|
2
|
+
/** The PDF `null` object (§7.3.9), modelled as a unique symbol. */
|
|
2
3
|
var PDF_NULL = Symbol("PDF_NULL");
|
|
4
|
+
/** A PDF name object (§7.3.5), e.g. `/Type` — the leading slash is added on serialization. */
|
|
3
5
|
var PdfName = class {
|
|
6
|
+
/** @param value The name's text, without the leading `/`. */
|
|
4
7
|
constructor(value) {
|
|
5
8
|
this.value = value;
|
|
6
9
|
}
|
|
7
10
|
};
|
|
11
|
+
/** An indirect reference (§7.3.10), written `id gen R`. */
|
|
8
12
|
var PdfRef = class {
|
|
13
|
+
/**
|
|
14
|
+
* @param id The referenced object number.
|
|
15
|
+
* @param generation The generation number (0 for freshly written objects).
|
|
16
|
+
*/
|
|
9
17
|
constructor(id, generation = 0) {
|
|
10
18
|
this.id = id;
|
|
11
19
|
this.generation = generation;
|
|
12
20
|
}
|
|
13
21
|
};
|
|
22
|
+
/** A PDF stream object (§7.3.8): a dictionary plus its raw byte payload. */
|
|
14
23
|
var PdfStream = class {
|
|
24
|
+
/**
|
|
25
|
+
* @param dict The stream dictionary (`/Length` is filled in on serialization).
|
|
26
|
+
* @param data The raw stream bytes.
|
|
27
|
+
*/
|
|
15
28
|
constructor(dict, data) {
|
|
16
29
|
this.dict = dict;
|
|
17
30
|
this.data = data;
|
|
18
31
|
}
|
|
19
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* A PDF hex string (§7.3.4.3), written as `<HEXBYTES>` and decoding to raw
|
|
35
|
+
* bytes. Used for `/Info` entries containing non-ASCII text: the bytes are
|
|
36
|
+
* UTF-16BE with a leading BOM, the PDF-standard form for Unicode strings.
|
|
37
|
+
*/
|
|
20
38
|
var PdfHexString = class {
|
|
39
|
+
/** @param bytes The raw bytes to emit as hex. */
|
|
21
40
|
constructor(bytes) {
|
|
22
41
|
this.bytes = bytes;
|
|
23
42
|
}
|
|
24
43
|
};
|
|
44
|
+
/**
|
|
45
|
+
* A verbatim token emitted exactly as given — no escaping, no quoting. Used for
|
|
46
|
+
* the signature `/ByteRange` placeholder, a fixed-width array overwritten in
|
|
47
|
+
* place after the byte offsets are known (ISO 32000 §12.8.1).
|
|
48
|
+
*/
|
|
25
49
|
var PdfRawToken = class {
|
|
50
|
+
/** @param token The literal text to emit unchanged. */
|
|
26
51
|
constructor(token) {
|
|
27
52
|
this.token = token;
|
|
28
53
|
}
|
|
29
54
|
};
|
|
55
|
+
/** Construct a {@link PdfName} from its text (without the leading `/`). */
|
|
30
56
|
var name = (v) => new PdfName(v);
|
|
57
|
+
/** Construct a {@link PdfRef} to object `id` at generation `gen` (default 0). */
|
|
31
58
|
var ref = (id, gen = 0) => new PdfRef(id, gen);
|
|
59
|
+
/** Construct a {@link PdfDict} from a plain object of name → value entries. */
|
|
32
60
|
var dict = (entries) => new Map(Object.entries(entries));
|
|
61
|
+
/** Construct a {@link PdfStream} from a dictionary literal plus its byte payload. */
|
|
33
62
|
var stream = (entries, data) => new PdfStream(dict(entries), data);
|
|
63
|
+
/**
|
|
64
|
+
* Build a PDF Unicode string (UTF-16BE with BOM) suitable for `/Info` or
|
|
65
|
+
* document-level text metadata. Accepts arbitrary Unicode input.
|
|
66
|
+
*
|
|
67
|
+
* @param s The text to encode.
|
|
68
|
+
* @returns A {@link PdfHexString} holding the BOM-prefixed UTF-16BE bytes.
|
|
69
|
+
*/
|
|
34
70
|
var unicodeString = (s) => {
|
|
35
71
|
const codepoints = [];
|
|
36
72
|
for (const ch of s) codepoints.push(ch.codePointAt(0));
|
|
@@ -1,3 +1,21 @@
|
|
|
1
1
|
import { PdfValue } from './objects.js';
|
|
2
|
+
/**
|
|
3
|
+
* Serialize a single PDF value to its textual representation (ISO 32000-1 §7.3).
|
|
4
|
+
*
|
|
5
|
+
* @param v The value to serialize.
|
|
6
|
+
* @returns The serialized string.
|
|
7
|
+
* @throws Error on a non-finite number, or a {@link PdfStream} (which must be an
|
|
8
|
+
* indirect object, not inlined).
|
|
9
|
+
*/
|
|
2
10
|
export declare function serializeValue(v: PdfValue): string;
|
|
11
|
+
/**
|
|
12
|
+
* Serialize a value as a complete `id gen obj … endobj` indirect object
|
|
13
|
+
* (§7.3.10). Streams are emitted with their raw payload; everything else is
|
|
14
|
+
* inlined via {@link serializeValue}.
|
|
15
|
+
*
|
|
16
|
+
* @param id The object number.
|
|
17
|
+
* @param generation The generation number.
|
|
18
|
+
* @param value The object value.
|
|
19
|
+
* @returns The encoded indirect-object bytes.
|
|
20
|
+
*/
|
|
3
21
|
export declare function serializeIndirectObject(id: number, generation: number, value: PdfValue): Uint8Array;
|
|
@@ -8,6 +8,14 @@ var formatNumber = (n) => {
|
|
|
8
8
|
if (Number.isInteger(n)) return String(n);
|
|
9
9
|
return n.toFixed(6).replace(/0+$/, "").replace(/\.$/, "");
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Serialize a single PDF value to its textual representation (ISO 32000-1 §7.3).
|
|
13
|
+
*
|
|
14
|
+
* @param v The value to serialize.
|
|
15
|
+
* @returns The serialized string.
|
|
16
|
+
* @throws Error on a non-finite number, or a {@link PdfStream} (which must be an
|
|
17
|
+
* indirect object, not inlined).
|
|
18
|
+
*/
|
|
11
19
|
function serializeValue(v) {
|
|
12
20
|
if (v === PDF_NULL) return "null";
|
|
13
21
|
if (typeof v === "boolean") return v ? "true" : "false";
|
|
@@ -34,6 +42,16 @@ function serializeDict(d) {
|
|
|
34
42
|
for (const [k, v] of d) entries.push(`/${escapeName(k)} ${serializeValue(v)}`);
|
|
35
43
|
return `<<${entries.join(" ")}>>`;
|
|
36
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Serialize a value as a complete `id gen obj … endobj` indirect object
|
|
47
|
+
* (§7.3.10). Streams are emitted with their raw payload; everything else is
|
|
48
|
+
* inlined via {@link serializeValue}.
|
|
49
|
+
*
|
|
50
|
+
* @param id The object number.
|
|
51
|
+
* @param generation The generation number.
|
|
52
|
+
* @param value The object value.
|
|
53
|
+
* @returns The encoded indirect-object bytes.
|
|
54
|
+
*/
|
|
37
55
|
function serializeIndirectObject(id, generation, value) {
|
|
38
56
|
if (value instanceof PdfStream) return serializeStreamObject(id, generation, value);
|
|
39
57
|
const body = `${id} ${generation} obj\n${serializeValue(value)}\nendobj\n`;
|
|
@@ -7,6 +7,22 @@ interface Bbox {
|
|
|
7
7
|
readonly maxX: number;
|
|
8
8
|
readonly maxY: number;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* The local-space bounding box of a shape's paths (y-up).
|
|
12
|
+
*
|
|
13
|
+
* @returns The bounding box, or `undefined` for an empty/degenerate shape (where
|
|
14
|
+
* no gradient can be placed).
|
|
15
|
+
*/
|
|
10
16
|
export declare function shapeBbox(shape: VectorShape): Bbox | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Build the PatternType-2 shading pattern object (axial or radial) for a
|
|
19
|
+
* DrawingML gradient (EP16b) and add it to `doc`. The pattern's `/Matrix` is the
|
|
20
|
+
* shape's CTM and the shading `/Coords` are in the shape's local space.
|
|
21
|
+
*
|
|
22
|
+
* @param gradient The gradient fill (kind, angle, colour stops).
|
|
23
|
+
* @param bbox The shape's local-space bounding box, from {@link shapeBbox}.
|
|
24
|
+
* @param ctm The shape's current transformation matrix, used as `/Matrix`.
|
|
25
|
+
* @returns A reference to the `/Pattern` object, for a `/Pattern cs /Pn scn` fill.
|
|
26
|
+
*/
|
|
11
27
|
export declare function buildGradientPattern(doc: PdfDocument, gradient: ShapeGradient, bbox: Bbox, ctm: readonly [number, number, number, number, number, number]): PdfRef;
|
|
12
28
|
export {};
|
package/dist/esm/pdf/shading.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { dict, name, ref } from "./objects.js";
|
|
2
2
|
//#region src/pdf/shading.ts
|
|
3
|
+
/**
|
|
4
|
+
* The local-space bounding box of a shape's paths (y-up).
|
|
5
|
+
*
|
|
6
|
+
* @returns The bounding box, or `undefined` for an empty/degenerate shape (where
|
|
7
|
+
* no gradient can be placed).
|
|
8
|
+
*/
|
|
3
9
|
function shapeBbox(shape) {
|
|
4
10
|
let minX = Infinity;
|
|
5
11
|
let minY = Infinity;
|
|
@@ -24,6 +30,16 @@ function shapeBbox(shape) {
|
|
|
24
30
|
maxY
|
|
25
31
|
} : void 0;
|
|
26
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Build the PatternType-2 shading pattern object (axial or radial) for a
|
|
35
|
+
* DrawingML gradient (EP16b) and add it to `doc`. The pattern's `/Matrix` is the
|
|
36
|
+
* shape's CTM and the shading `/Coords` are in the shape's local space.
|
|
37
|
+
*
|
|
38
|
+
* @param gradient The gradient fill (kind, angle, colour stops).
|
|
39
|
+
* @param bbox The shape's local-space bounding box, from {@link shapeBbox}.
|
|
40
|
+
* @param ctm The shape's current transformation matrix, used as `/Matrix`.
|
|
41
|
+
* @returns A reference to the `/Pattern` object, for a `/Pattern cs /Pn scn` fill.
|
|
42
|
+
*/
|
|
27
43
|
function buildGradientPattern(doc, gradient, bbox, ctm) {
|
|
28
44
|
const fnRef = doc.add(buildRamp(gradient.stops));
|
|
29
45
|
const shading = gradient.kind === "radial" ? radialShading(bbox, fnRef) : axialShading(gradient.angle ?? 0, bbox, fnRef);
|
|
@@ -1,25 +1,61 @@
|
|
|
1
1
|
import { PdfDict, PdfRef } from './objects.js';
|
|
2
2
|
import { PdfDocument } from './writer.js';
|
|
3
|
+
/** The signature-dictionary metadata stamped at placeholder time by {@link addSignaturePlaceholder}. */
|
|
3
4
|
export interface SignaturePlaceholder {
|
|
4
5
|
readonly reason?: string;
|
|
5
6
|
readonly location?: string;
|
|
7
|
+
/** Signer name recorded in the dictionary (`/Name`). */
|
|
6
8
|
readonly name?: string;
|
|
7
9
|
readonly contactInfo?: string;
|
|
10
|
+
/** Claimed signing time (→ `/M` and the CMS `signingTime` attribute). */
|
|
8
11
|
readonly signingTime?: Date;
|
|
12
|
+
/** Signature field name (default `"Signature1"`). */
|
|
9
13
|
readonly fieldName?: string;
|
|
14
|
+
/** Bytes reserved for the `/Contents` signature hole (default 8192). */
|
|
10
15
|
readonly reserveBytes?: number;
|
|
11
16
|
}
|
|
17
|
+
/** The signing key material consumed by {@link signPdf}. */
|
|
12
18
|
export interface SignerCredentials {
|
|
19
|
+
/** Signer's X.509 certificate (DER). */
|
|
13
20
|
readonly certificate: Uint8Array;
|
|
21
|
+
/**
|
|
22
|
+
* WebCrypto private key. An RSASSA-PKCS1-v1_5 key (default) or — when
|
|
23
|
+
* `algorithm` is `'ecdsa'` — an ECDSA key (P-256/P-384/P-521).
|
|
24
|
+
*/
|
|
14
25
|
readonly privateKey: CryptoKey;
|
|
26
|
+
/** Signature algorithm of the key (default `'rsa'`). */
|
|
15
27
|
readonly algorithm?: 'rsa' | 'ecdsa';
|
|
28
|
+
/** Optional chain certificates (DER) to embed alongside the signer cert. */
|
|
16
29
|
readonly extraCertificates?: ReadonlyArray<Uint8Array>;
|
|
17
30
|
readonly signingTime?: Date;
|
|
18
31
|
}
|
|
32
|
+
/** Converter convenience: everything needed to emit a placeholder and sign in one call. */
|
|
19
33
|
export interface SignatureOptions extends SignaturePlaceholder, SignerCredentials {
|
|
20
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Add an (invisible) signature field plus its signature dictionary to a document
|
|
37
|
+
* being built (§12.8). The dictionary carries placeholder `/ByteRange` and
|
|
38
|
+
* `/Contents` that {@link signPdf} fills later.
|
|
39
|
+
*
|
|
40
|
+
* @param ph The signature metadata and reserved-bytes size.
|
|
41
|
+
* @param pageRef The page the (zero-size) widget annotation belongs to.
|
|
42
|
+
* @returns The field ref (attach to the page's `/Annots`) and the `/AcroForm`
|
|
43
|
+
* dictionary (attach to the catalog).
|
|
44
|
+
*/
|
|
21
45
|
export declare function addSignaturePlaceholder(doc: PdfDocument, ph: SignaturePlaceholder, pageRef: PdfRef): {
|
|
22
46
|
readonly fieldRef: PdfRef;
|
|
23
47
|
readonly acroForm: PdfDict;
|
|
24
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Sign a PDF that already carries a signature placeholder (from
|
|
51
|
+
* {@link addSignaturePlaceholder}). Computes the real `/ByteRange`, hashes the
|
|
52
|
+
* covered bytes (SHA-256), builds the detached PKCS#7/CMS, and writes it into
|
|
53
|
+
* the reserved `/Contents` hole — leaving every other byte untouched.
|
|
54
|
+
*
|
|
55
|
+
* @param pdf The placeholder-bearing PDF bytes.
|
|
56
|
+
* @param cred The signer's certificate, key and algorithm.
|
|
57
|
+
* @returns A new byte array with the real ByteRange and signature spliced in.
|
|
58
|
+
* @throws Error when no placeholder is found, it is malformed, WebCrypto is
|
|
59
|
+
* unavailable, or the signature exceeds the reserved `/Contents` size.
|
|
60
|
+
*/
|
|
25
61
|
export declare function signPdf(pdf: Uint8Array, cred: SignerCredentials): Promise<Uint8Array>;
|
|
@@ -11,6 +11,16 @@ function pad2(n) {
|
|
|
11
11
|
function pdfDate(d) {
|
|
12
12
|
return `D:${d.getUTCFullYear()}${pad2(d.getUTCMonth() + 1)}${pad2(d.getUTCDate())}${pad2(d.getUTCHours())}${pad2(d.getUTCMinutes())}${pad2(d.getUTCSeconds())}+00'00'`;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Add an (invisible) signature field plus its signature dictionary to a document
|
|
16
|
+
* being built (§12.8). The dictionary carries placeholder `/ByteRange` and
|
|
17
|
+
* `/Contents` that {@link signPdf} fills later.
|
|
18
|
+
*
|
|
19
|
+
* @param ph The signature metadata and reserved-bytes size.
|
|
20
|
+
* @param pageRef The page the (zero-size) widget annotation belongs to.
|
|
21
|
+
* @returns The field ref (attach to the page's `/Annots`) and the `/AcroForm`
|
|
22
|
+
* dictionary (attach to the catalog).
|
|
23
|
+
*/
|
|
14
24
|
function addSignaturePlaceholder(doc, ph, pageRef) {
|
|
15
25
|
const reserve = ph.reserveBytes ?? DEFAULT_RESERVE_BYTES;
|
|
16
26
|
const sigEntries = {
|
|
@@ -78,6 +88,18 @@ function toHex(bytes) {
|
|
|
78
88
|
for (const b of bytes) s += HEX[b >> 4] + HEX[b & 15];
|
|
79
89
|
return s;
|
|
80
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Sign a PDF that already carries a signature placeholder (from
|
|
93
|
+
* {@link addSignaturePlaceholder}). Computes the real `/ByteRange`, hashes the
|
|
94
|
+
* covered bytes (SHA-256), builds the detached PKCS#7/CMS, and writes it into
|
|
95
|
+
* the reserved `/Contents` hole — leaving every other byte untouched.
|
|
96
|
+
*
|
|
97
|
+
* @param pdf The placeholder-bearing PDF bytes.
|
|
98
|
+
* @param cred The signer's certificate, key and algorithm.
|
|
99
|
+
* @returns A new byte array with the real ByteRange and signature spliced in.
|
|
100
|
+
* @throws Error when no placeholder is found, it is malformed, WebCrypto is
|
|
101
|
+
* unavailable, or the signature exceeds the reserved `/Contents` size.
|
|
102
|
+
*/
|
|
81
103
|
async function signPdf(pdf, cred) {
|
|
82
104
|
const out = pdf.slice();
|
|
83
105
|
const brKey = indexOfAscii(out, `/ByteRange ${BYTE_RANGE_PLACEHOLDER}`);
|