@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,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
module: pdfInfo
|
|
3
|
+
category: pdf/metadata
|
|
4
|
+
dependencies: [pdfErrors, pdfParser]
|
|
5
|
+
returns: object
|
|
6
|
+
worker-safe: true
|
|
7
|
+
status: complete
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# pdfInfo
|
|
11
|
+
|
|
12
|
+
> Document Information dictionary — ISO 32000-2 §14.3.3.
|
|
13
|
+
|
|
14
|
+
**Module** `pdfInfo` | **Source** `packages/front/office/pdf/src/metadata/info.js` | **Deps** `pdfErrors`, `pdfParser` | **Worker-safe** yes
|
|
15
|
+
|
|
16
|
+
The trailer's `/Info` entry carries legacy metadata: `/Title`, `/Author`, `/Subject`, `/Keywords`, `/Creator`, `/Producer`, `/CreationDate`, `/ModDate`, `/Trapped` (`True`/`False`/`Unknown`). PDF 2.0 deprecates it in favour of XMP (Catalog `/Metadata`), but `/Info` remains common. **Dates are returned as the raw PDF date string** (`D:YYYYMMDDHHmmSSOHH'mm'`) — `typeInfo` does not parse them into `Date` objects; the caller parses the string if it needs a `Date`.
|
|
17
|
+
|
|
18
|
+
## Resolve
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
const info = runtime.resolve('pdfInfo');
|
|
22
|
+
// Returns: { typeInfo }
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## API
|
|
26
|
+
|
|
27
|
+
| Method | Signature | Returns |
|
|
28
|
+
|---------|-----------|----------|
|
|
29
|
+
| `typeInfo` | `(dict) => Info` | Typing. |
|
|
30
|
+
|
|
31
|
+
### Shape `Info`
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
{
|
|
35
|
+
title, author, subject, keywords, creator, producer, // strings
|
|
36
|
+
creationDate: string | undefined, // raw D:YYYYMMDDHHmmSSOHH'mm', unparsed
|
|
37
|
+
modDate: string | undefined, // raw D:YYYYMMDDHHmmSSOHH'mm', unparsed
|
|
38
|
+
trapped: 'True' | 'False' | 'Unknown' | undefined,
|
|
39
|
+
raw, _extras
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Examples
|
|
44
|
+
|
|
45
|
+
### Reading the trailer's Info
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
const info = runtime.resolve('pdfInfo').typeInfo(doc._raw.resolve(trailer.info));
|
|
49
|
+
info.title;
|
|
50
|
+
info.creationDate; // 'D:20260115120000+01\'00\'' — raw, parse it yourself
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Prepress check
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
if (info.trapped !== 'True') console.warn('document not trapped');
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Errors
|
|
60
|
+
|
|
61
|
+
| Code | Class | When |
|
|
62
|
+
|------|--------|------|
|
|
63
|
+
| `pdf/info/not-dict` | `ParseError` | Argument is not a dict. |
|
|
64
|
+
| `pdf/info/bad-string` | `ParseError` | A text field is not a string. |
|
|
65
|
+
| `pdf/info/bad-date` | `ParseError` | `/CreationDate`/`/ModDate` is not a string. |
|
|
66
|
+
| `pdf/info/bad-trapped` | `ParseError` | `/Trapped` is outside the allowed set. |
|
|
67
|
+
|
|
68
|
+
## See also
|
|
69
|
+
|
|
70
|
+
- [`pdfXmp`](./xmp.md) · [`pdfTrailer`](../syntax/trailer.md)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
module: pdfXmp
|
|
3
|
+
category: pdf/metadata
|
|
4
|
+
dependencies: [pdfErrors, pdfParser]
|
|
5
|
+
returns: object
|
|
6
|
+
worker-safe: true
|
|
7
|
+
status: complete
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# pdfXmp
|
|
11
|
+
|
|
12
|
+
> XMP Metadata stream — ISO 32000-2 §14.3.2 / ISO 16684-1 (XMP).
|
|
13
|
+
|
|
14
|
+
**Module** `pdfXmp` | **Source** `packages/front/office/pdf/src/metadata/xmp.js` | **Deps** `pdfErrors`, `pdfParser` | **Worker-safe** yes
|
|
15
|
+
|
|
16
|
+
The Catalog may carry `/Metadata`, pointing to a stream `/Type /Metadata /Subtype /XML`. The content is an XMP (RDF/XML) packet. This module validates the stream's conformance (`/Type`, `/Subtype`, dict presence) and exposes the raw bytes; parsing the XML/RDF itself is left to the caller (no XML dependency embedded).
|
|
17
|
+
|
|
18
|
+
## Resolve
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
const xmp = runtime.resolve('pdfXmp');
|
|
22
|
+
// Returns: { typeXmpStream }
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## API
|
|
26
|
+
|
|
27
|
+
| Method | Signature | Returns |
|
|
28
|
+
|---------|-----------|----------|
|
|
29
|
+
| `typeXmpStream` | `(stream) => { type: 'Metadata', subtype: 'XML', bytes: Uint8Array, raw: PdfStream }` | Validation + extraction. |
|
|
30
|
+
|
|
31
|
+
## Examples
|
|
32
|
+
|
|
33
|
+
### Extracting the packet text
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
const xmp = runtime.resolve('pdfXmp').typeXmpStream(
|
|
37
|
+
doc._raw.resolve(catalog.metadata)
|
|
38
|
+
);
|
|
39
|
+
const xml = new TextDecoder('utf-8').decode(xmp.bytes);
|
|
40
|
+
// → '<?xpacket begin=…?><x:xmpmeta …>…'
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Common XMP fields
|
|
44
|
+
|
|
45
|
+
An XMP packet typically carries:
|
|
46
|
+
- `dc:title`, `dc:creator`, `dc:description` (Dublin Core).
|
|
47
|
+
- `xmp:CreateDate`, `xmp:ModifyDate`, `xmp:CreatorTool`.
|
|
48
|
+
- `pdf:Producer`, `pdf:Keywords`.
|
|
49
|
+
- `pdfaid:part` / `pdfuaid:part` (PDF/A and PDF/UA conformance).
|
|
50
|
+
|
|
51
|
+
## Errors
|
|
52
|
+
|
|
53
|
+
| Code | Class | When |
|
|
54
|
+
|------|--------|------|
|
|
55
|
+
| `pdf/xmp/not-stream` | `ParseError` | Argument is not a stream. |
|
|
56
|
+
| `pdf/xmp/no-dict` | `ParseError` | Stream has no dict. |
|
|
57
|
+
| `pdf/xmp/bad-type` | `ParseError` | `/Type` is not `/Metadata`. |
|
|
58
|
+
| `pdf/xmp/bad-subtype` | `ParseError` | `/Subtype` is not `/XML`. |
|
|
59
|
+
|
|
60
|
+
## See also
|
|
61
|
+
|
|
62
|
+
- [`pdfInfo`](./info.md) · [`pdfCatalog`](../document/catalog.md)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Optional Content (Layers) — ISO 32000-2 §8.11
|
|
2
|
+
|
|
3
|
+
Optional layers — conditional visibility of content.
|
|
4
|
+
|
|
5
|
+
| Module | Returns | Deps | Description |
|
|
6
|
+
|--------|----------|------|-------------|
|
|
7
|
+
| [`pdfOCG`](./ocg.md) | `{ typeOCG, typeUsage }` | `pdfErrors`, `pdfParser` | OCG dict §8.11.2. |
|
|
8
|
+
| [`pdfOCConfig`](./config.md) | `{ typeOCConfig, typeUsageApp }` | `pdfErrors`, `pdfParser` | OC Configuration §8.11.4. |
|
|
9
|
+
|
|
10
|
+
## Read pattern
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
const ocg = runtime.resolve('pdfOCG');
|
|
14
|
+
const cfg = runtime.resolve('pdfOCConfig');
|
|
15
|
+
const props = catalog.ocProperties;
|
|
16
|
+
const groups = props.entries.OCGs.items.map(ref => ocg.typeOCG(resolveRef(ref)));
|
|
17
|
+
const defaultCfg = cfg.typeOCConfig(resolveRef(props.entries.D));
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## See also
|
|
21
|
+
|
|
22
|
+
- [Catalog](../document/catalog.md) — `/OCProperties`.
|
|
23
|
+
- [Content streams](../content/README.md) — `BMC /OC … EMC`.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
---
|
|
2
|
+
module: pdfOCConfig
|
|
3
|
+
category: pdf/ocg
|
|
4
|
+
dependencies: [pdfErrors, pdfParser]
|
|
5
|
+
returns: object
|
|
6
|
+
worker-safe: true
|
|
7
|
+
status: complete
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# pdfOCConfig
|
|
11
|
+
|
|
12
|
+
> Optional Content Configuration — ISO 32000-2 §8.11.4.
|
|
13
|
+
|
|
14
|
+
**Module** `pdfOCConfig` | **Source** `packages/front/office/pdf/src/ocg/config.js` | **Deps** `pdfErrors`, `pdfParser` | **Worker-safe** yes
|
|
15
|
+
|
|
16
|
+
Types the OC configuration dict referenced by `/OCProperties /D` (default config) or an entry of `/OCProperties /Configs`. Entries: `/Name`, `/Creator`, `/BaseState` (`ON`/`OFF`/`Unchanged`), `/ON` (refs forced visible), `/OFF` (refs forced hidden), `/Locked` (refs the user cannot toggle), `/Intent` (a name or array of names), `/AS` (auto-state — array of UsageApplication dicts), `/Order` (display tree for viewers, kept raw), `/ListMode` (`AllPages`/`VisiblePages`), `/RBGroups` (radio-button groups).
|
|
17
|
+
|
|
18
|
+
## Resolve
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
const cfg = runtime.resolve('pdfOCConfig');
|
|
22
|
+
// Returns: { typeOCConfig, typeUsageApp }
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## API
|
|
26
|
+
|
|
27
|
+
| Method | Signature | Returns |
|
|
28
|
+
|---------|-----------|----------|
|
|
29
|
+
| `typeOCConfig` | `(dict) => OCConfig` | Typing. |
|
|
30
|
+
| `typeUsageApp` | `(d) => UsageApplication` | Typing of one `/AS[*]` entry. |
|
|
31
|
+
|
|
32
|
+
### Shape `OCConfig`
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
{
|
|
36
|
+
name?, creator?,
|
|
37
|
+
baseState?: 'ON' | 'OFF' | 'Unchanged',
|
|
38
|
+
on?: PdfRef[], off?: PdfRef[], locked?: PdfRef[],
|
|
39
|
+
intent?: string[],
|
|
40
|
+
as?: UsageApplication[],
|
|
41
|
+
order?: PdfNode[], // /Order items, kept raw
|
|
42
|
+
listMode?: string,
|
|
43
|
+
rbGroups?: PdfRef[][],
|
|
44
|
+
raw, _extras
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Shape `UsageApplication`
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
{ event?: string, ocgs?: PdfRef[], category?: string[], raw }
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Examples
|
|
55
|
+
|
|
56
|
+
### Default configuration
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
const cfg = runtime.resolve('pdfOCConfig');
|
|
60
|
+
const c = cfg.typeOCConfig(doc._raw.resolve(catalog.ocProperties.entries.D));
|
|
61
|
+
c.baseState; // 'ON'
|
|
62
|
+
c.on; // [ref, …] forced ON
|
|
63
|
+
c.rbGroups; // mutually-exclusive groups
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Applying UsageApplication entries
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
for (const uaDict of c.as ?? []) {
|
|
70
|
+
const ua = cfg.typeUsageApp(uaDict);
|
|
71
|
+
ua.event; // 'View' | 'Print' | 'Export'
|
|
72
|
+
ua.ocgs; // refs this application applies to
|
|
73
|
+
ua.category; // ['Zoom', …]
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Errors
|
|
78
|
+
|
|
79
|
+
| Code | Class | When |
|
|
80
|
+
|------|--------|------|
|
|
81
|
+
| `pdf/ocg/config/not-dict` | `ParseError` | Argument is not a dict. |
|
|
82
|
+
| `pdf/ocg/config/bad-name` | `ParseError` | `/Name` is not a string. |
|
|
83
|
+
| `pdf/ocg/config/bad-creator` | `ParseError` | `/Creator` is not a string. |
|
|
84
|
+
| `pdf/ocg/config/bad-base-state` | `ParseError` | `/BaseState` outside `ON`/`OFF`/`Unchanged`. |
|
|
85
|
+
| `pdf/ocg/config/bad-intent` | `ParseError` | `/Intent` is neither a name nor an array. |
|
|
86
|
+
| `pdf/ocg/config/bad-as` | `ParseError` | `/AS` is not an array. |
|
|
87
|
+
| `pdf/ocg/config/bad-order` | `ParseError` | `/Order` is not an array. |
|
|
88
|
+
| `pdf/ocg/config/bad-list-mode` | `ParseError` | `/ListMode` is not a name. |
|
|
89
|
+
| `pdf/ocg/config/bad-rb` | `ParseError` | `/RBGroups` is not an array. |
|
|
90
|
+
| `pdf/ocg/config/bad-refs` | `ParseError` | `/ON`/`/OFF`/`/Locked` is not an array. |
|
|
91
|
+
| `pdf/ocg/config/as/not-dict` | `ParseError` | An `/AS` entry is not a dict. |
|
|
92
|
+
|
|
93
|
+
## See also
|
|
94
|
+
|
|
95
|
+
- [`pdfOCG`](./ocg.md) · [`pdfCatalog`](../document/catalog.md)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
---
|
|
2
|
+
module: pdfOCG
|
|
3
|
+
category: pdf/ocg
|
|
4
|
+
dependencies: [pdfErrors, pdfParser]
|
|
5
|
+
returns: object
|
|
6
|
+
worker-safe: true
|
|
7
|
+
status: complete
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# pdfOCG
|
|
11
|
+
|
|
12
|
+
> Optional Content Group — ISO 32000-2 §8.11.2.
|
|
13
|
+
|
|
14
|
+
**Module** `pdfOCG` | **Source** `packages/front/office/pdf/src/ocg/ocg.js` | **Deps** `pdfErrors`, `pdfParser` | **Worker-safe** yes
|
|
15
|
+
|
|
16
|
+
Types a `/Type /OCG` dict — a named optional (togglable) layer. Entries: `/Name` (required string), `/Intent` (a name or an array of names — e.g. `View`, `Design`), `/Usage` (sub-dict — `CreatorInfo`, `Language`, `Export`, `Zoom`, `Print`, `View`, `User`, `PageElement`, plus the state convenience entries `ViewState`/`PrintState`/`ExportState`). `typeUsage` decodes that sub-dict separately.
|
|
17
|
+
|
|
18
|
+
## Resolve
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
const ocg = runtime.resolve('pdfOCG');
|
|
22
|
+
// Returns: { typeOCG, typeUsage }
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## API
|
|
26
|
+
|
|
27
|
+
| Method | Signature | Returns |
|
|
28
|
+
|---------|-----------|----------|
|
|
29
|
+
| `typeOCG` | `(dict) => { name, intent?, usage?, raw, _extras }` | OCG dict. |
|
|
30
|
+
| `typeUsage` | `(dict) => Usage` | The `/Usage` sub-dict. |
|
|
31
|
+
|
|
32
|
+
### Shape `Usage`
|
|
33
|
+
|
|
34
|
+
`typeUsage` decodes the three `*State` entries into plain name strings; every other known `/Usage` entry (`creatorInfo`, `language`, `export`, `zoom`, `print`, `view`, `user`, `pageElement`) is copied through **as its raw parsed node** (still a `{ type: 'dict', entries: {...} }` object, not further typed) — callers that need its fields must read `entries` themselves.
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
{
|
|
38
|
+
creatorInfo?, language?, export?, zoom?, print?, view?, user?, pageElement?, // raw nodes
|
|
39
|
+
viewState?: string, printState?: string, exportState?: string, // decoded names
|
|
40
|
+
raw, _extras
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Examples
|
|
45
|
+
|
|
46
|
+
### Reading an OCG
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
const ocg = runtime.resolve('pdfOCG');
|
|
50
|
+
const g = ocg.typeOCG(doc._raw.resolve(ocgRef));
|
|
51
|
+
g.name; // 'Layer 1'
|
|
52
|
+
g.intent; // ['View', 'Design']
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Visibility state
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
const u = ocg.typeUsage(g.usage);
|
|
59
|
+
u.viewState === 'ON'; // decoded convenience state
|
|
60
|
+
u.zoom?.entries?.min?.value; // /Zoom kept raw — read its entries directly
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Errors
|
|
64
|
+
|
|
65
|
+
| Code | Class | When |
|
|
66
|
+
|------|--------|------|
|
|
67
|
+
| `pdf/ocg/not-dict` | `ParseError` | Argument is not a dict. |
|
|
68
|
+
| `pdf/ocg/bad-type` | `ParseError` | `/Type` is not `/OCG`. |
|
|
69
|
+
| `pdf/ocg/missing-name` | `ParseError` | `/Name` absent or not a string. |
|
|
70
|
+
| `pdf/ocg/bad-usage` | `ParseError` | `/Usage` is not a dict. |
|
|
71
|
+
| `pdf/ocg/usage/not-dict` | `ParseError` | `typeUsage` receives a non-dict. |
|
|
72
|
+
| `pdf/ocg/usage/bad-state` | `ParseError` | `/ViewState`, `/PrintState` or `/ExportState` is not a name. |
|
|
73
|
+
|
|
74
|
+
## See also
|
|
75
|
+
|
|
76
|
+
- [`pdfOCConfig`](./config.md) — OC configuration.
|
|
77
|
+
- [`pdfCatalog`](../document/catalog.md) — `/OCProperties`.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Outline — ISO 32000-2 §12.3.3
|
|
2
|
+
|
|
3
|
+
Bookmarks / navigable table of contents.
|
|
4
|
+
|
|
5
|
+
| Module | Returns | Deps | Description |
|
|
6
|
+
|--------|----------|------|-------------|
|
|
7
|
+
| [`pdfOutline`](./outline.md) | `{ walkOutline, typeOutlineItem }` | `pdfErrors`, `pdfParser` | §12.3.3 — flat depth-first walk. |
|
|
8
|
+
|
|
9
|
+
## See also
|
|
10
|
+
|
|
11
|
+
- [Destination](../destination/README.md) · [Action](../action/README.md)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
module: pdfOutline
|
|
3
|
+
category: pdf/outline
|
|
4
|
+
dependencies: [pdfErrors, pdfParser]
|
|
5
|
+
returns: object
|
|
6
|
+
worker-safe: true
|
|
7
|
+
status: complete
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# pdfOutline
|
|
11
|
+
|
|
12
|
+
> Document outline (bookmarks) — ISO 32000-2 §12.3.3.
|
|
13
|
+
|
|
14
|
+
**Module** `pdfOutline` | **Source** `packages/front/office/pdf/src/outline/outline.js` | **Deps** `pdfErrors`, `pdfParser` | **Worker-safe** yes
|
|
15
|
+
|
|
16
|
+
The outline (Catalog `/Outlines`) is a doubly-linked tree. Each item carries `/Title`, `/Parent`, `/Prev`, `/Next`, `/First`, `/Last`, `/Count` (signed — negative means collapsed), `/A` (action) or `/Dest`, `/C` (RGB colour), `/F` (style flags: 1 italic, 2 bold). `/SE` (structure element) is accepted but not decoded (kept in `_extras`). `walkOutline` walks the tree depth-first, enforcing a depth limit and detecting cycles.
|
|
17
|
+
|
|
18
|
+
**`walkOutline` returns a flat array, not a nested tree** — there is no `children` field. Each record keeps its `parent`/`prev`/`next`/`first`/`last` entries as unresolved refs (`{ type: 'ref', num, gen }`); build a tree from the flat list yourself if you need one (e.g. by indexing records by `ref.num`).
|
|
19
|
+
|
|
20
|
+
## Resolve
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
const out = runtime.resolve('pdfOutline');
|
|
24
|
+
// Returns: { walkOutline, typeOutlineItem }
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## API
|
|
28
|
+
|
|
29
|
+
| Method | Signature | Returns |
|
|
30
|
+
|---------|-----------|----------|
|
|
31
|
+
| `walkOutline` | `(rootDict, resolveRef, opts?) => OutlineItem[]` | Flat depth-first list. |
|
|
32
|
+
| `typeOutlineItem` | `(dict) => OutlineItem` | Single item, refs left unresolved. |
|
|
33
|
+
|
|
34
|
+
`opts`: `{ maxDepth = 64, maxItems = 100000 }`.
|
|
35
|
+
|
|
36
|
+
### Shape `OutlineItem`
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
{
|
|
40
|
+
title: string,
|
|
41
|
+
parent?, prev?, next?, first?, last?, // { type: 'ref', num, gen } — unresolved
|
|
42
|
+
count?: number, // signed
|
|
43
|
+
action?, // /A, kept raw
|
|
44
|
+
dest?, // /Dest, kept raw
|
|
45
|
+
color?: [r, g, b], // /C, 3 numbers
|
|
46
|
+
F?: number, // style flags
|
|
47
|
+
ref?: { num, gen }, // set by walkOutline only
|
|
48
|
+
raw, _extras
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Examples
|
|
53
|
+
|
|
54
|
+
### Full walk (flat list)
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
const out = runtime.resolve('pdfOutline');
|
|
58
|
+
const root = doc._raw.resolve(doc.catalog.outlines);
|
|
59
|
+
const items = out.walkOutline(root, doc._raw.resolve);
|
|
60
|
+
for (const it of items) console.log(it.title);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Rebuilding a tree from the flat list
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
const byNum = new Map(items.map(it => [it.ref.num, it]));
|
|
67
|
+
function children(it) {
|
|
68
|
+
const kids = [];
|
|
69
|
+
let cur = it.first;
|
|
70
|
+
while (cur) {
|
|
71
|
+
const child = byNum.get(cur.num);
|
|
72
|
+
if (!child) break;
|
|
73
|
+
kids.push(child);
|
|
74
|
+
cur = child.next;
|
|
75
|
+
}
|
|
76
|
+
return kids;
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Navigating from an item
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
if (item.dest) {
|
|
84
|
+
const d = runtime.resolve('pdfDestination')
|
|
85
|
+
.typeDestination(item.dest, catalog.names?.entries?.Dests, resolveRef);
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Errors
|
|
90
|
+
|
|
91
|
+
| Code | Class | When |
|
|
92
|
+
|------|--------|------|
|
|
93
|
+
| `pdf/outline/not-dict` | `ParseError` | Root or resolved item is not a dict. |
|
|
94
|
+
| `pdf/outline/bad-first` | `ParseError` | `/First` is not a ref. |
|
|
95
|
+
| `pdf/outline/no-resolver` | `ParseError` | `resolveRef` not supplied. |
|
|
96
|
+
| `pdf/outline/max-depth` | `ParseError` | Depth exceeds `opts.maxDepth`. |
|
|
97
|
+
| `pdf/outline/non-ref-sibling` | `ParseError` | A sibling entry is not a ref. |
|
|
98
|
+
| `pdf/outline/cycle` | `ParseError` | An item was visited twice. |
|
|
99
|
+
| `pdf/outline/too-many` | `ParseError` | Item count exceeds `opts.maxItems`. |
|
|
100
|
+
| `pdf/outline/runaway` | `ParseError` | Sibling chain exceeds the item cap (infinite-loop guard). |
|
|
101
|
+
| `pdf/outline/item/not-dict` | `ParseError` | `typeOutlineItem` receives a non-dict. |
|
|
102
|
+
| `pdf/outline/missing-title` | `ParseError` | `/Title` absent. |
|
|
103
|
+
|
|
104
|
+
## See also
|
|
105
|
+
|
|
106
|
+
- [`pdfDestination`](../destination/destination.md) · [`pdfAction`](../action/action.md)
|
|
107
|
+
- [`pdfCatalog`](../document/catalog.md)
|
package/docs/api/pdf.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
---
|
|
2
|
+
module: pdf
|
|
3
|
+
category: pdf
|
|
4
|
+
dependencies: [pdfErrors, pdfShared, pdfTokenizer, pdfParserObj, pdfParser, pdfXref, pdfTrailer, pdfSerializer, pdfCatalog, pdfPages, pdfPage, pdfDocument, pdfWriter]
|
|
5
|
+
returns: object
|
|
6
|
+
worker-safe: true
|
|
7
|
+
status: complete
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# pdf
|
|
11
|
+
|
|
12
|
+
> Top-level public orchestrator — `read`, `header`, `write`, and the `.use()` extension hook.
|
|
13
|
+
|
|
14
|
+
**Module** `pdf` | **Source** `packages/front/office/pdf/src/pdf.js` | **Deps** `pdfErrors`, `pdfShared`, `pdfTokenizer`, `pdfParserObj`, `pdfParser`, `pdfXref`, `pdfTrailer`, `pdfSerializer`, `pdfCatalog`, `pdfPages`, `pdfPage`, `pdfDocument`, `pdfWriter` | **Worker-safe** yes
|
|
15
|
+
|
|
16
|
+
The syntax + document layers are declared as `dependencies[]` and received as positional factory parameters; the file's top-level `import`s only bring in the dependency descriptors for the generated `deps` companion, and there is no internal bootstrap. `pdf.factory()` therefore cannot be called with no arguments. Register `fw_require` and `modules` from `src/main.js` into a `@awacloud/fw` `ModuleRuntime` to resolve it, or use the committed `dist/standalone/pdf.js` build, whose `pdfBundled.factory()` takes no arguments (same returned API either way). See [`main`](./main.md) for DI registration.
|
|
17
|
+
|
|
18
|
+
## Resolve
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
const api = runtime.resolve('pdf');
|
|
22
|
+
// Returns: { read, header, write, use, usedExtension }
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or stand-alone, from the committed framework-free build:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import { pdfBundled } from '@awacloud/pdf/standalone/pdf.js';
|
|
29
|
+
const api = pdfBundled.factory();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## API
|
|
33
|
+
|
|
34
|
+
| Method | Signature | Returns |
|
|
35
|
+
|--------|-----------|---------|
|
|
36
|
+
| `read` | `(bytes: Uint8Array, opts?: { allowEncrypted?: boolean }) => Document` | Full typed document — see [`pdfDocument`](./document/document.md). Throws `pdf/document/encrypted` on an encrypted document unless `opts.allowEncrypted === true`. |
|
|
37
|
+
| `header` | `(bytes: Uint8Array) => { version: string, end: number }` | Header only, without parsing the rest. |
|
|
38
|
+
| `write` | `(model: Document \| WriteModel, opts?: { strict?, onSkipped? }) => Uint8Array` | Serializes a document model back to bytes. When `model._raw.resolve` is a function (i.e. `model` is a `Document` returned by `read`), builds the write model from it (indirects, root, info, id, version `'2.0'`) via `pdfWriter`'s `assembleIndirects`; otherwise passes `model` straight through to `pdfWriter.writeDocument`. The result carries a non-enumerable `skippedObjects` property — see [`pdf.write(model, opts)`](#pdfwritemodel-opts). |
|
|
39
|
+
| `use` | `(ext: { name: string, register: function }) => api` | Applies an extension (idempotent per `name`). |
|
|
40
|
+
| `usedExtension` | `(name: string) => boolean` | Tests whether an extension is wired. |
|
|
41
|
+
|
|
42
|
+
### `pdf.write(model, opts)`
|
|
43
|
+
|
|
44
|
+
A `Document` returned by `read` can hold in-use xref entries that cannot be resolved (a damaged object, a truncated stream). By default `write` is lenient: it drops those objects and still returns bytes, so the loss must be made visible.
|
|
45
|
+
|
|
46
|
+
| Option | Type | Effect |
|
|
47
|
+
|--------|------|--------|
|
|
48
|
+
| `strict` | `boolean` | Only the value `true` counts (a truthy non-boolean such as `'yes'` or `1` stays lenient). With `strict: true`, `write` throws `pdf/writer/unresolvable-objects` instead of dropping anything; the error's `context.objects` lists every unresolvable entry. |
|
|
49
|
+
| `onSkipped` | `(skipped) => void` | Lenient mode only. Called once, with a copy of the skip list, when at least one object was dropped. Never called when nothing was skipped or when `strict: true` throws. Anything that is not a function is ignored. |
|
|
50
|
+
|
|
51
|
+
The returned `Uint8Array` always has a non-enumerable `skippedObjects` property: an array of `{ num, gen, code }` entries, one per dropped object (`code` is the caught error's `pdf/…` code, or `'unknown'`). It is `[]` for a clean `Document` and for a raw `WriteModel`. Being non-enumerable, it does not show up in `Object.keys`, spreading, `JSON.stringify` or `toEqual`, so the bytes compare exactly as before. A raw `WriteModel` has no xref to resolve, so `opts` is ignored for it. `write(model)` with no `opts` produces the same bytes as before.
|
|
52
|
+
|
|
53
|
+
### `pdf.use(ext)`
|
|
54
|
+
|
|
55
|
+
`ext.register(api, ctx)` is invoked with `ctx = { usedExtensions: Set<string> }`. If the return value is an object, its keys (except `use`) are merged into the API in place. The `api` object's identity is preserved — safe to capture.
|
|
56
|
+
|
|
57
|
+
Applying the same `name` twice is a no-op (returns `api` without calling `register` again). See [`extending.md`](../guide/extending.md).
|
|
58
|
+
|
|
59
|
+
## Examples
|
|
60
|
+
|
|
61
|
+
### Read through a runtime
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
import { ModuleRuntime } from '@awacloud/fw/core/runtime.js';
|
|
65
|
+
import { fw_require, modules } from '@awacloud/pdf';
|
|
66
|
+
|
|
67
|
+
const rt = new ModuleRuntime();
|
|
68
|
+
for (const m of fw_require) rt.register(m);
|
|
69
|
+
for (const m of modules) rt.register(m);
|
|
70
|
+
|
|
71
|
+
const api = rt.resolve('pdf');
|
|
72
|
+
const doc = api.read(bytes);
|
|
73
|
+
console.log(doc.version, doc.pages.length);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Header only (quick smoke test)
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
import { pdfBundled } from '@awacloud/pdf/standalone/pdf.js';
|
|
80
|
+
|
|
81
|
+
const { version, end } = pdfBundled.factory().header(bytes);
|
|
82
|
+
// version: the header's version, e.g. '1.7' or '2.0'; end: offset after the header line
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Write back
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
import { pdfBundled } from '@awacloud/pdf/standalone/pdf.js';
|
|
89
|
+
|
|
90
|
+
const api = pdfBundled.factory();
|
|
91
|
+
const doc = api.read(bytes);
|
|
92
|
+
const out = api.write(doc); // Uint8Array
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Write strictly
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
import { pdfBundled } from '@awacloud/pdf/standalone/pdf.js';
|
|
99
|
+
|
|
100
|
+
const api = pdfBundled.factory();
|
|
101
|
+
const doc = api.read(bytes);
|
|
102
|
+
const out = api.write(doc, { strict: true }); // throws pdf/writer/unresolvable-objects if anything would be dropped
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Inspect what a lenient write dropped
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
import { pdfBundled } from '@awacloud/pdf/standalone/pdf.js';
|
|
109
|
+
|
|
110
|
+
const api = pdfBundled.factory();
|
|
111
|
+
const doc = api.read(bytes);
|
|
112
|
+
const out = api.write(doc, {
|
|
113
|
+
onSkipped(skipped) { console.warn(`${skipped.length} object(s) dropped`); }
|
|
114
|
+
});
|
|
115
|
+
for (const { num, gen, code } of out.skippedObjects) {
|
|
116
|
+
console.warn(`object ${num} ${gen} was not written (${code})`);
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### `.use()` hook
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
import { pdfBundled } from '@awacloud/pdf/standalone/pdf.js';
|
|
124
|
+
|
|
125
|
+
const api = pdfBundled.factory().use({
|
|
126
|
+
name: 'count-annots',
|
|
127
|
+
register(self) {
|
|
128
|
+
return {
|
|
129
|
+
countAnnots(b) {
|
|
130
|
+
return self.read(b).pages.reduce((n, p) => n + p.annots.length, 0);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
api.countAnnots(bytes);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Errors
|
|
139
|
+
|
|
140
|
+
| Code | Class | When |
|
|
141
|
+
|------|--------|------|
|
|
142
|
+
| `pdf/use/bad-extension` | `ContractError` | `.use()` receives anything other than `{ name: string, register: function }`. |
|
|
143
|
+
| `pdf/writer/unresolvable-objects` | `RenderError` | `.write(doc, { strict: true })` on a `Document` holding at least one in-use xref entry that cannot be resolved; `context.objects` is the `{ num, gen, code }` list. |
|
|
144
|
+
|
|
145
|
+
`.read()` propagates every code from [`pdfDocument`](./document/document.md) (`pdf/document/*`, `pdf/xref/*`, …); `.write()` propagates `pdfWriter`'s other codes.
|
|
146
|
+
|
|
147
|
+
## See also
|
|
148
|
+
|
|
149
|
+
- [`pdfDocument`](./document/document.md) — back-end of `read` / `header`.
|
|
150
|
+
- [`pdfErrors`](./errors.md)
|
|
151
|
+
- [Extending via `.use()`](../guide/extending.md)
|
|
152
|
+
- [Getting started](../guide/getting-started.md)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Prepress — ISO 32000-2 §14.11
|
|
2
|
+
|
|
3
|
+
| Module | Returns | Deps | Description |
|
|
4
|
+
|--------|----------|------|-------------|
|
|
5
|
+
| [`pdfOutputIntent`](./outputIntent.md) | `{ typeOutputIntent }` | `pdfErrors`, `pdfParser` | §14.11.5 — target colour environment. |
|
|
6
|
+
| [`pdfPageBoundary`](./pageBoundary.md) | `{ effectiveMediaBox, effectiveCropBox, effectiveTrimBox, effectiveBleedBox, effectiveArtBox }` | `pdfErrors`, `pdfParser` | §14.11.2 — boundary boxes. |
|
|
7
|
+
|
|
8
|
+
## See also
|
|
9
|
+
|
|
10
|
+
- [Document](../document/README.md) · [Metadata](../metadata/README.md)
|