reamkit 1.15.1 → 1.15.2
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 +9 -0
- package/dist/esm/core/bytes.js +9 -0
- 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 +46 -0
- 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 +281 -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 +26 -0
- 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 +56 -0
- package/dist/esm/excel/print-model.js +43 -0
- 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 +19 -0
- package/dist/esm/excel/sheet-to-flow.js +10 -0
- 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 +9 -0
- 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 +26 -0
- package/dist/esm/excel/xlsx-reader.js +26 -0
- 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 +117 -2
- 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 +21 -0
- 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 +16 -0
- 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 +1 -1
|
@@ -1,37 +1,101 @@
|
|
|
1
1
|
import { PdfRef } from './objects.js';
|
|
2
2
|
import { PdfDocument } from './writer.js';
|
|
3
|
+
/**
|
|
4
|
+
* Standard structure types (ISO 32000-1 Table 333/337). Every type here is
|
|
5
|
+
* recognised without a `/RoleMap`, so the builder never emits one.
|
|
6
|
+
*/
|
|
3
7
|
export type StructType = 'Document' | 'Part' | 'Sect' | 'H1' | 'H2' | 'H3' | 'H4' | 'H5' | 'H6' | 'P' | 'L' | 'LI' | 'Lbl' | 'LBody' | 'Table' | 'TR' | 'TH' | 'TD' | 'Caption' | 'Figure' | 'Link' | 'Note' | 'Span';
|
|
4
8
|
interface Mcref {
|
|
5
9
|
readonly pageIndex: number;
|
|
6
10
|
readonly mcid: number;
|
|
7
11
|
}
|
|
12
|
+
/** One node in the logical structure tree: a {@link StructType} plus its children, marked-content and attributes. */
|
|
8
13
|
export declare class StructNode {
|
|
9
14
|
readonly id: number;
|
|
10
15
|
type: StructType;
|
|
11
16
|
readonly children: Array<StructNode>;
|
|
12
17
|
readonly mcrefs: Array<Mcref>;
|
|
18
|
+
/**
|
|
19
|
+
* §14.7.4.3 object references (`/OBJR` kids) — e.g. a Link element pointing at
|
|
20
|
+
* its link annotation. The annotation's own `/StructParent` entry is recorded
|
|
21
|
+
* via {@link StructTreeBuilder.addAnnotParent}.
|
|
22
|
+
*/
|
|
13
23
|
readonly objrs: Array<{
|
|
14
24
|
readonly annotRef: PdfRef;
|
|
15
25
|
readonly pageIndex: number;
|
|
16
26
|
}>;
|
|
17
27
|
parent: StructNode | null;
|
|
18
28
|
ref: PdfRef | null;
|
|
29
|
+
/** Alternate text (`/Alt`, §14.9.4) — required on Figure for PDF/A-1a. */
|
|
19
30
|
alt: string | null;
|
|
31
|
+
/** Natural language (`/Lang`) when it differs from the document default. */
|
|
20
32
|
lang: string | null;
|
|
33
|
+
/**
|
|
34
|
+
* §14.8.5.2 Table attribute (emitted via a `/A` attribute object on the cell):
|
|
35
|
+
* `/Scope` on a TH (Row/Column) so assistive tech binds headers to data cells.
|
|
36
|
+
*/
|
|
21
37
|
scope: 'Row' | 'Column' | null;
|
|
38
|
+
/** §14.8.5.2 — `/ColSpan` when the cell spans more than one column (gridSpan). */
|
|
22
39
|
colSpan: number | null;
|
|
40
|
+
/** §14.8.5.2 — `/RowSpan` when the cell spans more than one row (vertical merge). */
|
|
23
41
|
rowSpan: number | null;
|
|
42
|
+
/**
|
|
43
|
+
* @param id The node's index, used for deterministic id assignment and `/ID`.
|
|
44
|
+
* @param type The structure type (mutable, so the renderer can retag).
|
|
45
|
+
*/
|
|
24
46
|
constructor(id: number, type: StructType);
|
|
25
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Builds the tagged-PDF logical structure tree (ISO 32000-1 §14.7–14.8): a
|
|
50
|
+
* `/StructTreeRoot` over a tree of {@link StructNode}s, tied back to page
|
|
51
|
+
* marked-content via MCRs and the `/ParentTree`. A generic emitter — the
|
|
52
|
+
* structure-type mapping policy lives in the renderer. Object ids are assigned by
|
|
53
|
+
* a deterministic pre-order DFS so identical input yields byte-identical output.
|
|
54
|
+
*/
|
|
26
55
|
export declare class StructTreeBuilder {
|
|
27
56
|
private readonly nodes;
|
|
57
|
+
/** The root logical element (the single `/Document` under `/StructTreeRoot`). */
|
|
28
58
|
readonly root: StructNode;
|
|
29
59
|
constructor();
|
|
60
|
+
/**
|
|
61
|
+
* Create a node of `type` as the last child of `parent`.
|
|
62
|
+
*
|
|
63
|
+
* @param parent The parent node, or `null` for a free node (only the root is
|
|
64
|
+
* created that way).
|
|
65
|
+
* @returns The new node.
|
|
66
|
+
*/
|
|
30
67
|
create(type: StructType, parent: StructNode | null): StructNode;
|
|
68
|
+
/**
|
|
69
|
+
* Look up a node by its id.
|
|
70
|
+
*
|
|
71
|
+
* @throws Error if no node has that id.
|
|
72
|
+
*/
|
|
31
73
|
node(id: number): StructNode;
|
|
74
|
+
/**
|
|
75
|
+
* Record that marked content `mcid` on page `pageIndex` is the content of node
|
|
76
|
+
* `nodeId`. Called from the emit phase as MCIDs are assigned.
|
|
77
|
+
*/
|
|
32
78
|
addMcref(nodeId: number, pageIndex: number, mcid: number): void;
|
|
79
|
+
/**
|
|
80
|
+
* §14.7.4.4: an annotation's `/StructParent` key maps DIRECTLY to its owning
|
|
81
|
+
* `/StructElem` in the parent tree (a scalar entry, unlike the per-page MCID
|
|
82
|
+
* arrays). The emit phase allocates keys above the page indices.
|
|
83
|
+
*/
|
|
33
84
|
private readonly annotParents;
|
|
85
|
+
/**
|
|
86
|
+
* Register that annotation parent-tree key `key` resolves to node `nodeId`.
|
|
87
|
+
*
|
|
88
|
+
* @see StructTreeBuilder.annotParents
|
|
89
|
+
*/
|
|
34
90
|
addAnnotParent(key: number, nodeId: number): void;
|
|
91
|
+
/**
|
|
92
|
+
* Emit the `/StructTreeRoot`, every `/StructElem`, and the `/ParentTree`. Must
|
|
93
|
+
* run after all pages are added (so `pageRefs` is complete) and after every
|
|
94
|
+
* {@link StructTreeBuilder.addMcref} call.
|
|
95
|
+
*
|
|
96
|
+
* @param pageRefs The page object references, indexed by page number.
|
|
97
|
+
* @returns A reference to the `/StructTreeRoot`, for the catalog.
|
|
98
|
+
*/
|
|
35
99
|
emit(doc: PdfDocument, pageRefs: ReadonlyArray<PdfRef>): PdfRef;
|
|
36
100
|
}
|
|
37
101
|
export {};
|
|
@@ -1,27 +1,60 @@
|
|
|
1
1
|
import { PDF_NULL, dict, name, unicodeString } from "./objects.js";
|
|
2
2
|
//#region src/pdf/struct-tree.ts
|
|
3
|
+
/** One node in the logical structure tree: a {@link StructType} plus its children, marked-content and attributes. */
|
|
3
4
|
var StructNode = class {
|
|
4
5
|
children = [];
|
|
5
6
|
mcrefs = [];
|
|
7
|
+
/**
|
|
8
|
+
* §14.7.4.3 object references (`/OBJR` kids) — e.g. a Link element pointing at
|
|
9
|
+
* its link annotation. The annotation's own `/StructParent` entry is recorded
|
|
10
|
+
* via {@link StructTreeBuilder.addAnnotParent}.
|
|
11
|
+
*/
|
|
6
12
|
objrs = [];
|
|
7
13
|
parent = null;
|
|
8
14
|
ref = null;
|
|
15
|
+
/** Alternate text (`/Alt`, §14.9.4) — required on Figure for PDF/A-1a. */
|
|
9
16
|
alt = null;
|
|
17
|
+
/** Natural language (`/Lang`) when it differs from the document default. */
|
|
10
18
|
lang = null;
|
|
19
|
+
/**
|
|
20
|
+
* §14.8.5.2 Table attribute (emitted via a `/A` attribute object on the cell):
|
|
21
|
+
* `/Scope` on a TH (Row/Column) so assistive tech binds headers to data cells.
|
|
22
|
+
*/
|
|
11
23
|
scope = null;
|
|
24
|
+
/** §14.8.5.2 — `/ColSpan` when the cell spans more than one column (gridSpan). */
|
|
12
25
|
colSpan = null;
|
|
26
|
+
/** §14.8.5.2 — `/RowSpan` when the cell spans more than one row (vertical merge). */
|
|
13
27
|
rowSpan = null;
|
|
28
|
+
/**
|
|
29
|
+
* @param id The node's index, used for deterministic id assignment and `/ID`.
|
|
30
|
+
* @param type The structure type (mutable, so the renderer can retag).
|
|
31
|
+
*/
|
|
14
32
|
constructor(id, type) {
|
|
15
33
|
this.id = id;
|
|
16
34
|
this.type = type;
|
|
17
35
|
}
|
|
18
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Builds the tagged-PDF logical structure tree (ISO 32000-1 §14.7–14.8): a
|
|
39
|
+
* `/StructTreeRoot` over a tree of {@link StructNode}s, tied back to page
|
|
40
|
+
* marked-content via MCRs and the `/ParentTree`. A generic emitter — the
|
|
41
|
+
* structure-type mapping policy lives in the renderer. Object ids are assigned by
|
|
42
|
+
* a deterministic pre-order DFS so identical input yields byte-identical output.
|
|
43
|
+
*/
|
|
19
44
|
var StructTreeBuilder = class {
|
|
20
45
|
nodes = [];
|
|
46
|
+
/** The root logical element (the single `/Document` under `/StructTreeRoot`). */
|
|
21
47
|
root;
|
|
22
48
|
constructor() {
|
|
23
49
|
this.root = this.create("Document", null);
|
|
24
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Create a node of `type` as the last child of `parent`.
|
|
53
|
+
*
|
|
54
|
+
* @param parent The parent node, or `null` for a free node (only the root is
|
|
55
|
+
* created that way).
|
|
56
|
+
* @returns The new node.
|
|
57
|
+
*/
|
|
25
58
|
create(type, parent) {
|
|
26
59
|
const node = new StructNode(this.nodes.length, type);
|
|
27
60
|
node.parent = parent;
|
|
@@ -29,24 +62,51 @@ var StructTreeBuilder = class {
|
|
|
29
62
|
this.nodes.push(node);
|
|
30
63
|
return node;
|
|
31
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Look up a node by its id.
|
|
67
|
+
*
|
|
68
|
+
* @throws Error if no node has that id.
|
|
69
|
+
*/
|
|
32
70
|
node(id) {
|
|
33
71
|
const n = this.nodes[id];
|
|
34
72
|
if (!n) throw new Error(`Unknown struct node id ${id}`);
|
|
35
73
|
return n;
|
|
36
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Record that marked content `mcid` on page `pageIndex` is the content of node
|
|
77
|
+
* `nodeId`. Called from the emit phase as MCIDs are assigned.
|
|
78
|
+
*/
|
|
37
79
|
addMcref(nodeId, pageIndex, mcid) {
|
|
38
80
|
this.node(nodeId).mcrefs.push({
|
|
39
81
|
pageIndex,
|
|
40
82
|
mcid
|
|
41
83
|
});
|
|
42
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* §14.7.4.4: an annotation's `/StructParent` key maps DIRECTLY to its owning
|
|
87
|
+
* `/StructElem` in the parent tree (a scalar entry, unlike the per-page MCID
|
|
88
|
+
* arrays). The emit phase allocates keys above the page indices.
|
|
89
|
+
*/
|
|
43
90
|
annotParents = [];
|
|
91
|
+
/**
|
|
92
|
+
* Register that annotation parent-tree key `key` resolves to node `nodeId`.
|
|
93
|
+
*
|
|
94
|
+
* @see StructTreeBuilder.annotParents
|
|
95
|
+
*/
|
|
44
96
|
addAnnotParent(key, nodeId) {
|
|
45
97
|
this.annotParents.push({
|
|
46
98
|
key,
|
|
47
99
|
nodeId
|
|
48
100
|
});
|
|
49
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Emit the `/StructTreeRoot`, every `/StructElem`, and the `/ParentTree`. Must
|
|
104
|
+
* run after all pages are added (so `pageRefs` is complete) and after every
|
|
105
|
+
* {@link StructTreeBuilder.addMcref} call.
|
|
106
|
+
*
|
|
107
|
+
* @param pageRefs The page object references, indexed by page number.
|
|
108
|
+
* @returns A reference to the `/StructTreeRoot`, for the catalog.
|
|
109
|
+
*/
|
|
50
110
|
emit(doc, pageRefs) {
|
|
51
111
|
const order = [];
|
|
52
112
|
const walk = (n) => {
|
|
@@ -2,12 +2,45 @@ import { LaidOutPdfDocument, StyledRenderOptions } from '../layout/styled-layout
|
|
|
2
2
|
import { PdfDocument } from './writer.js';
|
|
3
3
|
import { PdfEncryptOptions } from './encryption.js';
|
|
4
4
|
type EmitOptions = Pick<StyledRenderOptions, 'attachments' | 'info' | 'language' | 'pdfUA' | 'signaturePlaceholder'>;
|
|
5
|
+
/**
|
|
6
|
+
* The emit phase: turn a laid-out document into PDF objects (ISO 32000) and
|
|
7
|
+
* serialize it. The counterpart of `layoutStyledDocument` (the seam of
|
|
8
|
+
* ir-design §7 / oop-design §4.1); it sees only the laid-out document plus the
|
|
9
|
+
* output-side options, never the layout options. Fonts and images embed first
|
|
10
|
+
* (the object order the pre-split renderer produced), pages replay their
|
|
11
|
+
* `PageItem`s, then the catalog assembles the OutputIntent / XMP / struct-tree /
|
|
12
|
+
* attachments as required.
|
|
13
|
+
*
|
|
14
|
+
* @returns The serialized PDF bytes.
|
|
15
|
+
*/
|
|
5
16
|
export declare function emitStyledPdf(laid: LaidOutPdfDocument, options: EmitOptions, doc: PdfDocument): Uint8Array;
|
|
17
|
+
/**
|
|
18
|
+
* The encrypted build (ISO 32000 §7.6): assemble as usual, encrypt every
|
|
19
|
+
* collected object with the derived file key, then add the (plaintext)
|
|
20
|
+
* `/Encrypt` dictionary and emit with a file `/ID`. Asynchronous because
|
|
21
|
+
* WebCrypto is.
|
|
22
|
+
*
|
|
23
|
+
* @param encrypt The encryption parameters (handler revision, permissions,
|
|
24
|
+
* passwords) used to prepare the file key and `/Encrypt` dict.
|
|
25
|
+
* @returns The serialized, encrypted PDF bytes.
|
|
26
|
+
*/
|
|
6
27
|
export declare function emitStyledPdfEncrypted(laid: LaidOutPdfDocument, options: EmitOptions, doc: PdfDocument, encrypt: PdfEncryptOptions): Promise<Uint8Array>;
|
|
28
|
+
/**
|
|
29
|
+
* Per-page tagging state threaded into `emitPageContent` when emitting a tagged
|
|
30
|
+
* PDF (ISO 32000-1 §14.7).
|
|
31
|
+
*/
|
|
7
32
|
export interface PageTagging {
|
|
33
|
+
/** The running MCID counter, reset per page. */
|
|
8
34
|
next: number;
|
|
35
|
+
/** Whether any tagged marked content was emitted (so the page gets `/StructParents`). */
|
|
9
36
|
assigned: boolean;
|
|
37
|
+
/** Tie an assigned MCID back to its structure node. */
|
|
10
38
|
record: (structId: number, mcid: number) => void;
|
|
39
|
+
/**
|
|
40
|
+
* The marked-content tag for a structure node — its structure type, so the
|
|
41
|
+
* `BDC` tag matches the `StructElem` `/S` (§14.7.2: a heading is `/H1`, a
|
|
42
|
+
* cell's paragraph `/P`, …), not a hardcoded `/P`.
|
|
43
|
+
*/
|
|
11
44
|
tagFor: (structId: number) => string;
|
|
12
45
|
}
|
|
13
46
|
export {};
|
|
@@ -15,10 +15,31 @@ import { addSignaturePlaceholder } from "./signature.js";
|
|
|
15
15
|
import { buildXmpPacket } from "./xmp.js";
|
|
16
16
|
//#region src/pdf/styled-page-emitter.ts
|
|
17
17
|
var encoder = new TextEncoder();
|
|
18
|
+
/**
|
|
19
|
+
* The emit phase: turn a laid-out document into PDF objects (ISO 32000) and
|
|
20
|
+
* serialize it. The counterpart of `layoutStyledDocument` (the seam of
|
|
21
|
+
* ir-design §7 / oop-design §4.1); it sees only the laid-out document plus the
|
|
22
|
+
* output-side options, never the layout options. Fonts and images embed first
|
|
23
|
+
* (the object order the pre-split renderer produced), pages replay their
|
|
24
|
+
* `PageItem`s, then the catalog assembles the OutputIntent / XMP / struct-tree /
|
|
25
|
+
* attachments as required.
|
|
26
|
+
*
|
|
27
|
+
* @returns The serialized PDF bytes.
|
|
28
|
+
*/
|
|
18
29
|
function emitStyledPdf(laid, options, doc) {
|
|
19
30
|
const a = assembleStyledPdf(laid, options, doc);
|
|
20
31
|
return doc.build(a.catalogRef, a.infoRef, a.buildOptions);
|
|
21
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* The encrypted build (ISO 32000 §7.6): assemble as usual, encrypt every
|
|
35
|
+
* collected object with the derived file key, then add the (plaintext)
|
|
36
|
+
* `/Encrypt` dictionary and emit with a file `/ID`. Asynchronous because
|
|
37
|
+
* WebCrypto is.
|
|
38
|
+
*
|
|
39
|
+
* @param encrypt The encryption parameters (handler revision, permissions,
|
|
40
|
+
* passwords) used to prepare the file key and `/Encrypt` dict.
|
|
41
|
+
* @returns The serialized, encrypted PDF bytes.
|
|
42
|
+
*/
|
|
22
43
|
async function emitStyledPdfEncrypted(laid, options, doc, encrypt) {
|
|
23
44
|
const a = assembleStyledPdf(laid, options, doc);
|
|
24
45
|
const prepared = await preparePdfEncryption(encrypt);
|
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import { BodyElement } from '../core/document-model/index.js';
|
|
2
2
|
import { StyledRenderOptions } from '../layout/styled-layout.js';
|
|
3
|
+
/**
|
|
4
|
+
* Render a body to a PDF: lay it out, then emit it over a fresh
|
|
5
|
+
* {@link PdfDocument}. The byte-stable synchronous path.
|
|
6
|
+
*
|
|
7
|
+
* @throws Error when `options.encrypt` is set — encryption requires the async
|
|
8
|
+
* {@link renderStyledPdfEncrypted} path (WebCrypto).
|
|
9
|
+
*/
|
|
3
10
|
export declare function renderStyledPdf(body: ReadonlyArray<BodyElement>, options: StyledRenderOptions): Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* The encrypting variant of {@link renderStyledPdf} (ISO 32000 §7.6; async
|
|
13
|
+
* because WebCrypto is). Validates the standing conflicts here so every
|
|
14
|
+
* converter shares them: PDF/A forbids `/Encrypt` (ISO 19005), signatures +
|
|
15
|
+
* encryption is out of scope in v1, and PDF/UA requires assistive technology to
|
|
16
|
+
* keep extraction access (bit 10, forced on here). With no `options.encrypt` it
|
|
17
|
+
* falls through to the plain {@link renderStyledPdf}.
|
|
18
|
+
*
|
|
19
|
+
* @throws Error when `options.pdfA` is set (PDF/A forbids encryption) or when a
|
|
20
|
+
* signature placeholder is combined with encryption.
|
|
21
|
+
*/
|
|
4
22
|
export declare function renderStyledPdfEncrypted(body: ReadonlyArray<BodyElement>, options: StyledRenderOptions): Promise<Uint8Array>;
|
|
5
23
|
export * from '../layout/page-doc.js';
|
|
6
24
|
export * from '../layout/styled-layout.js';
|
|
@@ -3,10 +3,28 @@ import { layoutStyledDocument } from "../layout/styled-layout.js";
|
|
|
3
3
|
import "../layout/page-doc.js";
|
|
4
4
|
import { emitStyledPdf, emitStyledPdfEncrypted } from "./styled-page-emitter.js";
|
|
5
5
|
//#region src/pdf/styled-page-renderer.ts
|
|
6
|
+
/**
|
|
7
|
+
* Render a body to a PDF: lay it out, then emit it over a fresh
|
|
8
|
+
* {@link PdfDocument}. The byte-stable synchronous path.
|
|
9
|
+
*
|
|
10
|
+
* @throws Error when `options.encrypt` is set — encryption requires the async
|
|
11
|
+
* {@link renderStyledPdfEncrypted} path (WebCrypto).
|
|
12
|
+
*/
|
|
6
13
|
function renderStyledPdf(body, options) {
|
|
7
14
|
if (options.encrypt) throw new Error("PDF encryption requires the async conversion path (WebCrypto)");
|
|
8
15
|
return emitStyledPdf(layoutStyledDocument(body, options), options, new PdfDocument());
|
|
9
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* The encrypting variant of {@link renderStyledPdf} (ISO 32000 §7.6; async
|
|
19
|
+
* because WebCrypto is). Validates the standing conflicts here so every
|
|
20
|
+
* converter shares them: PDF/A forbids `/Encrypt` (ISO 19005), signatures +
|
|
21
|
+
* encryption is out of scope in v1, and PDF/UA requires assistive technology to
|
|
22
|
+
* keep extraction access (bit 10, forced on here). With no `options.encrypt` it
|
|
23
|
+
* falls through to the plain {@link renderStyledPdf}.
|
|
24
|
+
*
|
|
25
|
+
* @throws Error when `options.pdfA` is set (PDF/A forbids encryption) or when a
|
|
26
|
+
* signature placeholder is combined with encryption.
|
|
27
|
+
*/
|
|
10
28
|
async function renderStyledPdfEncrypted(body, options) {
|
|
11
29
|
const encrypt = options.encrypt;
|
|
12
30
|
if (!encrypt) return renderStyledPdf(body, options);
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encode text as WinAnsiEncoding (CP-1252) bytes (ISO 32000-1 §D.2). Latin-1 is
|
|
3
|
+
* passed through; the CP-1252 high range (smart quotes, dashes, €, …) is
|
|
4
|
+
* remapped; anything else becomes `?`.
|
|
5
|
+
*
|
|
6
|
+
* @param text The string to encode.
|
|
7
|
+
* @returns One byte per code point.
|
|
8
|
+
*/
|
|
1
9
|
export declare function encodeWinAnsi(text: string): Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* Encode text as a PDF literal string body (ISO 32000-1 §7.3.4.2): WinAnsi
|
|
12
|
+
* bytes with `(`, `)` and `\` backslash-escaped. The result is ready to be
|
|
13
|
+
* wrapped in `(` … `)` within a content stream.
|
|
14
|
+
*
|
|
15
|
+
* @param text The string to encode.
|
|
16
|
+
* @returns The escaped bytes (without the surrounding parentheses).
|
|
17
|
+
*/
|
|
2
18
|
export declare function encodeLiteralBytes(text: string): Uint8Array;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ParsedTtf } from '../core/font/index.js';
|
|
2
|
+
/** A font for {@link renderPlainTextPdf}: an already-parsed TTF or its raw bytes. */
|
|
2
3
|
export type FontInput = ParsedTtf | {
|
|
3
4
|
readonly bytes: Uint8Array;
|
|
4
5
|
};
|
|
6
|
+
/** Options for {@link renderPlainTextPdf}; every layout dimension defaults (A4, 72pt margins, 12pt text). */
|
|
5
7
|
export interface TextRenderOptions {
|
|
6
8
|
readonly font: FontInput;
|
|
7
9
|
readonly pageWidth?: number;
|
|
@@ -11,6 +13,15 @@ export interface TextRenderOptions {
|
|
|
11
13
|
readonly marginTop?: number;
|
|
12
14
|
readonly marginBottom?: number;
|
|
13
15
|
readonly fontSize?: number;
|
|
16
|
+
/** Baseline-to-baseline distance in points; defaults to `1.2 × fontSize`. */
|
|
14
17
|
readonly lineHeight?: number;
|
|
15
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Render plain-text paragraphs to a single-font PDF, paginating greedily with
|
|
21
|
+
* real TTF metrics and embedding the subset font.
|
|
22
|
+
*
|
|
23
|
+
* @param paragraphs One string per paragraph; empty strings become blank lines.
|
|
24
|
+
* @param options The font plus optional page geometry and type size.
|
|
25
|
+
* @returns The encoded PDF bytes.
|
|
26
|
+
*/
|
|
16
27
|
export declare function renderPlainTextPdf(paragraphs: ReadonlyArray<string>, options: TextRenderOptions): Uint8Array;
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { VectorShape } from '../core/vector.js';
|
|
2
2
|
export type { PathSegment, StrokeStyle, VectorPath, VectorShape } from '../core/vector.js';
|
|
3
3
|
export { PathBuilder } from '../core/vector.js';
|
|
4
|
+
/**
|
|
5
|
+
* Emit a {@link VectorShape} as PDF content-stream operators (ISO 32000 §8.5),
|
|
6
|
+
* wrapped in a `q`/`Q` save-restore with the shape's transform as the CTM. The
|
|
7
|
+
* subpaths are painted with a single operator, so the winding rule is decided
|
|
8
|
+
* once (even-odd if any subpath asks).
|
|
9
|
+
*
|
|
10
|
+
* @param shape The shape to draw.
|
|
11
|
+
* @param patternName When set, the fill is this named shading pattern from the
|
|
12
|
+
* page's `/Pattern` resources (a gradient, EP16b) rather than a solid colour;
|
|
13
|
+
* only used if the shape actually carries a `fillGradient`.
|
|
14
|
+
* @returns The content-stream operator lines.
|
|
15
|
+
*/
|
|
4
16
|
export declare function emitVectorShape(shape: VectorShape, patternName?: string): Array<string>;
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import "../core/vector.js";
|
|
2
2
|
//#region src/pdf/vector-graphics.ts
|
|
3
|
+
/**
|
|
4
|
+
* Emit a {@link VectorShape} as PDF content-stream operators (ISO 32000 §8.5),
|
|
5
|
+
* wrapped in a `q`/`Q` save-restore with the shape's transform as the CTM. The
|
|
6
|
+
* subpaths are painted with a single operator, so the winding rule is decided
|
|
7
|
+
* once (even-odd if any subpath asks).
|
|
8
|
+
*
|
|
9
|
+
* @param shape The shape to draw.
|
|
10
|
+
* @param patternName When set, the fill is this named shading pattern from the
|
|
11
|
+
* page's `/Pattern` resources (a gradient, EP16b) rather than a solid colour;
|
|
12
|
+
* only used if the shape actually carries a `fillGradient`.
|
|
13
|
+
* @returns The content-stream operator lines.
|
|
14
|
+
*/
|
|
3
15
|
function emitVectorShape(shape, patternName) {
|
|
4
16
|
const out = [];
|
|
5
17
|
out.push("q");
|
package/dist/esm/pdf/writer.d.ts
CHANGED
|
@@ -1,12 +1,51 @@
|
|
|
1
1
|
import { PdfValue, PdfRef } from './objects.js';
|
|
2
|
+
/** Options for {@link PdfDocument.build}. */
|
|
2
3
|
export interface BuildOptions {
|
|
4
|
+
/** PDF header version, e.g. `"1.7"` (default) or `"1.4"` (PDF/A-1). */
|
|
3
5
|
readonly version?: string;
|
|
6
|
+
/**
|
|
7
|
+
* When true, emit a `/ID` array in the trailer (required by PDF/A). The two
|
|
8
|
+
* identifiers are a deterministic hash of the file body — no `Date`/random,
|
|
9
|
+
* so the same input always yields the same bytes.
|
|
10
|
+
*/
|
|
4
11
|
readonly id?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The `/Encrypt` dictionary's ref (§7.6.2) — emitted in the trailer. The
|
|
14
|
+
* referenced object must be added AFTER {@link PdfDocument.encryptAll} so it
|
|
15
|
+
* stays plaintext.
|
|
16
|
+
*/
|
|
5
17
|
readonly encrypt?: PdfRef;
|
|
6
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Collects indirect objects and emits a complete PDF file (ISO 32000-1 §7.5):
|
|
21
|
+
* header (§7.5.2), body of indirect objects (§7.5.3), cross-reference table
|
|
22
|
+
* (§7.5.4) and trailer (§7.5.5).
|
|
23
|
+
*/
|
|
7
24
|
export declare class PdfDocument {
|
|
8
25
|
private readonly objects;
|
|
26
|
+
/**
|
|
27
|
+
* Append `value` as a new indirect object.
|
|
28
|
+
*
|
|
29
|
+
* @param value The object to add.
|
|
30
|
+
* @returns An indirect reference to it (generation 0).
|
|
31
|
+
*/
|
|
9
32
|
add(value: PdfValue): PdfRef;
|
|
33
|
+
/**
|
|
34
|
+
* Encrypt every string and stream in every object added so far (§7.6). The
|
|
35
|
+
* `/Encrypt` dictionary itself must be added AFTER this pass so it stays
|
|
36
|
+
* plaintext.
|
|
37
|
+
*
|
|
38
|
+
* @param fileKey The document encryption key.
|
|
39
|
+
*/
|
|
10
40
|
encryptAll(fileKey: Uint8Array): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Serialize the whole document to bytes: header, body, cross-reference table
|
|
43
|
+
* and trailer.
|
|
44
|
+
*
|
|
45
|
+
* @param root Reference to the document catalog (`/Root`).
|
|
46
|
+
* @param info Optional reference to the `/Info` dictionary.
|
|
47
|
+
* @param options Header version, `/ID` emission, and `/Encrypt` reference.
|
|
48
|
+
* @returns The complete PDF file bytes.
|
|
49
|
+
*/
|
|
11
50
|
build(root: PdfRef, info?: PdfRef, options?: BuildOptions): Uint8Array;
|
|
12
51
|
}
|
package/dist/esm/pdf/writer.js
CHANGED
|
@@ -11,8 +11,19 @@ var BINARY_MARKER = new Uint8Array([
|
|
|
11
11
|
211,
|
|
12
12
|
10
|
|
13
13
|
]);
|
|
14
|
+
/**
|
|
15
|
+
* Collects indirect objects and emits a complete PDF file (ISO 32000-1 §7.5):
|
|
16
|
+
* header (§7.5.2), body of indirect objects (§7.5.3), cross-reference table
|
|
17
|
+
* (§7.5.4) and trailer (§7.5.5).
|
|
18
|
+
*/
|
|
14
19
|
var PdfDocument = class {
|
|
15
20
|
objects = [];
|
|
21
|
+
/**
|
|
22
|
+
* Append `value` as a new indirect object.
|
|
23
|
+
*
|
|
24
|
+
* @param value The object to add.
|
|
25
|
+
* @returns An indirect reference to it (generation 0).
|
|
26
|
+
*/
|
|
16
27
|
add(value) {
|
|
17
28
|
const id = this.objects.length + 1;
|
|
18
29
|
this.objects.push({
|
|
@@ -21,9 +32,25 @@ var PdfDocument = class {
|
|
|
21
32
|
});
|
|
22
33
|
return new PdfRef(id);
|
|
23
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Encrypt every string and stream in every object added so far (§7.6). The
|
|
37
|
+
* `/Encrypt` dictionary itself must be added AFTER this pass so it stays
|
|
38
|
+
* plaintext.
|
|
39
|
+
*
|
|
40
|
+
* @param fileKey The document encryption key.
|
|
41
|
+
*/
|
|
24
42
|
async encryptAll(fileKey) {
|
|
25
43
|
for (const obj of this.objects) obj.value = await encryptObjectGraph(obj.value, fileKey);
|
|
26
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Serialize the whole document to bytes: header, body, cross-reference table
|
|
47
|
+
* and trailer.
|
|
48
|
+
*
|
|
49
|
+
* @param root Reference to the document catalog (`/Root`).
|
|
50
|
+
* @param info Optional reference to the `/Info` dictionary.
|
|
51
|
+
* @param options Header version, `/ID` emission, and `/Encrypt` reference.
|
|
52
|
+
* @returns The complete PDF file bytes.
|
|
53
|
+
*/
|
|
27
54
|
build(root, info, options = {}) {
|
|
28
55
|
const parts = [];
|
|
29
56
|
const offsets = new Array(this.objects.length + 1).fill(0);
|
package/dist/esm/pdf/xmp.d.ts
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
|
+
/** The document metadata projected into an XMP packet by {@link buildXmpPacket}. */
|
|
1
2
|
export interface XmpInput {
|
|
2
3
|
readonly title?: string;
|
|
3
4
|
readonly author?: string;
|
|
4
5
|
readonly subject?: string;
|
|
5
6
|
readonly keywords?: string;
|
|
7
|
+
/** Application that created the doc (`xmp:CreatorTool`). */
|
|
6
8
|
readonly creator?: string;
|
|
7
9
|
readonly producer?: string;
|
|
8
10
|
readonly createDate?: Date;
|
|
9
11
|
readonly modifyDate?: Date;
|
|
12
|
+
/**
|
|
13
|
+
* PDF/A identifier: part 1 (ISO 19005-1) / 2 / 3; conformance level
|
|
14
|
+
* `'A'` (tagged) / `'B'` (visual) / `'U'` (Unicode — parts 2/3 only).
|
|
15
|
+
*/
|
|
10
16
|
readonly pdfaPart?: '1' | '2' | '3';
|
|
17
|
+
/** PDF/UA identification (ISO 14289-1) — `pdfuaid:part`. */
|
|
11
18
|
readonly pdfuaPart?: '1';
|
|
12
19
|
readonly pdfaConformance?: 'A' | 'B' | 'U';
|
|
13
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Build an XMP metadata packet (ISO 16684-1) for the document `/Metadata`
|
|
23
|
+
* stream, emitting only the sections the supplied {@link XmpInput} populates
|
|
24
|
+
* (PDF/A and PDF/UA identifiers, Dublin Core, XMP basic, Adobe PDF). For PDF/A
|
|
25
|
+
* the standard properties must agree with the `/Info` dictionary.
|
|
26
|
+
*
|
|
27
|
+
* @param input The metadata to project.
|
|
28
|
+
* @returns The UTF-8 encoded XMP packet bytes.
|
|
29
|
+
*/
|
|
14
30
|
export declare function buildXmpPacket(input: XmpInput): Uint8Array;
|
package/dist/esm/pdf/xmp.js
CHANGED
|
@@ -6,6 +6,15 @@ function xmpDate(d) {
|
|
|
6
6
|
const pad = (n, w = 2) => String(n).padStart(w, "0");
|
|
7
7
|
return `${pad(d.getUTCFullYear(), 4)}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}T${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}:${pad(d.getUTCSeconds())}Z`;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Build an XMP metadata packet (ISO 16684-1) for the document `/Metadata`
|
|
11
|
+
* stream, emitting only the sections the supplied {@link XmpInput} populates
|
|
12
|
+
* (PDF/A and PDF/UA identifiers, Dublin Core, XMP basic, Adobe PDF). For PDF/A
|
|
13
|
+
* the standard properties must agree with the `/Info` dictionary.
|
|
14
|
+
*
|
|
15
|
+
* @param input The metadata to project.
|
|
16
|
+
* @returns The UTF-8 encoded XMP packet bytes.
|
|
17
|
+
*/
|
|
9
18
|
function buildXmpPacket(input) {
|
|
10
19
|
const props = [];
|
|
11
20
|
if (input.pdfaPart) props.push(` <rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">`, ` <pdfaid:part>${input.pdfaPart}</pdfaid:part>`, ` <pdfaid:conformance>${input.pdfaConformance ?? "B"}</pdfaid:conformance>`, ` </rdf:Description>`);
|
|
@@ -1,14 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `/CCITTFaxDecode` parameters that drive {@link decodeCcitt} (ISO 32000-1
|
|
3
|
+
* §7.4.6), pulled from the filter's `/DecodeParms`.
|
|
4
|
+
*/
|
|
1
5
|
export interface CcittParams {
|
|
6
|
+
/** `/K` — `<0` Group 4, `0` Group 3 1-D, `>0` Group 3 2-D (unsupported). */
|
|
2
7
|
readonly k: number;
|
|
8
|
+
/** `/Columns` (pixels per row). */
|
|
3
9
|
readonly columns: number;
|
|
10
|
+
/** `/Rows` (or the image `/Height`) — the row count to decode. */
|
|
4
11
|
readonly rows: number;
|
|
12
|
+
/** `/EncodedByteAlign` — pad each row to a byte boundary. */
|
|
5
13
|
readonly byteAlign: boolean;
|
|
6
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Decode a CCITT Group 3 / Group 4 fax stream into a packed 1-bit-per-pixel
|
|
17
|
+
* bitmap.
|
|
18
|
+
*
|
|
19
|
+
* @param data The raw fax codestream (any wrapping filters already stripped).
|
|
20
|
+
* @param params The `/CCITTFaxDecode` parameters.
|
|
21
|
+
* @returns The packed bitmap (`rowBytes × rows`, bit 1 = black, MSB first), or
|
|
22
|
+
* `undefined` when the stream cannot be decoded (e.g. Group 3 2-D, or nothing
|
|
23
|
+
* decoded at all).
|
|
24
|
+
*/
|
|
7
25
|
export declare function decodeCcitt(data: Uint8Array, params: CcittParams): Uint8Array | undefined;
|
|
26
|
+
/** A decoded T.6 two-dimensional mode code: pass, horizontal, or vertical V(d). */
|
|
8
27
|
export interface Mode {
|
|
9
28
|
readonly kind: 'pass' | 'horizontal' | 'vertical';
|
|
29
|
+
/** Vertical offset (−3..3); meaningful only when `kind` is `'vertical'`. */
|
|
10
30
|
readonly d: number;
|
|
11
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* T.4 white-run modified-Huffman codes as `[run, bit-string]` (terminating runs
|
|
34
|
+
* 0..63, make-up runs multiples of 64). Exported so the test can build an
|
|
35
|
+
* independent encoder and validate the codes form a valid prefix set.
|
|
36
|
+
*/
|
|
12
37
|
export declare const WHITE_CODES: ReadonlyArray<readonly [number, string]>;
|
|
13
38
|
export declare const BLACK_CODES: ReadonlyArray<readonly [number, string]>;
|
|
14
39
|
export declare const SHARED_MAKEUP: ReadonlyArray<readonly [number, string]>;
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
//#region src/pdf-reader/ccitt.ts
|
|
2
|
+
/**
|
|
3
|
+
* Decode a CCITT Group 3 / Group 4 fax stream into a packed 1-bit-per-pixel
|
|
4
|
+
* bitmap.
|
|
5
|
+
*
|
|
6
|
+
* @param data The raw fax codestream (any wrapping filters already stripped).
|
|
7
|
+
* @param params The `/CCITTFaxDecode` parameters.
|
|
8
|
+
* @returns The packed bitmap (`rowBytes × rows`, bit 1 = black, MSB first), or
|
|
9
|
+
* `undefined` when the stream cannot be decoded (e.g. Group 3 2-D, or nothing
|
|
10
|
+
* decoded at all).
|
|
11
|
+
*/
|
|
2
12
|
function decodeCcitt(data, params) {
|
|
3
13
|
const { k, columns, rows, byteAlign } = params;
|
|
4
14
|
if (k > 0) return void 0;
|
|
@@ -136,6 +146,11 @@ var BitReader = class {
|
|
|
136
146
|
}
|
|
137
147
|
}
|
|
138
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* T.4 white-run modified-Huffman codes as `[run, bit-string]` (terminating runs
|
|
151
|
+
* 0..63, make-up runs multiples of 64). Exported so the test can build an
|
|
152
|
+
* independent encoder and validate the codes form a valid prefix set.
|
|
153
|
+
*/
|
|
139
154
|
var WHITE_CODES = [
|
|
140
155
|
[0, "00110101"],
|
|
141
156
|
[1, "000111"],
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
+
/** A parsed `/ToUnicode` CMap: the code→Unicode mapping and the code width. */
|
|
1
2
|
export interface ToUnicode {
|
|
3
|
+
/** Character code → Unicode string (a single code may map to a ligature). */
|
|
2
4
|
readonly map: ReadonlyMap<number, string>;
|
|
5
|
+
/** Whether character codes are one or two bytes wide (from `codespacerange`). */
|
|
3
6
|
readonly codeBytes: 1 | 2;
|
|
4
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Parse a `/ToUnicode` CMap (ISO 32000-1 §9.10.3) into a code→Unicode map. Reads
|
|
10
|
+
* the `codespacerange` (code width), `bfchar` (single codes) and `bfrange`
|
|
11
|
+
* (contiguous ranges, scalar or array destination) blocks; everything else is
|
|
12
|
+
* ignored.
|
|
13
|
+
*
|
|
14
|
+
* @param bytes The decoded CMap stream.
|
|
15
|
+
* @returns The mapping plus the declared code width (1 or 2 bytes).
|
|
16
|
+
*/
|
|
5
17
|
export declare function parseToUnicodeCMap(bytes: Uint8Array): ToUnicode;
|