@awacloud/pdf 0.0.0-stage → 1.0.0
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/CHANGELOG.md +609 -0
- package/LICENSE +661 -0
- package/NOTICE +77 -0
- package/README.md +363 -2
- package/dist/build/index.js +21 -0
- package/dist/build/pdf-full-rw.js +10972 -0
- package/dist/build/pdf-full-rw.meta.json +105 -0
- package/dist/build/pdf-full-rw.min.js +53 -0
- package/dist/build/pdf-full.js +6078 -0
- package/dist/build/pdf-full.meta.json +90 -0
- package/dist/build/pdf-full.min.js +32 -0
- package/dist/build/pdf-large-rw.js +10367 -0
- package/dist/build/pdf-large-rw.meta.json +99 -0
- package/dist/build/pdf-large-rw.min.js +53 -0
- package/dist/build/pdf-large.js +5473 -0
- package/dist/build/pdf-large.meta.json +84 -0
- package/dist/build/pdf-large.min.js +32 -0
- package/dist/build/pdf-legacy-rw.js +12402 -0
- package/dist/build/pdf-legacy-rw.meta.json +110 -0
- package/dist/build/pdf-legacy-rw.min.js +53 -0
- package/dist/build/pdf-legacy.js +7508 -0
- package/dist/build/pdf-legacy.meta.json +95 -0
- package/dist/build/pdf-legacy.min.js +32 -0
- package/dist/build/pdf-rw.js +7578 -0
- package/dist/build/pdf-rw.meta.json +77 -0
- package/dist/build/pdf-rw.min.js +53 -0
- package/dist/build/pdf.js +2684 -0
- package/dist/build/pdf.meta.json +62 -0
- package/dist/build/pdf.min.js +32 -0
- package/dist/standalone/pdf-full-rw.js +16798 -0
- package/dist/standalone/pdf-full-rw.meta.json +78 -0
- package/dist/standalone/pdf-full-rw.min.js +56 -0
- package/dist/standalone/pdf-full.js +11904 -0
- package/dist/standalone/pdf-full.meta.json +63 -0
- package/dist/standalone/pdf-full.min.js +35 -0
- package/dist/standalone/pdf-large-rw.js +16193 -0
- package/dist/standalone/pdf-large-rw.meta.json +72 -0
- package/dist/standalone/pdf-large-rw.min.js +56 -0
- package/dist/standalone/pdf-large.js +11299 -0
- package/dist/standalone/pdf-large.meta.json +57 -0
- package/dist/standalone/pdf-large.min.js +35 -0
- package/dist/standalone/pdf-legacy-rw.js +18228 -0
- package/dist/standalone/pdf-legacy-rw.meta.json +83 -0
- package/dist/standalone/pdf-legacy-rw.min.js +56 -0
- package/dist/standalone/pdf-legacy.js +13334 -0
- package/dist/standalone/pdf-legacy.meta.json +68 -0
- package/dist/standalone/pdf-legacy.min.js +35 -0
- package/dist/standalone/pdf-rw.js +13404 -0
- package/dist/standalone/pdf-rw.meta.json +50 -0
- package/dist/standalone/pdf-rw.min.js +56 -0
- package/dist/standalone/pdf.js +8510 -0
- package/dist/standalone/pdf.meta.json +35 -0
- package/dist/standalone/pdf.min.js +35 -0
- package/docs/README.md +53 -0
- package/docs/api/README.md +38 -0
- package/docs/api/_shared/README.md +91 -0
- package/docs/api/action/README.md +29 -0
- package/docs/api/action/action.md +81 -0
- package/docs/api/action/goTo.md +66 -0
- package/docs/api/action/launch.md +58 -0
- package/docs/api/action/named.md +55 -0
- package/docs/api/action/uri.md +54 -0
- package/docs/api/annot/README.md +53 -0
- package/docs/api/annot/annot.md +114 -0
- package/docs/api/annot/fileAttach.md +53 -0
- package/docs/api/annot/freeText.md +68 -0
- package/docs/api/annot/ink.md +69 -0
- package/docs/api/annot/link.md +74 -0
- package/docs/api/annot/markup.md +83 -0
- package/docs/api/annot/popup.md +52 -0
- package/docs/api/annot/projection.md +56 -0
- package/docs/api/annot/redact.md +67 -0
- package/docs/api/annot/square.md +87 -0
- package/docs/api/annot/stamp.md +54 -0
- package/docs/api/annot/text.md +69 -0
- package/docs/api/annot/widget.md +69 -0
- package/docs/api/associatedFiles/README.md +9 -0
- package/docs/api/associatedFiles/associatedFiles.md +78 -0
- package/docs/api/bundles/README.md +68 -0
- package/docs/api/bundles/dist-matrix.md +165 -0
- package/docs/api/bundles/pdf-full.md +148 -0
- package/docs/api/bundles/pdf-large.md +144 -0
- package/docs/api/bundles/pdf-legacy.md +169 -0
- package/docs/api/content/README.md +29 -0
- package/docs/api/content/color.md +99 -0
- package/docs/api/content/graphics.md +114 -0
- package/docs/api/content/images.md +124 -0
- package/docs/api/content/ops.md +100 -0
- package/docs/api/content/stream.md +107 -0
- package/docs/api/content/text.md +98 -0
- package/docs/api/crypto/README.md +29 -0
- package/docs/api/crypto/aesGcm.md +72 -0
- package/docs/api/crypto/permissions.md +79 -0
- package/docs/api/crypto/security.md +98 -0
- package/docs/api/crypto/standardV4.md +104 -0
- package/docs/api/crypto/standardV5.md +84 -0
- package/docs/api/crypto/standardV6.md +93 -0
- package/docs/api/destination/README.md +9 -0
- package/docs/api/destination/destination.md +79 -0
- package/docs/api/document/README.md +29 -0
- package/docs/api/document/builder.md +281 -0
- package/docs/api/document/catalog.md +98 -0
- package/docs/api/document/document.md +187 -0
- package/docs/api/document/encryptedWriter.md +149 -0
- package/docs/api/document/incrementalWriter.md +148 -0
- package/docs/api/document/page.md +99 -0
- package/docs/api/document/pages.md +82 -0
- package/docs/api/document/resources.md +102 -0
- package/docs/api/document/writer.md +157 -0
- package/docs/api/document/xrefStreamWriter.md +122 -0
- package/docs/api/embedded/README.md +13 -0
- package/docs/api/embedded/collection.md +80 -0
- package/docs/api/embedded/embeddedFile.md +86 -0
- package/docs/api/embedded/fileSpec.md +87 -0
- package/docs/api/errors.md +110 -0
- package/docs/api/extra/3d-richmedia.md +76 -0
- package/docs/api/extra/README.md +99 -0
- package/docs/api/extra/annot-extended.md +71 -0
- package/docs/api/extra/associated-files.md +70 -0
- package/docs/api/extra/ccitt-fax-decoder.md +74 -0
- package/docs/api/extra/color-spaces-extended.md +72 -0
- package/docs/api/extra/content-ops-extended.md +82 -0
- package/docs/api/extra/document-parts.md +69 -0
- package/docs/api/extra/embedded-files-portfolio.md +87 -0
- package/docs/api/extra/font-cid-typed.md +77 -0
- package/docs/api/extra/font-color-tagging.md +76 -0
- package/docs/api/extra/form-actions-extended.md +75 -0
- package/docs/api/extra/info-dict-deprecated.md +72 -0
- package/docs/api/extra/jbig2-read.md +80 -0
- package/docs/api/extra/legacy-deprecated-annots.md +89 -0
- package/docs/api/extra/legacy-deprecated-filters.md +78 -0
- package/docs/api/extra/legacy-rc4-read.md +74 -0
- package/docs/api/extra/legacy-xfa-read.md +65 -0
- package/docs/api/extra/linearization-write.md +71 -0
- package/docs/api/extra/misc.md +93 -0
- package/docs/api/extra/optional-content-extended.md +83 -0
- package/docs/api/extra/pdf-a-output-intent.md +65 -0
- package/docs/api/extra/pdf-sandbox.md +76 -0
- package/docs/api/extra/pdf-ua-tagged.md +63 -0
- package/docs/api/extra/pdf-x-prepress.md +65 -0
- package/docs/api/extra/redaction-iso32005.md +65 -0
- package/docs/api/extra/shading-typed.md +73 -0
- package/docs/api/extra/sig-aes-gcm.md +69 -0
- package/docs/api/extra/sig-pades.md +103 -0
- package/docs/api/extra/tagged-pdf-typed.md +78 -0
- package/docs/api/extra/transparency-typed.md +74 -0
- package/docs/api/extra/well-tagged-pdf.md +61 -0
- package/docs/api/extra/xmp-extended.md +65 -0
- package/docs/api/font/README.md +25 -0
- package/docs/api/font/embed.md +157 -0
- package/docs/api/font/encoding.md +95 -0
- package/docs/api/font/font.md +97 -0
- package/docs/api/font/type3.md +89 -0
- package/docs/api/form/README.md +35 -0
- package/docs/api/form/acroform.md +88 -0
- package/docs/api/form/appearance.md +87 -0
- package/docs/api/form/button.md +97 -0
- package/docs/api/form/choice.md +96 -0
- package/docs/api/form/fieldTree.md +93 -0
- package/docs/api/form/signature.md +90 -0
- package/docs/api/form/text.md +88 -0
- package/docs/api/linearization/README.md +11 -0
- package/docs/api/linearization/linearization.md +81 -0
- package/docs/api/main.md +116 -0
- package/docs/api/metadata/README.md +10 -0
- package/docs/api/metadata/info.md +70 -0
- package/docs/api/metadata/xmp.md +62 -0
- package/docs/api/ocg/README.md +23 -0
- package/docs/api/ocg/config.md +95 -0
- package/docs/api/ocg/ocg.md +77 -0
- package/docs/api/outline/README.md +11 -0
- package/docs/api/outline/outline.md +107 -0
- package/docs/api/pdf.md +152 -0
- package/docs/api/prepress/README.md +10 -0
- package/docs/api/prepress/outputIntent.md +79 -0
- package/docs/api/prepress/pageBoundary.md +75 -0
- package/docs/api/sig/README.md +32 -0
- package/docs/api/sig/byteRange.md +120 -0
- package/docs/api/sig/certChain.md +84 -0
- package/docs/api/sig/dss.md +111 -0
- package/docs/api/sig/oids.md +76 -0
- package/docs/api/sig/sha1.md +72 -0
- package/docs/api/sig/sign.md +317 -0
- package/docs/api/sig/signature.md +178 -0
- package/docs/api/sig/timestamp.md +84 -0
- package/docs/api/syntax/README.md +29 -0
- package/docs/api/syntax/crossRefStream.md +115 -0
- package/docs/api/syntax/filters/README.md +50 -0
- package/docs/api/syntax/filters/ascii85.md +76 -0
- package/docs/api/syntax/filters/asciiHex.md +73 -0
- package/docs/api/syntax/filters/dispatch.md +125 -0
- package/docs/api/syntax/filters/flate.md +134 -0
- package/docs/api/syntax/filters/runLength.md +78 -0
- package/docs/api/syntax/objStream.md +88 -0
- package/docs/api/syntax/parser-obj.md +97 -0
- package/docs/api/syntax/parser.md +151 -0
- package/docs/api/syntax/serializer.md +109 -0
- package/docs/api/syntax/tokenizer.md +104 -0
- package/docs/api/syntax/trailer.md +85 -0
- package/docs/api/syntax/xref.md +139 -0
- package/docs/api/tagged/README.md +25 -0
- package/docs/api/tagged/classMap.md +67 -0
- package/docs/api/tagged/markedContent.md +62 -0
- package/docs/api/tagged/parentTree.md +67 -0
- package/docs/api/tagged/roleMap.md +67 -0
- package/docs/api/tagged/structElement.md +76 -0
- package/docs/api/tagged/structTree.md +75 -0
- package/docs/guide/coverage.md +113 -0
- package/docs/guide/crypto.md +121 -0
- package/docs/guide/extending.md +76 -0
- package/docs/guide/getting-started.md +75 -0
- package/docs/guide/legacy-1.7.md +42 -0
- package/docs/guide/pades-integration.md +579 -0
- package/docs/guide/read-pdf.md +89 -0
- package/package.json +97 -4
- package/src/_shared/index.js +179 -0
- package/src/action/action.js +119 -0
- package/src/action/goTo.js +89 -0
- package/src/action/launch.js +61 -0
- package/src/action/named.js +54 -0
- package/src/action/uri.js +51 -0
- package/src/annot/annot.js +212 -0
- package/src/annot/fileAttach.js +55 -0
- package/src/annot/freeText.js +82 -0
- package/src/annot/ink.js +77 -0
- package/src/annot/link.js +77 -0
- package/src/annot/markup.js +91 -0
- package/src/annot/popup.js +53 -0
- package/src/annot/projection.js +52 -0
- package/src/annot/redact.js +87 -0
- package/src/annot/square.js +132 -0
- package/src/annot/stamp.js +48 -0
- package/src/annot/text.js +54 -0
- package/src/annot/widget.js +61 -0
- package/src/associatedFiles/associatedFiles.js +86 -0
- package/src/bundles/pdf-full.js +91 -0
- package/src/bundles/pdf-large.js +81 -0
- package/src/bundles/pdf-legacy.js +107 -0
- package/src/content/color.js +114 -0
- package/src/content/graphics.js +192 -0
- package/src/content/images.js +160 -0
- package/src/content/ops.js +137 -0
- package/src/content/stream.js +154 -0
- package/src/content/text.js +125 -0
- package/src/crypto/aesGcm.js +123 -0
- package/src/crypto/permissions.js +112 -0
- package/src/crypto/security.js +327 -0
- package/src/crypto/standardV4.js +443 -0
- package/src/crypto/standardV5.js +306 -0
- package/src/crypto/standardV6.js +334 -0
- package/src/destination/destination.js +183 -0
- package/src/document/builder.js +618 -0
- package/src/document/catalog.js +100 -0
- package/src/document/document.js +472 -0
- package/src/document/encryptedWriter.js +554 -0
- package/src/document/incrementalWriter.js +514 -0
- package/src/document/page.js +131 -0
- package/src/document/pages.js +103 -0
- package/src/document/resources.js +146 -0
- package/src/document/writer.js +211 -0
- package/src/document/xrefStreamWriter.js +353 -0
- package/src/embedded/collection.js +102 -0
- package/src/embedded/embeddedFile.js +99 -0
- package/src/embedded/fileSpec.js +137 -0
- package/src/errors.js +78 -0
- package/src/extra/3d-richmedia.js +171 -0
- package/src/extra/annot-extended.js +200 -0
- package/src/extra/associated-files.js +131 -0
- package/src/extra/ccitt-fax-decoder.js +776 -0
- package/src/extra/color-spaces-extended.js +196 -0
- package/src/extra/content-ops-extended.js +153 -0
- package/src/extra/document-parts.js +149 -0
- package/src/extra/embedded-files-portfolio.js +234 -0
- package/src/extra/font-cid-typed.js +185 -0
- package/src/extra/font-color-tagging.js +144 -0
- package/src/extra/form-actions-extended.js +196 -0
- package/src/extra/info-dict-deprecated.js +137 -0
- package/src/extra/jbig2-read.js +169 -0
- package/src/extra/legacy-deprecated-annots.js +198 -0
- package/src/extra/legacy-deprecated-filters.js +167 -0
- package/src/extra/legacy-rc4-read.js +235 -0
- package/src/extra/legacy-xfa-read.js +104 -0
- package/src/extra/linearization-write.js +97 -0
- package/src/extra/misc.js +217 -0
- package/src/extra/optional-content-extended.js +142 -0
- package/src/extra/pdf-a-output-intent.js +112 -0
- package/src/extra/pdf-sandbox.js +88 -0
- package/src/extra/pdf-ua-tagged.js +116 -0
- package/src/extra/pdf-x-prepress.js +114 -0
- package/src/extra/redaction-iso32005.js +136 -0
- package/src/extra/shading-typed.js +222 -0
- package/src/extra/sig-aes-gcm.js +135 -0
- package/src/extra/sig-pades.js +242 -0
- package/src/extra/tagged-pdf-typed.js +203 -0
- package/src/extra/transparency-typed.js +135 -0
- package/src/extra/well-tagged-pdf.js +138 -0
- package/src/extra/xmp-extended.js +190 -0
- package/src/font/embed.js +480 -0
- package/src/font/encoding.js +92 -0
- package/src/font/font.js +101 -0
- package/src/font/type3.js +75 -0
- package/src/form/acroform.js +94 -0
- package/src/form/appearance.js +90 -0
- package/src/form/button.js +105 -0
- package/src/form/choice.js +152 -0
- package/src/form/fieldTree.js +120 -0
- package/src/form/signature.js +100 -0
- package/src/form/text.js +101 -0
- package/src/linearization/linearization.js +107 -0
- package/src/main.js +411 -0
- package/src/metadata/info.js +87 -0
- package/src/metadata/xmp.js +62 -0
- package/src/ocg/config.js +156 -0
- package/src/ocg/ocg.js +124 -0
- package/src/outline/outline.js +157 -0
- package/src/pdf.js +133 -0
- package/src/prepress/outputIntent.js +118 -0
- package/src/prepress/pageBoundary.js +108 -0
- package/src/sig/byteRange.js +306 -0
- package/src/sig/certChain.js +247 -0
- package/src/sig/dss.js +317 -0
- package/src/sig/oids.js +157 -0
- package/src/sig/sha1.js +142 -0
- package/src/sig/sign.js +1899 -0
- package/src/sig/signature.js +1441 -0
- package/src/sig/timestamp.js +236 -0
- package/src/syntax/crossRefStream.js +133 -0
- package/src/syntax/filters/ascii85.js +122 -0
- package/src/syntax/filters/asciiHex.js +83 -0
- package/src/syntax/filters/dispatch.js +176 -0
- package/src/syntax/filters/flate.js +316 -0
- package/src/syntax/filters/runLength.js +96 -0
- package/src/syntax/objStream.js +99 -0
- package/src/syntax/parser-obj.js +52 -0
- package/src/syntax/parser.js +321 -0
- package/src/syntax/serializer.js +221 -0
- package/src/syntax/tokenizer.js +290 -0
- package/src/syntax/trailer.js +76 -0
- package/src/syntax/xref.js +341 -0
- package/src/tagged/classMap.js +81 -0
- package/src/tagged/markedContent.js +123 -0
- package/src/tagged/parentTree.js +126 -0
- package/src/tagged/roleMap.js +107 -0
- package/src/tagged/structElement.js +138 -0
- package/src/tagged/structTree.js +94 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
---
|
|
2
|
+
module: pdfLargeBundle
|
|
3
|
+
category: pdf/bundles
|
|
4
|
+
dependencies: [pdf, pdfContentOpsExtended, pdfFontCidTyped, pdfFontColorTagging, pdfTaggedPdfTyped, pdfAnnotExtended, pdfAOutputIntent, pdfUaTagged, pdfFormActionsExtended, pdfColorSpacesExtended, pdfShadingTyped, pdfTransparencyTyped, pdfSigPades, pdfSigAesGcm, pdfDocumentParts, pdfRedactionIso32005, pdfXPrepress, pdfWellTagged, pdfOptionalContentExtended, pdfEmbeddedFilesPortfolio, pdfAssociatedFiles2, pdfXmpExtended]
|
|
5
|
+
returns: object
|
|
6
|
+
worker-safe: true
|
|
7
|
+
status: complete
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# pdfLargeBundle
|
|
11
|
+
|
|
12
|
+
> Core PDF + P0/P1 extras — the common PDF 2.0 features.
|
|
13
|
+
|
|
14
|
+
**Module** `pdfLargeBundle` | **Source** `packages/front/office/pdf/src/bundles/pdf-large.js` | **Deps** `pdf` + the 21 extras enumerated under [Extras wired](#extras-wired) (22 names total, listed literally in the frontmatter `dependencies`) | **Worker-safe** yes
|
|
15
|
+
|
|
16
|
+
A module descriptor that declares the core `pdf` and **21 P0+P1 extras** as dependencies. The runtime supplies the already-constructed instances; the factory wires them into `pdf` via `.use(...)` and returns the enriched instance. Fits most production use where the long tail (PDF 1.7 legacy, deprecated filters, the linearization-dictionary builder) is not required.
|
|
17
|
+
|
|
18
|
+
## Resolve
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
import { ModuleRuntime } from '@awacloud/fw/core/runtime.js';
|
|
22
|
+
import { fw_require, pkg_require, modules, extras, bundle } from '@awacloud/pdf';
|
|
23
|
+
|
|
24
|
+
const rt = new ModuleRuntime();
|
|
25
|
+
for (const m of fw_require) rt.register(m);
|
|
26
|
+
for (const m of pkg_require) rt.register(m);
|
|
27
|
+
for (const m of modules) rt.register(m);
|
|
28
|
+
for (const m of extras) rt.register(m);
|
|
29
|
+
for (const m of bundle) rt.register(m);
|
|
30
|
+
|
|
31
|
+
const api = rt.resolve('pdfLargeBundle');
|
|
32
|
+
const doc = api.read(pdfBytes);
|
|
33
|
+
doc.pages.length;
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`@awacloud/pdf`'s root entry re-exports the **five descriptor arrays** (`fw_require`, `pkg_require`, `modules`, `extras`, `bundle`) plus every `modules` descriptor by binding name. The `extras` and `bundle` descriptors are **not** individually re-exported from the root — `import { pdfLargeBundle } from '@awacloud/pdf'` is `undefined`. Register the arrays as above, or import a single bundle descriptor from its own subpath export:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import { pdfLargeBundle } from '@awacloud/pdf/pdf-large'; // or '@awacloud/pdf/bundles/pdf-large'
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Every dependency listed in `dependencies` must be `register()`ed on the `ModuleRuntime` before `resolve('pdfLargeBundle')` — the runtime resolves by name and throws `Module not found: <name>` if one is missing. Registering all five arrays is the pattern used by the package's own test bootstrap (`tests/_helpers/build.js`); `pdf-large` itself resolves without `fw_require`/`pkg_require` registered, but the sibling bundles do not (see [`pdf-legacy`](./pdf-legacy.md)), so registering all five is the safe default.
|
|
43
|
+
|
|
44
|
+
## API
|
|
45
|
+
|
|
46
|
+
| Export | Description |
|
|
47
|
+
|--------|-------------|
|
|
48
|
+
| `pdfLargeBundle` | Descriptor `{ name, dependencies, factory }`. Resolved by `ModuleRuntime` → `pdf` instance wired with the P0+P1 extras. |
|
|
49
|
+
|
|
50
|
+
The resolved instance is the core `pdf` object (`src/pdf.js`) with the 21 extras merged in — it carries `pdf`'s own 5 members plus one property per wired extra name:
|
|
51
|
+
|
|
52
|
+
| Member | Signature | Description |
|
|
53
|
+
|--------|-----------|--------------|
|
|
54
|
+
| `read` | `(bytes: Uint8Array) => doc` | Full document read. |
|
|
55
|
+
| `header` | `(bytes: Uint8Array) => { version, end }` | Header-only read, no xref/catalog walk. |
|
|
56
|
+
| `write` | `(doc) => Uint8Array` | PDF 2.0 write. |
|
|
57
|
+
| `use` | `(ext) => api` | Extension hook (idempotent by name); this is how the bundle factory wires each extra. |
|
|
58
|
+
| `usedExtension` | `(name: string) => boolean` | Whether an extension name has already been applied via `.use()`. The bundle factory calls `.use({ name, register })` once per wired extra (its own name, e.g. `'pdfSigPades'`), so `api.usedExtension('pdfSigPades')` is `true` right after resolve — `api.usedExtension('pdfLargeBundle')` is `false`, since the bundle's own descriptor name is never itself passed to `.use()`. |
|
|
59
|
+
|
|
60
|
+
## Extras wired
|
|
61
|
+
|
|
62
|
+
| # | Extra | Phase | Status |
|
|
63
|
+
|---|-------|-------|--------|
|
|
64
|
+
| 1 | [`pdfContentOpsExtended`](../extra/content-ops-extended.md) | P0 | read |
|
|
65
|
+
| 2 | [`pdfFontCidTyped`](../extra/font-cid-typed.md) | P0 | read |
|
|
66
|
+
| 3 | [`pdfFontColorTagging`](../extra/font-color-tagging.md) | P0 | read |
|
|
67
|
+
| 4 | [`pdfTaggedPdfTyped`](../extra/tagged-pdf-typed.md) | P0 | read |
|
|
68
|
+
| 5 | [`pdfAnnotExtended`](../extra/annot-extended.md) | P0 | read |
|
|
69
|
+
| 6 | [`pdfAOutputIntent`](../extra/pdf-a-output-intent.md) | P0 | lint |
|
|
70
|
+
| 7 | [`pdfUaTagged`](../extra/pdf-ua-tagged.md) | P0 | lint |
|
|
71
|
+
| 8 | [`pdfFormActionsExtended`](../extra/form-actions-extended.md) | P1 | read |
|
|
72
|
+
| 9 | [`pdfColorSpacesExtended`](../extra/color-spaces-extended.md) | P1 | read |
|
|
73
|
+
| 10 | [`pdfShadingTyped`](../extra/shading-typed.md) | P1 | read |
|
|
74
|
+
| 11 | [`pdfTransparencyTyped`](../extra/transparency-typed.md) | P1 | read |
|
|
75
|
+
| 12 | [`pdfSigPades`](../extra/sig-pades.md) | P1 | read |
|
|
76
|
+
| 13 | [`pdfSigAesGcm`](../extra/sig-aes-gcm.md) | P1 | read |
|
|
77
|
+
| 14 | [`pdfDocumentParts`](../extra/document-parts.md) | P1 | read |
|
|
78
|
+
| 15 | [`pdfRedactionIso32005`](../extra/redaction-iso32005.md) | P1 | read |
|
|
79
|
+
| 16 | [`pdfXPrepress`](../extra/pdf-x-prepress.md) | P1 | lint |
|
|
80
|
+
| 17 | [`pdfWellTagged`](../extra/well-tagged-pdf.md) | P1 | lint |
|
|
81
|
+
| 18 | [`pdfOptionalContentExtended`](../extra/optional-content-extended.md) | P1 | read |
|
|
82
|
+
| 19 | [`pdfEmbeddedFilesPortfolio`](../extra/embedded-files-portfolio.md) | P1 | read |
|
|
83
|
+
| 20 | [`pdfAssociatedFiles2`](../extra/associated-files.md) | P1 | read |
|
|
84
|
+
| 21 | [`pdfXmpExtended`](../extra/xmp-extended.md) | P1 | read |
|
|
85
|
+
|
|
86
|
+
## When to choose
|
|
87
|
+
|
|
88
|
+
- **`pdf-large`** — standard production use, typed PDF 2.0 read/write of the common features. No linearization-dictionary builder, no 3D/RichMedia, no legacy 1.7.
|
|
89
|
+
- `pdf-full` — adds the linearization-dictionary builder, 3D/RichMedia, JBIG2 segment-header read, `/Info` lint, misc tail. Choose it when you need every PDF 2.0 extra.
|
|
90
|
+
- `pdf-legacy` — adds XFA read, RC4 decryption helpers, LZW / CCITT fax decode, Sound/Movie/Screen typing. Choose it for PDF 1.7 reading.
|
|
91
|
+
|
|
92
|
+
## Examples
|
|
93
|
+
|
|
94
|
+
### Read + extra
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
const api = rt.resolve('pdfLargeBundle');
|
|
98
|
+
const doc = api.read(bytes);
|
|
99
|
+
|
|
100
|
+
// Use a wired extra via api.<extName>
|
|
101
|
+
const padesProfile = api.pdfSigPades.detectPadesProfile(sigDict, ctx);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Write
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
const api = rt.resolve('pdfLargeBundle');
|
|
108
|
+
const out = api.write(doc); // PDF 2.0 bytes
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Header only
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
const api = rt.resolve('pdfLargeBundle');
|
|
115
|
+
api.header(bytes); // { version: '2.0', end: <offset> } — no xref/catalog walk
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Checking a wired extra
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
const api = rt.resolve('pdfLargeBundle');
|
|
122
|
+
api.usedExtension('pdfSigPades'); // true — wired by the bundle factory
|
|
123
|
+
api.usedExtension('not-a-real-extra'); // false
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Adding a custom extra
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
const api = rt.resolve('pdfLargeBundle');
|
|
130
|
+
api.use({ name: 'myThing', register(self) { return { myThing: {/* … */} }; } });
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Errors
|
|
134
|
+
|
|
135
|
+
| Code | Class | When |
|
|
136
|
+
|------|--------|------|
|
|
137
|
+
| `pdf/use/bad-extension` | `ContractError` | `.use()` is called with an object missing `name`/`register` (thrown by the core `pdf` orchestrator, not specific to bundles). |
|
|
138
|
+
|
|
139
|
+
## See also
|
|
140
|
+
|
|
141
|
+
- [`pdf-full`](./pdf-full.md)
|
|
142
|
+
- [`pdf-legacy`](./pdf-legacy.md)
|
|
143
|
+
- [Bundles index](./README.md)
|
|
144
|
+
- [Extras index](../extra/README.md)
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
---
|
|
2
|
+
module: pdfLegacyBundle
|
|
3
|
+
category: pdf/bundles
|
|
4
|
+
dependencies: [pdf, pdfContentOpsExtended, pdfFontCidTyped, pdfFontColorTagging, pdfTaggedPdfTyped, pdfAnnotExtended, pdfAOutputIntent, pdfUaTagged, pdfFormActionsExtended, pdfColorSpacesExtended, pdfShadingTyped, pdfTransparencyTyped, pdfSigPades, pdfSigAesGcm, pdfDocumentParts, pdfRedactionIso32005, pdfXPrepress, pdfWellTagged, pdfOptionalContentExtended, pdfEmbeddedFilesPortfolio, pdfAssociatedFiles2, pdfXmpExtended, pdfLinearizationWrite, pdf3dRichMedia, pdfJbig2Read, pdfMisc, pdfInfoDictDeprecated, pdfSandbox, pdfLegacyXfaRead, pdfLegacyRc4Read, pdfLegacyDeprecatedFilters, pdfLegacyDeprecatedAnnots]
|
|
5
|
+
returns: object
|
|
6
|
+
worker-safe: true
|
|
7
|
+
status: complete
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# pdfLegacyBundle
|
|
11
|
+
|
|
12
|
+
> `pdfFullBundle` + the PDF 1.7 legacy readers.
|
|
13
|
+
|
|
14
|
+
**Module** `pdfLegacyBundle` | **Source** `packages/front/office/pdf/src/bundles/pdf-legacy.js` | **Deps** `pdf` + the 31 extras enumerated under [Extras wired](#extras-wired) (32 names total, listed literally in the frontmatter `dependencies`; the `@awacloud/fw` `lzw` binding is a further transitive requirement of `pdfLegacyDeprecatedFilters`, not a direct entry) | **Worker-safe** yes
|
|
15
|
+
|
|
16
|
+
A module descriptor that adds the `legacy-*` extras on top of `pdfFullBundle`:
|
|
17
|
+
|
|
18
|
+
- `legacy-xfa-read` — accepts `/XFA` on read, surfaces it as opaque XML.
|
|
19
|
+
- `legacy-rc4-read` — RC4 v2/v3 password validation + stream decrypt.
|
|
20
|
+
- `legacy-deprecated-filters` — LZWDecode (via the `@awacloud/fw` `lzw` factory), CCITTFaxDecode (a full ITU-T T.4 / T.6 decoder, through `pdfCcittFaxDecoder`), DCT/JPX passthrough. These decoders are called through the extra's own API; they are not registered into `pdfFilterDispatch`, so `read` does not apply them to streams by itself.
|
|
21
|
+
- `legacy-deprecated-annots` — Sound/Movie/Screen typing (read-only; no conversion to RichMedia).
|
|
22
|
+
|
|
23
|
+
`pdfInfoDictDeprecated` (Info dict lint) is already wired by `pdf-full`; `pdf-legacy` re-lists it idempotently.
|
|
24
|
+
|
|
25
|
+
**Writing PDF 1.7 is never supported** — `write` always emits a `%PDF-2.0` header. It does **not** convert legacy content: it re-emits the objects of the model it is given, so an `/XFA` entry, an RC4 `/Encrypt` dictionary, an LZW-filtered stream or a Sound/Movie annotation read from a 1.7 file is written back as it was. Converting it is the caller's work.
|
|
26
|
+
|
|
27
|
+
## Resolve
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import { ModuleRuntime } from '@awacloud/fw/core/runtime.js';
|
|
31
|
+
import { fw_require, pkg_require, modules, extras, bundle } from '@awacloud/pdf';
|
|
32
|
+
|
|
33
|
+
const rt = new ModuleRuntime();
|
|
34
|
+
for (const m of fw_require) rt.register(m); // provides the real `lzw` fw binding
|
|
35
|
+
for (const m of pkg_require) rt.register(m);
|
|
36
|
+
for (const m of modules) rt.register(m);
|
|
37
|
+
for (const m of extras) rt.register(m);
|
|
38
|
+
for (const m of bundle) rt.register(m);
|
|
39
|
+
|
|
40
|
+
const api = rt.resolve('pdfLegacyBundle');
|
|
41
|
+
const doc = api.read(oldPdfBytes); // PDF 1.7 OK
|
|
42
|
+
const out = api.write(doc); // always PDF 2.0
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The `extras` and `bundle` descriptors are **not** re-exported from the package root by binding name — `import { pdfLegacyBundle } from '@awacloud/pdf'` is `undefined`. Register the arrays as above, or import the single descriptor from its own subpath export (`import { pdfLegacyBundle } from '@awacloud/pdf/pdf-legacy';`). Unlike `pdf-large` and `pdf-full`, `pdf-legacy` **cannot** be resolved without `fw_require` registered: omitting it throws `Module not found: lzw`.
|
|
46
|
+
|
|
47
|
+
`pdfLegacyDeprecatedFilters` validates its `lzw` dependency eagerly at construction time — if a stub/invalid binding is registered under the name `lzw` instead of the real `@awacloud/fw/io/compress/lzw.js` export, resolving the bundle throws `pdf/filters/missing-lzw` immediately (not lazily on first decode).
|
|
48
|
+
|
|
49
|
+
## API
|
|
50
|
+
|
|
51
|
+
| Export | Description |
|
|
52
|
+
|--------|-------------|
|
|
53
|
+
| `pdfLegacyBundle` | Descriptor `{ name, dependencies, factory }`. Resolved by `ModuleRuntime` → `pdf` instance wired with every P0-P3 extra + the 4 legacy extras (listed under [Extras wired](#extras-wired)). |
|
|
54
|
+
|
|
55
|
+
The resolved instance is the core `pdf` object (`src/pdf.js`) with the extras merged in — it carries `pdf`'s own 5 members plus one property per wired extra name:
|
|
56
|
+
|
|
57
|
+
| Member | Signature | Description |
|
|
58
|
+
|--------|-----------|--------------|
|
|
59
|
+
| `read` | `(bytes: Uint8Array) => doc` | Full document read (accepts PDF 1.7). |
|
|
60
|
+
| `header` | `(bytes: Uint8Array) => { version, end }` | Header-only read, no xref/catalog walk. |
|
|
61
|
+
| `write` | `(doc) => Uint8Array` | Always PDF 2.0 write. |
|
|
62
|
+
| `use` | `(ext) => api` | Extension hook (idempotent by name); this is how the bundle factory wires each extra. |
|
|
63
|
+
| `usedExtension` | `(name: string) => boolean` | Whether an extension name has already been applied via `.use()`. The bundle factory calls `.use({ name, register })` once per wired extra (e.g. `'pdfLegacyRc4Read'`), so `api.usedExtension('pdfLegacyRc4Read')` is `true` right after resolve — `api.usedExtension('pdfLegacyBundle')` is `false`, since the bundle's own descriptor name is never itself passed to `.use()`. |
|
|
64
|
+
|
|
65
|
+
## Extras wired
|
|
66
|
+
|
|
67
|
+
Items 1-27 are [`pdf-full`](./pdf-full.md)'s extras, re-listed here so every member of the resolved instance is documented on this page; items 28-31 are `pdf-legacy`'s own additions.
|
|
68
|
+
|
|
69
|
+
| # | Extra | Phase | Status |
|
|
70
|
+
|---|-------|-------|--------|
|
|
71
|
+
| 1 | [`pdfContentOpsExtended`](../extra/content-ops-extended.md) | P0 | read |
|
|
72
|
+
| 2 | [`pdfFontCidTyped`](../extra/font-cid-typed.md) | P0 | read |
|
|
73
|
+
| 3 | [`pdfFontColorTagging`](../extra/font-color-tagging.md) | P0 | read |
|
|
74
|
+
| 4 | [`pdfTaggedPdfTyped`](../extra/tagged-pdf-typed.md) | P0 | read |
|
|
75
|
+
| 5 | [`pdfAnnotExtended`](../extra/annot-extended.md) | P0 | read |
|
|
76
|
+
| 6 | [`pdfAOutputIntent`](../extra/pdf-a-output-intent.md) | P0 | lint |
|
|
77
|
+
| 7 | [`pdfUaTagged`](../extra/pdf-ua-tagged.md) | P0 | lint |
|
|
78
|
+
| 8 | [`pdfFormActionsExtended`](../extra/form-actions-extended.md) | P1 | read |
|
|
79
|
+
| 9 | [`pdfColorSpacesExtended`](../extra/color-spaces-extended.md) | P1 | read |
|
|
80
|
+
| 10 | [`pdfShadingTyped`](../extra/shading-typed.md) | P1 | read |
|
|
81
|
+
| 11 | [`pdfTransparencyTyped`](../extra/transparency-typed.md) | P1 | read |
|
|
82
|
+
| 12 | [`pdfSigPades`](../extra/sig-pades.md) | P1 | read |
|
|
83
|
+
| 13 | [`pdfSigAesGcm`](../extra/sig-aes-gcm.md) | P1 | read |
|
|
84
|
+
| 14 | [`pdfDocumentParts`](../extra/document-parts.md) | P1 | read |
|
|
85
|
+
| 15 | [`pdfRedactionIso32005`](../extra/redaction-iso32005.md) | P1 | read |
|
|
86
|
+
| 16 | [`pdfXPrepress`](../extra/pdf-x-prepress.md) | P1 | lint |
|
|
87
|
+
| 17 | [`pdfWellTagged`](../extra/well-tagged-pdf.md) | P1 | lint |
|
|
88
|
+
| 18 | [`pdfOptionalContentExtended`](../extra/optional-content-extended.md) | P1 | read |
|
|
89
|
+
| 19 | [`pdfEmbeddedFilesPortfolio`](../extra/embedded-files-portfolio.md) | P1 | read |
|
|
90
|
+
| 20 | [`pdfAssociatedFiles2`](../extra/associated-files.md) | P1 | read |
|
|
91
|
+
| 21 | [`pdfXmpExtended`](../extra/xmp-extended.md) | P1 | read |
|
|
92
|
+
| 22 | [`pdfLinearizationWrite`](../extra/linearization-write.md) | P2 | write |
|
|
93
|
+
| 23 | [`pdf3dRichMedia`](../extra/3d-richmedia.md) | P2 | read |
|
|
94
|
+
| 24 | [`pdfJbig2Read`](../extra/jbig2-read.md) | P2 | read (partial) |
|
|
95
|
+
| 25 | [`pdfMisc`](../extra/misc.md) | P3 | read |
|
|
96
|
+
| 26 | [`pdfInfoDictDeprecated`](../extra/info-dict-deprecated.md) | P3 | lint |
|
|
97
|
+
| 27 | [`pdfSandbox`](../extra/pdf-sandbox.md) | P3 | opt-in audit hook |
|
|
98
|
+
| 28 | [`pdfLegacyXfaRead`](../extra/legacy-xfa-read.md) | legacy | read-only |
|
|
99
|
+
| 29 | [`pdfLegacyRc4Read`](../extra/legacy-rc4-read.md) | legacy | read-only |
|
|
100
|
+
| 30 | [`pdfLegacyDeprecatedFilters`](../extra/legacy-deprecated-filters.md) | legacy | read (needs the `lzw` + `pdfCcittFaxDecoder` dependencies) |
|
|
101
|
+
| 31 | [`pdfLegacyDeprecatedAnnots`](../extra/legacy-deprecated-annots.md) | legacy | read |
|
|
102
|
+
|
|
103
|
+
`pdfCcittFaxDecoder` (the CCITT Fax decode helper `legacy-deprecated-filters` depends on) is a separate, 32nd module in the package's overall `extras` manifest array, but it is a private sub-dependency here — it is resolved transitively, not wired onto the bundle's own namespace via a `.use()` call, so there is no `api.pdfCcittFaxDecoder`.
|
|
104
|
+
|
|
105
|
+
## When to choose
|
|
106
|
+
|
|
107
|
+
- `pdf-large` — strict PDF 2.0 production minimal.
|
|
108
|
+
- `pdf-full` — strict PDF 2.0 complete.
|
|
109
|
+
- **`pdf-legacy`** — mixed legacy corpus (1.7 + 2.0). Choose it when ingesting older PDFs (XFA, RC4, LZW, Sound/Movie); conversion to PDF 2.0 equivalents is left to the caller.
|
|
110
|
+
|
|
111
|
+
## Examples
|
|
112
|
+
|
|
113
|
+
### Reading an RC4-encrypted PDF 1.7 file
|
|
114
|
+
|
|
115
|
+
`read` refuses an encrypted file (`pdf/document/encrypted`); opt in to the raw
|
|
116
|
+
container, then decrypt with the extra's helpers (see
|
|
117
|
+
[`pdfLegacyRc4Read`](../extra/legacy-rc4-read.md) for the `params` shape):
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
const api = rt.resolve('pdfLegacyBundle');
|
|
121
|
+
const doc = api.read(pdf17Bytes, { allowEncrypted: true }); // strings and streams still ciphertext
|
|
122
|
+
const r = api.pdfLegacyRc4Read.validateUserPassword('', params);
|
|
123
|
+
if (r.ok) {
|
|
124
|
+
const plain = api.pdfLegacyRc4Read.decryptStream(r.fileKey, objNum, gen, streamBytes);
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Reading an XFA form
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
const api = rt.resolve('pdfLegacyBundle');
|
|
132
|
+
const doc = api.read(xfaFormBytes);
|
|
133
|
+
const xfa = api.pdfLegacyXfaRead.readXfa(acroFormDict.entries.XFA);
|
|
134
|
+
// xfa._legacy.xfa: the XDP payload, opaque; api.write(doc) keeps /XFA as it was
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Legacy filter
|
|
138
|
+
|
|
139
|
+
```js
|
|
140
|
+
const plain = api.pdfLegacyDeprecatedFilters.lzwDecode(streamBytes, { EarlyChange: 1 });
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Header only
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
api.header(pdf17Bytes); // { version: '1.7', end: <offset> } — no xref/catalog walk
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Checking a wired extra
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
api.usedExtension('pdfLegacyRc4Read'); // true — wired by the bundle factory
|
|
153
|
+
api.usedExtension('not-a-real-extra'); // false
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Errors
|
|
157
|
+
|
|
158
|
+
| Code | Class | When |
|
|
159
|
+
|------|--------|------|
|
|
160
|
+
| `pdf/use/bad-extension` | `ContractError` | `.use()` is called with an object missing `name`/`register` (thrown by the core `pdf` orchestrator, not specific to bundles). |
|
|
161
|
+
| `pdf/filters/missing-lzw` | `ParseError` | `pdfLegacyDeprecatedFilters` is constructed without a valid `@awacloud/fw` `lzw` factory output (`decode`/`encode` functions). |
|
|
162
|
+
| `pdf/filters/missing-ccitt` | `ParseError` | Same, for a missing/invalid `pdfCcittFaxDecoder` output. |
|
|
163
|
+
|
|
164
|
+
## See also
|
|
165
|
+
|
|
166
|
+
- [`pdf-large`](./pdf-large.md)
|
|
167
|
+
- [`pdf-full`](./pdf-full.md)
|
|
168
|
+
- [Bundles index](./README.md)
|
|
169
|
+
- [Extras index](../extra/README.md)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Content — ISO 32000-2 §7.8 / §8 / §9.3–§9.4
|
|
2
|
+
|
|
3
|
+
Content-stream layer: decoded `Uint8Array` → typed ops → gstate / text / colour
|
|
4
|
+
applied, plus typed XObjects.
|
|
5
|
+
|
|
6
|
+
| Module | Returns | Deps | Description |
|
|
7
|
+
|--------|---------|------|-------------|
|
|
8
|
+
| [`pdfContentOps`](./ops.md) | `{ OPS, OP_NAMES, lookupOp, isOp }` | none | Operator table §8.2 + §9.4. |
|
|
9
|
+
| [`pdfContentStream`](./stream.md) | `{ parseContentStream }` | `pdfErrors`, `pdfParser`, `pdfContentOps` | Bytes → ops §7.8. |
|
|
10
|
+
| [`pdfGraphics`](./graphics.md) | `{ GStateStack, createStack, applyOp, initialGState, mulCtm }` | `pdfErrors` | Graphics-state stack §8.4. |
|
|
11
|
+
| [`pdfText`](./text.md) | `{ setFont, beginTextObject, td, tdSetLeading, setTextMatrix, nextLine, rawStringBytes, extractText }` | `pdfErrors` | Text state + Tm/Tlm §9.3. |
|
|
12
|
+
| [`pdfColor`](./color.md) | `{ applyColorOp }` | `pdfErrors` | Colour §8.6. |
|
|
13
|
+
| [`pdfImages`](./images.md) | `{ typeImageXObject, typeFormXObject, typeXObject }` | `pdfErrors`, `pdfParser` | XObjects §8.9 / §8.10. |
|
|
14
|
+
|
|
15
|
+
## Common pattern
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const cs = runtime.resolve('pdfContentStream');
|
|
19
|
+
const g = runtime.resolve('pdfGraphics');
|
|
20
|
+
const ops = cs.parseContentStream(decodedBytes);
|
|
21
|
+
const stack = g.createStack();
|
|
22
|
+
for (const op of ops) g.applyOp(stack, op);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## See also
|
|
26
|
+
|
|
27
|
+
- [Document layer](../document/README.md) — supplies `pageDict` and Resources.
|
|
28
|
+
- [Font layer](../font/README.md) — feeds `pdfText.extractText`.
|
|
29
|
+
- [Syntax layer](../syntax/README.md) — the underlying `pdfParser`.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
module: pdfColor
|
|
3
|
+
category: pdf/content
|
|
4
|
+
dependencies: [pdfErrors]
|
|
5
|
+
returns: object
|
|
6
|
+
worker-safe: true
|
|
7
|
+
status: complete
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# pdfColor
|
|
11
|
+
|
|
12
|
+
> Applying the colour operators to a graphics state — ISO 32000-2 §8.6.
|
|
13
|
+
|
|
14
|
+
**Module** `pdfColor` | **Source** `packages/front/office/pdf/src/content/color.js` | **Deps** `pdfErrors` | **Worker-safe** yes
|
|
15
|
+
|
|
16
|
+
Mutates `gstate.strokeColor` / `gstate.fillColor` for the 12 PDF colour
|
|
17
|
+
operators: `g`/`G`, `rg`/`RG`, `k`/`K`, `cs`/`CS`, `sc`/`SC`, `scn`/`SCN`.
|
|
18
|
+
Pattern / Separation / DeviceN spaces accept a trailing `/PatternName` on
|
|
19
|
+
`scn`/`SCN` — captured as `gstate.<slot>.pattern`. When `scn`/`SCN` carries no
|
|
20
|
+
trailing name, any previously captured `pattern` is deleted.
|
|
21
|
+
|
|
22
|
+
## Resolve
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
const c = runtime.resolve('pdfColor');
|
|
26
|
+
// Returns: { applyColorOp }
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## API
|
|
30
|
+
|
|
31
|
+
| Method | Signature | Returns |
|
|
32
|
+
|--------|-----------|---------|
|
|
33
|
+
| `applyColorOp` | `(gstate, { op, args }) => void` | Mutates the gstate in place. |
|
|
34
|
+
|
|
35
|
+
### Operator → mutation
|
|
36
|
+
|
|
37
|
+
| Op | Target | Effect |
|
|
38
|
+
|----|--------|--------|
|
|
39
|
+
| `g` / `G` | fill / stroke | `{ space: 'DeviceGray', components: [n] }` |
|
|
40
|
+
| `rg` / `RG` | fill / stroke | `{ space: 'DeviceRGB', components: [r,g,b] }` |
|
|
41
|
+
| `k` / `K` | fill / stroke | `{ space: 'DeviceCMYK', components: [c,m,y,k] }` |
|
|
42
|
+
| `cs` / `CS` | fill / stroke | `{ space: name, components: device default }` |
|
|
43
|
+
| `sc` / `SC` | fill / stroke | replaces `components` only (numeric args kept, others dropped) |
|
|
44
|
+
| `scn` / `SCN` | fill / stroke | `components` plus an optional `pattern` when the last arg is a name |
|
|
45
|
+
|
|
46
|
+
### Defaults per named space
|
|
47
|
+
|
|
48
|
+
| Space | Default `components` |
|
|
49
|
+
|-------|----------------------|
|
|
50
|
+
| `DeviceGray` | `[0]` |
|
|
51
|
+
| `DeviceRGB` | `[0, 0, 0]` |
|
|
52
|
+
| `DeviceCMYK` | `[0, 0, 0, 1]` |
|
|
53
|
+
| any other | `[]` |
|
|
54
|
+
|
|
55
|
+
## Examples
|
|
56
|
+
|
|
57
|
+
### Set the fill colour in RGB
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
const c = runtime.resolve('pdfColor');
|
|
61
|
+
c.applyColorOp(gstate, {
|
|
62
|
+
op: 'rg',
|
|
63
|
+
args: [{type:'real',value:0.8},{type:'real',value:0.2},{type:'real',value:0.1}]
|
|
64
|
+
});
|
|
65
|
+
gstate.fillColor; // { space:'DeviceRGB', components:[0.8,0.2,0.1] }
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Set the stroke space
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
c.applyColorOp(gstate, { op: 'CS', args: [{type:'name',value:'DeviceCMYK'}] });
|
|
72
|
+
gstate.strokeColor; // { space:'DeviceCMYK', components:[0,0,0,1] }
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Pattern through `scn`
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
c.applyColorOp(gstate, {
|
|
79
|
+
op: 'scn',
|
|
80
|
+
args: [{type:'real',value:0.5}, {type:'name',value:'P1'}]
|
|
81
|
+
});
|
|
82
|
+
gstate.fillColor.pattern; // 'P1'
|
|
83
|
+
gstate.fillColor.components; // [0.5]
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Errors
|
|
87
|
+
|
|
88
|
+
| Code | Class | When |
|
|
89
|
+
|------|-------|------|
|
|
90
|
+
| `pdf/color/unknown-op` | `ContractError` | `applyColorOp` called with a non-colour operator. |
|
|
91
|
+
| `pdf/color/bad-name` | `ContractError` | `cs`/`CS` without a `name` argument. |
|
|
92
|
+
| `pdf/color/short-args` | `ContractError` | Fewer numeric arguments than required by `g`/`rg`/`k` and their stroke variants. |
|
|
93
|
+
| `pdf/color/bad-num` | `ContractError` | An argument expected to be numeric has another type. |
|
|
94
|
+
|
|
95
|
+
## See also
|
|
96
|
+
|
|
97
|
+
- [`pdfGraphics`](./graphics.md) — hosts `strokeColor`/`fillColor`.
|
|
98
|
+
- [`pdfContentStream`](./stream.md) — produces the ops.
|
|
99
|
+
- [`pdfContentOps`](./ops.md) — categorisation.
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
---
|
|
2
|
+
module: pdfGraphics
|
|
3
|
+
category: pdf/content
|
|
4
|
+
dependencies: [pdfErrors]
|
|
5
|
+
returns: object
|
|
6
|
+
worker-safe: true
|
|
7
|
+
status: complete
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# pdfGraphics
|
|
11
|
+
|
|
12
|
+
> Graphics-state stack for a content-stream interpreter — ISO 32000-2 §8.4.
|
|
13
|
+
|
|
14
|
+
**Module** `pdfGraphics` | **Source** `packages/front/office/pdf/src/content/graphics.js` | **Deps** `pdfErrors` | **Worker-safe** yes
|
|
15
|
+
|
|
16
|
+
Implements the **device-independent** subset (§8.4.1, Table 53) of the graphics
|
|
17
|
+
state: CTM, line width/cap/join, miter limit, dash pattern, rendering intent,
|
|
18
|
+
flatness — plus the nested `text` sub-tree (driven by [`pdfText`](./text.md))
|
|
19
|
+
and `strokeColor`/`fillColor` (driven by [`pdfColor`](./color.md)). This is
|
|
20
|
+
**not** a renderer: it is a faithful model of the `gstate` chain that the upper
|
|
21
|
+
layers (text extraction, MCID tracking, redaction) consume.
|
|
22
|
+
|
|
23
|
+
## Resolve
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
const g = runtime.resolve('pdfGraphics');
|
|
27
|
+
// Returns: { GStateStack, createStack, applyOp, initialGState, mulCtm }
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## API
|
|
31
|
+
|
|
32
|
+
| Member | Signature | Returns |
|
|
33
|
+
|--------|-----------|---------|
|
|
34
|
+
| `GStateStack` | `new GStateStack()` | Instance, starting from `initialGState`. |
|
|
35
|
+
| `createStack` | `() => GStateStack` | Equivalent helper. |
|
|
36
|
+
| `applyOp` | `(stack, { op, args }, handlers?) => void` | Applies one gstate op. |
|
|
37
|
+
| `initialGState` | `() => object` | Identity-state snapshot. |
|
|
38
|
+
| `mulCtm` | `(a: number[6], b: number[6]) => number[6]` | 2×3 matrix product. |
|
|
39
|
+
|
|
40
|
+
### `GStateStack` methods
|
|
41
|
+
|
|
42
|
+
| Method | Description |
|
|
43
|
+
|--------|-------------|
|
|
44
|
+
| `current()` | Top of stack (mutable). |
|
|
45
|
+
| `save()` | `q` — pushes a deep copy of the sensitive fields. |
|
|
46
|
+
| `restore()` | `Q` — pops; throws `pdf/gstate/unbalanced-Q` on an empty stack. |
|
|
47
|
+
| `depth()` | Current depth (≥ 1). |
|
|
48
|
+
| `concatCtm(matrix)` | `cm` — `ctm = matrix × ctm`. |
|
|
49
|
+
|
|
50
|
+
### `gstate` shape
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
{
|
|
54
|
+
ctm: [1,0,0,1,0,0],
|
|
55
|
+
lineWidth: 1, lineCap: 0, lineJoin: 0,
|
|
56
|
+
miterLimit: 10,
|
|
57
|
+
dash: { array: [], phase: 0 },
|
|
58
|
+
renderingIntent: 'RelativeColorimetric',
|
|
59
|
+
flatness: 1,
|
|
60
|
+
text: { charSpace: 0, wordSpace: 0, scale: 100, leading: 0,
|
|
61
|
+
font: null, fontSize: 0, renderMode: 0, rise: 0 },
|
|
62
|
+
strokeColor: { space: 'DeviceGray', components: [0] },
|
|
63
|
+
fillColor: { space: 'DeviceGray', components: [0] }
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`applyOp` routes only `q`, `Q`, `cm`, `w`, `J`, `j`, `M`, `d`, `ri`, `i`. Any
|
|
68
|
+
other operator falls through to `handlers.unhandled(op, stack)` when supplied.
|
|
69
|
+
|
|
70
|
+
## Examples
|
|
71
|
+
|
|
72
|
+
### Walking a content stream
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
const g = runtime.resolve('pdfGraphics');
|
|
76
|
+
const stack = g.createStack();
|
|
77
|
+
for (const op of ops) {
|
|
78
|
+
g.applyOp(stack, op, {
|
|
79
|
+
unhandled: (o) => {
|
|
80
|
+
if (o.op.startsWith('T')) applyTextOp(stack.current(), o);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Composing CTMs
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
const scale = [2, 0, 0, 2, 0, 0];
|
|
90
|
+
const translate = [1, 0, 0, 1, 100, 50];
|
|
91
|
+
const ctm = g.mulCtm(scale, translate);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Detecting an unbalanced stack
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
try { g.applyOp(stack, { op: 'Q', args: [] }); }
|
|
98
|
+
catch (e) { if (e.code === 'pdf/gstate/unbalanced-Q') { /* … */ } }
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Errors
|
|
102
|
+
|
|
103
|
+
| Code | Class | When |
|
|
104
|
+
|------|-------|------|
|
|
105
|
+
| `pdf/gstate/unbalanced-Q` | `ContractError` | `Q` without a matching `q`. |
|
|
106
|
+
| `pdf/gstate/bad-cm` | `ContractError` | `cm` matrix is not 6 elements. |
|
|
107
|
+
| `pdf/gstate/bad-arg-type` | `ContractError` | Non-numeric argument for `w`, `J`, `j`, `M`, `i`. |
|
|
108
|
+
| `pdf/gstate/bad-name-arg` | `ContractError` | Non-`name` argument for `ri`. |
|
|
109
|
+
|
|
110
|
+
## See also
|
|
111
|
+
|
|
112
|
+
- [`pdfContentStream`](./stream.md) — produces the op list.
|
|
113
|
+
- [`pdfText`](./text.md) — the nested text state.
|
|
114
|
+
- [`pdfColor`](./color.md) — `strokeColor` / `fillColor`.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
---
|
|
2
|
+
module: pdfImages
|
|
3
|
+
category: pdf/content
|
|
4
|
+
dependencies: [pdfErrors, pdfParser]
|
|
5
|
+
returns: object
|
|
6
|
+
worker-safe: true
|
|
7
|
+
status: complete
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# pdfImages
|
|
11
|
+
|
|
12
|
+
> Typing of XObjects (Image + Form) — ISO 32000-2 §8.9 / §8.10.
|
|
13
|
+
|
|
14
|
+
**Module** `pdfImages` | **Source** `packages/front/office/pdf/src/content/images.js` | **Deps** `pdfErrors`, `pdfParser` | **Worker-safe** yes
|
|
15
|
+
|
|
16
|
+
Types an XObject stream into a flat, ready-to-consume structure. It
|
|
17
|
+
distinguishes:
|
|
18
|
+
|
|
19
|
+
- **Image XObject** (`/Subtype /Image`, §8.9) — carries Width, Height,
|
|
20
|
+
ColorSpace, BitsPerComponent, Filter, DecodeParms, Decode, ImageMask, Mask,
|
|
21
|
+
SMask, Interpolate, Intent, Metadata.
|
|
22
|
+
- **Form XObject** (`/Subtype /Form`, §8.10) — carries FormType, BBox, Matrix,
|
|
23
|
+
Resources, Group, Metadata, StructParent(s).
|
|
24
|
+
|
|
25
|
+
The `raw` bytes are passed through **untouched**: it is the consumer's job
|
|
26
|
+
(renderer) to decode the `/Filter` chain via `pdfFilterDispatch`.
|
|
27
|
+
|
|
28
|
+
## Resolve
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
const im = runtime.resolve('pdfImages');
|
|
32
|
+
// Returns: { typeImageXObject, typeFormXObject, typeXObject }
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
| Method | Signature | Returns |
|
|
38
|
+
|--------|-----------|---------|
|
|
39
|
+
| `typeImageXObject` | `(stream) => ImageXObject` | Image typing. |
|
|
40
|
+
| `typeFormXObject` | `(stream) => FormXObject` | Form typing. |
|
|
41
|
+
| `typeXObject` | `(stream) => ImageXObject \| FormXObject \| Opaque` | Dispatch on `/Subtype`. |
|
|
42
|
+
|
|
43
|
+
### `ImageXObject` shape
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
{
|
|
47
|
+
kind: 'image',
|
|
48
|
+
width, height,
|
|
49
|
+
bitsPerComponent, // int or null
|
|
50
|
+
colorSpace, filter, decodeParms, decode, // raw typed objects or null
|
|
51
|
+
imageMask, // boolean, default false
|
|
52
|
+
mask, sMask,
|
|
53
|
+
interpolate, // boolean, default false
|
|
54
|
+
intent, // name or null
|
|
55
|
+
metadata,
|
|
56
|
+
raw: Uint8Array, dict
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### `FormXObject` shape
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
{
|
|
64
|
+
kind: 'form',
|
|
65
|
+
formType: 1, // /FormType, default 1
|
|
66
|
+
bbox: [llx,lly,urx,ury] | null,
|
|
67
|
+
matrix: [1,0,0,1,0,0], // default
|
|
68
|
+
resources, group, metadata,
|
|
69
|
+
structParents, structParent, // ints or null
|
|
70
|
+
raw: Uint8Array, dict
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
When `/Subtype` is neither `Image` nor `Form` (e.g. the PostScript XObject
|
|
75
|
+
deprecated in PDF 2.0), `typeXObject` returns `{ kind: <subtype>, raw, dict }`.
|
|
76
|
+
|
|
77
|
+
## Examples
|
|
78
|
+
|
|
79
|
+
### Type an XObject invoked by `Do`
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
const im = runtime.resolve('pdfImages');
|
|
83
|
+
const xobjName = op.args[0].value; // 'Im1'
|
|
84
|
+
const stream = doc._raw.resolve(resources.XObject[xobjName]);
|
|
85
|
+
const typed = im.typeXObject(stream);
|
|
86
|
+
if (typed.kind === 'image') console.log(typed.width, typed.height);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Type an image directly
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
const img = im.typeImageXObject(stream);
|
|
93
|
+
img.colorSpace; // typed name / array / ref
|
|
94
|
+
img.filter; // typed name / array
|
|
95
|
+
img.raw; // Uint8Array — feed to pdfFilterDispatch
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Form XObject with a BBox
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
const form = im.typeFormXObject(stream);
|
|
102
|
+
form.bbox; // [0, 0, 612, 792]
|
|
103
|
+
form.matrix; // [1, 0, 0, 1, 0, 0]
|
|
104
|
+
form.resources; // dict — pass to typeResources
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Errors
|
|
108
|
+
|
|
109
|
+
| Code | Class | When |
|
|
110
|
+
|------|-------|------|
|
|
111
|
+
| `pdf/image/not-stream` | `ParseError` | Argument is not a typed stream. |
|
|
112
|
+
| `pdf/image/wrong-subtype` | `ParseError` | `/Subtype` present but not `/Image`. |
|
|
113
|
+
| `pdf/image/missing-dim` | `ParseError` | `/Width` or `/Height` missing. |
|
|
114
|
+
| `pdf/form-xobj/not-stream` | `ParseError` | Argument is not a typed stream. |
|
|
115
|
+
| `pdf/form-xobj/wrong-subtype` | `ParseError` | `/Subtype` present but not `/Form`. |
|
|
116
|
+
| `pdf/xobject/not-stream` | `ParseError` | Argument is not a typed stream. |
|
|
117
|
+
| `pdf/xobject/bad-type` | `ParseError` | `/Type` present but not `/XObject`. |
|
|
118
|
+
| `pdf/xobject/missing-subtype` | `ParseError` | `/Subtype` missing. |
|
|
119
|
+
|
|
120
|
+
## See also
|
|
121
|
+
|
|
122
|
+
- [`pdfContentStream`](./stream.md) — emits the `Do` op.
|
|
123
|
+
- [`pdfResources`](../document/resources.md) — resolves the named `/XObject`.
|
|
124
|
+
- [Filters](../syntax/filters/README.md) — decoding `raw`.
|