pdf-skryba 0.10.2 → 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 +36 -3
- package/README.md +22 -20
- package/dist/first-party/reader.js +1178 -1108
- package/dist/first-party/reader.js.map +4 -4
- package/dist/first-party.js +7 -7
- package/dist/first-party.js.map +2 -2
- package/dist/index.js +1202 -1132
- package/dist/index.js.map +4 -4
- package/dist/index.min.js +4 -4
- package/dist/light.js +6 -6
- package/dist/light.js.map +3 -3
- package/dist/light.min.js +1 -1
- package/dist/types/extractor/codecs/ccitt-fax.d.ts +3 -3
- package/dist/types/extractor/document-cache.d.ts +1 -1
- package/dist/types/extractor/extraction-cost.d.ts +2 -2
- package/dist/types/extractor/font-weight.d.ts +2 -2
- package/dist/types/extractor/glyph-positions.d.ts +14 -14
- package/dist/types/extractor/glyph-runs.d.ts +4 -4
- package/dist/types/extractor/glyph-window.d.ts +2 -2
- package/dist/types/extractor/pdf-aside-figures.d.ts +1 -1
- package/dist/types/extractor/pdf-bands.d.ts +2 -2
- package/dist/types/extractor/pdf-ccitt-images.d.ts +1 -1
- package/dist/types/extractor/pdf-colour-ours.d.ts +4 -4
- package/dist/types/extractor/pdf-decrypt.d.ts +1 -1
- package/dist/types/extractor/pdf-document-info.d.ts +4 -4
- package/dist/types/extractor/pdf-document-scale.d.ts +1 -1
- package/dist/types/extractor/pdf-embedded-images.d.ts +1 -1
- package/dist/types/extractor/pdf-facts.d.ts +3 -3
- package/dist/types/extractor/pdf-flate-images.d.ts +1 -1
- package/dist/types/extractor/pdf-font-bridge.d.ts +3 -3
- package/dist/types/extractor/pdf-font-objects.d.ts +5 -5
- package/dist/types/extractor/pdf-fonts/font-text.d.ts +6 -6
- package/dist/types/extractor/pdf-fonts/predefined-cmaps.d.ts +6 -6
- package/dist/types/extractor/pdf-fonts/type1-encoding.d.ts +1 -1
- package/dist/types/extractor/pdf-fonts/widths.d.ts +2 -2
- package/dist/types/extractor/pdf-glyph-source.d.ts +13 -14
- package/dist/types/extractor/pdf-hidden-text.d.ts +3 -3
- package/dist/types/extractor/pdf-image-anchors.d.ts +1 -1
- package/dist/types/extractor/pdf-image-pixels.d.ts +13 -13
- package/dist/types/extractor/pdf-image-refusal.d.ts +2 -2
- package/dist/types/extractor/pdf-images.d.ts +4 -4
- package/dist/types/extractor/pdf-jpeg-images.d.ts +1 -1
- package/dist/types/extractor/pdf-layers.d.ts +1 -1
- package/dist/types/extractor/pdf-letter-spacing.d.ts +1 -1
- package/dist/types/extractor/pdf-line-breaks.d.ts +2 -2
- package/dist/types/extractor/pdf-links-ours.d.ts +2 -2
- package/dist/types/extractor/pdf-links.d.ts +2 -2
- package/dist/types/extractor/pdf-model.d.ts +8 -8
- package/dist/types/extractor/pdf-objects/bounds.d.ts +4 -4
- package/dist/types/extractor/pdf-objects/content.d.ts +4 -4
- package/dist/types/extractor/pdf-objects/document.d.ts +14 -14
- package/dist/types/extractor/pdf-objects/objects.d.ts +10 -10
- package/dist/types/extractor/pdf-objects/parse.d.ts +4 -4
- package/dist/types/extractor/pdf-objects/refusal.d.ts +2 -2
- package/dist/types/extractor/pdf-objects/streams.d.ts +4 -4
- package/dist/types/extractor/pdf-objects/xref.d.ts +3 -3
- package/dist/types/extractor/pdf-objstm-guard.d.ts +1 -1
- package/dist/types/extractor/pdf-objstm-source.d.ts +1 -1
- package/dist/types/extractor/pdf-open.d.ts +1 -1
- package/dist/types/extractor/pdf-ops-ours.d.ts +3 -3
- package/dist/types/extractor/pdf-ops.d.ts +9 -9
- package/dist/types/extractor/pdf-outline.d.ts +3 -3
- package/dist/types/extractor/pdf-page-content.d.ts +2 -2
- package/dist/types/extractor/pdf-page-figures.d.ts +1 -1
- package/dist/types/extractor/pdf-page-plan.d.ts +3 -3
- package/dist/types/extractor/pdf-page-stages.d.ts +2 -2
- package/dist/types/extractor/pdf-paragraphs.d.ts +1 -1
- package/dist/types/extractor/pdf-paths-ours.d.ts +4 -8
- package/dist/types/extractor/pdf-reference-ours.d.ts +2 -2
- package/dist/types/extractor/pdf-region-order.d.ts +2 -2
- package/dist/types/extractor/pdf-scanned.d.ts +2 -2
- package/dist/types/extractor/pdf-smask.d.ts +3 -3
- package/dist/types/extractor/pdf-source.d.ts +31 -32
- package/dist/types/extractor/pdf-stencil-images.d.ts +1 -1
- package/dist/types/extractor/pdf-structure.d.ts +1 -1
- package/dist/types/extractor/pdf-symbol-page.d.ts +2 -2
- package/dist/types/extractor/pdf-symbol-verdict.d.ts +3 -3
- package/dist/types/extractor/pdf-table-detector.d.ts +6 -6
- package/dist/types/extractor/pdf-table-render.d.ts +1 -1
- package/dist/types/extractor/text-writing-direction.d.ts +1 -1
- package/dist/types/layout/cell-text.d.ts +1 -1
- package/dist/types/layout/column-discriminant.d.ts +2 -2
- package/dist/types/layout/column-grid.d.ts +4 -4
- package/dist/types/layout/cut-word.d.ts +3 -3
- package/dist/types/layout/geometry.d.ts +3 -3
- package/dist/types/layout/grid-band.d.ts +3 -3
- package/dist/types/layout/gutter.d.ts +6 -6
- package/dist/types/layout/heading-sizes.d.ts +2 -2
- package/dist/types/layout/hidden-repaints.d.ts +1 -1
- package/dist/types/layout/hyphenation.d.ts +1 -1
- package/dist/types/layout/image-frontier.d.ts +1 -1
- package/dist/types/layout/induced-markers.d.ts +2 -2
- package/dist/types/layout/intervals.d.ts +3 -3
- package/dist/types/layout/list.d.ts +9 -9
- package/dist/types/layout/merged-cells.d.ts +1 -1
- package/dist/types/layout/mode.d.ts +2 -2
- package/dist/types/layout/superscript.d.ts +1 -1
- package/dist/types/layout/text-size.d.ts +1 -1
- package/dist/types/layout/vector-grid.d.ts +5 -5
- package/dist/types/lib/chunk.d.ts +1 -1
- package/dist/types/lib/extent.d.ts +2 -2
- package/dist/types/lib/link-schemes.d.ts +1 -1
- package/dist/types/lib/pdf-first-party.d.ts +4 -4
- package/dist/types/lib/pdf-light.d.ts +2 -2
- package/dist/types/lib/reader-options.d.ts +3 -3
- package/dist/types/lib/table-leading-bands.d.ts +2 -2
- package/dist/types/pipeline/cut-paragraph-repair.d.ts +1 -1
- package/dist/types/pipeline/glued-word-repair.d.ts +1 -1
- package/dist/types/pipeline/pdf-conservation-source.d.ts +8 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,14 +2,46 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `pdf-skryba` are written here. The format follows
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the package follows
|
|
5
|
-
[Semantic Versioning](https://semver.org/spec/v2.0.0.html):
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html): since 1.0.0, only a major version may break the
|
|
6
|
+
published surface (`pdf-skryba`, `pdf-skryba/light` and their minified twins); before 1.0, a minor version could.
|
|
7
|
+
The `pdf-skryba/first-party` entries are not covered (see the README). Dates are the publication dates on the npm
|
|
8
|
+
registry (UTC).
|
|
8
9
|
|
|
9
10
|
The package was named `skryba` from 0.1.0 to 0.6.2; `skryba` stays frozen at 0.6.2 and is deprecated
|
|
10
11
|
with the message « Renamed to pdf-skryba ». Before 0.1.0 the same reader was published as
|
|
11
12
|
`@miksumia/reader`, which the registry no longer serves; those versions are not reconstructed here.
|
|
12
13
|
|
|
14
|
+
## [1.0.0] - 2026-11-29
|
|
15
|
+
|
|
16
|
+
The first stable version. Every published name now follows one vocabulary: functions are verbs, booleans start
|
|
17
|
+
with `is`, `has`, `can` or `should`, and no name is abbreviated. Nothing changes in what the reader publishes: the
|
|
18
|
+
pages of 197 reference PDFs are byte-identical to 0.10.2.
|
|
19
|
+
|
|
20
|
+
### Changed (breaking)
|
|
21
|
+
|
|
22
|
+
- `pdf-skryba/light`: `noWorse` → `isGluedRepairNoWorse`, `joinNoWorse` → `isParagraphJoinNoWorse`.
|
|
23
|
+
- `ExtractOptions`: `ocr` → `canUseOcr`, `scanAsImages` → `shouldReturnScansAsImages`, `readAll` →
|
|
24
|
+
`shouldReadAllPages`.
|
|
25
|
+
- The result of `extractPdf`: `doc` → `document`, `docFacts` → `documentFacts`; in `PdfDocumentFacts`, `tagged` →
|
|
26
|
+
`isTagged`, `linearized` → `isLinearized`, `form` → `hasForm`.
|
|
27
|
+
- `pdf-skryba/first-party` (not covered by Semantic Versioning, listed for the record): `chunk` → `splitIntoChunks`,
|
|
28
|
+
`PUBLISHED_SCHEME` → `PUBLISHED_LINK_SCHEME_PATTERN`, `ReferenceCycle` → `ReferenceTextRun` (its fields `artifact`,
|
|
29
|
+
`rotated`, `hidden`, `note`, `middle` → `isArtifact`, `isRotated`, `isHidden`, `isInNote`, `verticalCentre`),
|
|
30
|
+
`PdfConservationSource.letters` → `letterReading`, and the property names of the objects the reader entry returns
|
|
31
|
+
(`PdfReference.objectNumber`/`generationNumber`, `dictionary`, `visibleBox`, `operator`/`operands`…).
|
|
32
|
+
- About 200 names inside the reader, reachable from no entry, take the same vocabulary.
|
|
33
|
+
|
|
34
|
+
### Removed
|
|
35
|
+
|
|
36
|
+
- `PdfTextRun.dir`, always `"ltr"` and read by nothing.
|
|
37
|
+
- `MAX_STATE_DEPTH`: it was the same bound as `GRAPHICS_STATE_MAX_DEPTH` (256), which stays.
|
|
38
|
+
|
|
39
|
+
### Other
|
|
40
|
+
|
|
41
|
+
- The column evidence value `"chars"` (`extractPdfPages` option `columns`) is now `"characters"`.
|
|
42
|
+
- `PathBuilder`'s members are truly private (`#private` in the published declaration).
|
|
43
|
+
- The type check covers the development scripts under `tools/`.
|
|
44
|
+
|
|
13
45
|
## [0.10.2] - 2026-11-28
|
|
14
46
|
|
|
15
47
|
### Fixed
|
|
@@ -243,6 +275,7 @@ publishing. It is not a release.
|
|
|
243
275
|
|
|
244
276
|
[Unreleased]: https://github.com/numiastowski-design/pdf-skryba
|
|
245
277
|
|
|
278
|
+
[1.0.0]: https://www.npmjs.com/package/pdf-skryba/v/1.0.0
|
|
246
279
|
[0.10.2]: https://www.npmjs.com/package/pdf-skryba/v/0.10.2
|
|
247
280
|
[0.10.1]: https://www.npmjs.com/package/pdf-skryba/v/0.10.1
|
|
248
281
|
[0.10.0]: https://www.npmjs.com/package/pdf-skryba/v/0.10.0
|
package/README.md
CHANGED
|
@@ -29,13 +29,15 @@ if (path === undefined) throw new Error("usage: node read.js <file.pdf>");
|
|
|
29
29
|
// A refusal is told by its name: that holds whichever entry, and whichever copy of the package, threw it.
|
|
30
30
|
const isRefusal = (error: unknown): error is ReaderError => error instanceof Error && error.name === "ReaderError";
|
|
31
31
|
|
|
32
|
-
// No AI reading here: with `
|
|
32
|
+
// No AI reading here: with `canUseOcr: false`, a page without a text layer is counted, never sent.
|
|
33
33
|
const vision = { analyzeDocument: () => Promise.reject(new Error("no AI reading configured")) };
|
|
34
34
|
|
|
35
35
|
try {
|
|
36
|
-
const {
|
|
36
|
+
const { document, pageCount, notices } = await extractPdf(new Uint8Array(readFileSync(path)), vision, {
|
|
37
|
+
canUseOcr: false,
|
|
38
|
+
});
|
|
37
39
|
console.log(`pages: ${pageCount}`);
|
|
38
|
-
const [pages] =
|
|
40
|
+
const [pages] = document.blocks;
|
|
39
41
|
if (pages?.kind === "tabs") console.log(`blocks on page 1: ${pages.tabs[0]?.blocks.length ?? 0}`);
|
|
40
42
|
console.log(`notices: ${notices?.length ?? 0}`);
|
|
41
43
|
} catch (error) {
|
|
@@ -52,18 +54,18 @@ import { readFileSync } from "node:fs";
|
|
|
52
54
|
import { extractPdf } from "pdf-skryba";
|
|
53
55
|
|
|
54
56
|
const bytes = new Uint8Array(readFileSync("report.pdf"));
|
|
55
|
-
const {
|
|
57
|
+
const { document, pageCount, notices } = await extractPdf(bytes, vision, { canUseOcr: false });
|
|
56
58
|
|
|
57
|
-
pageCount;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
notices;
|
|
59
|
+
pageCount; // 12
|
|
60
|
+
document.blocks[0].kind; // "tabs" — one tab per page
|
|
61
|
+
document.blocks[0].tabs[0]; // its blocks: headings, paragraphs, lists, tables, images
|
|
62
|
+
notices; // every part it could not read, each with a named reason
|
|
61
63
|
```
|
|
62
64
|
|
|
63
65
|
## Scanned pages: the AI reading is yours
|
|
64
66
|
|
|
65
67
|
`vision` is a port you implement. It receives a small PDF holding the pages to read and returns one
|
|
66
|
-
result per page, in order. With `
|
|
68
|
+
result per page, in order. With `canUseOcr: false` a page with no text layer is counted and never read; a
|
|
67
69
|
file that is a scan from end to end is refused (`SCANNED_PDF_NEEDS_AI_OCR`).
|
|
68
70
|
|
|
69
71
|
```js
|
|
@@ -72,10 +74,10 @@ const vision = {
|
|
|
72
74
|
};
|
|
73
75
|
|
|
74
76
|
// Hand back the page pictures instead of refusing a full scan:
|
|
75
|
-
await extractPdf(bytes, vision, {
|
|
77
|
+
await extractPdf(bytes, vision, { canUseOcr: false, shouldReturnScansAsImages: true });
|
|
76
78
|
|
|
77
79
|
// Or let the AI read every page, text layer included:
|
|
78
|
-
await extractPdf(bytes, vision, {
|
|
80
|
+
await extractPdf(bytes, vision, { shouldReadAllPages: true, languages: ["en", "fr"] });
|
|
79
81
|
```
|
|
80
82
|
|
|
81
83
|
## Your own ceilings
|
|
@@ -96,11 +98,11 @@ whichever copy of the package, threw the error. `pdf-skryba/light` exports the t
|
|
|
96
98
|
|
|
97
99
|
```js
|
|
98
100
|
try {
|
|
99
|
-
await extractPdf(bytes, vision, {
|
|
101
|
+
await extractPdf(bytes, vision, { canUseOcr: false });
|
|
100
102
|
} catch (error) {
|
|
101
103
|
if (error instanceof Error && error.name === "ReaderError") {
|
|
102
|
-
error.code;
|
|
103
|
-
error.pageCount;
|
|
104
|
+
error.code; // "SCANNED_PDF_NEEDS_AI_OCR", "FILE_UNSAFE", "EXTRACT_FAILED"…
|
|
105
|
+
error.pageCount; // what it knew before refusing
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
108
|
```
|
|
@@ -116,10 +118,10 @@ import { textConservation } from "pdf-skryba/light";
|
|
|
116
118
|
const { conservationSource } = await extractPdf(bytes, vision);
|
|
117
119
|
const verdict = textConservation(conservationSource.runs, { blocks: myPublishedTexts });
|
|
118
120
|
|
|
119
|
-
verdict.decision;
|
|
120
|
-
verdict.lostLetters;
|
|
121
|
-
verdict.lostPassages;
|
|
122
|
-
verdict.pages;
|
|
121
|
+
verdict.decision; // "ok" | "lost" | "glued" | "abstain"
|
|
122
|
+
verdict.lostLetters; // how many, and
|
|
123
|
+
verdict.lostPassages; // where: each passage, with the page it came from
|
|
124
|
+
verdict.pages; // the pages concerned
|
|
123
125
|
```
|
|
124
126
|
|
|
125
127
|
## Principles
|
|
@@ -154,8 +156,8 @@ Four entries, two of them the minified twins of the others.
|
|
|
154
156
|
- `pdf-skryba` — the reader, `extractPdf`, called as `extractPdf(bytes, vision, options?)`; and
|
|
155
157
|
`detectLanguage`; with the types of its options and results (`ExtractOptions`, `PdfDocumentFacts`…).
|
|
156
158
|
- `pdf-skryba/light` — loads no reader. The conservation check: `textConservation`, `lostWords`,
|
|
157
|
-
`placeLostPassages`, `gluedWordEdits`, `cutParagraphEdits`, `
|
|
158
|
-
`conservationKey`. Refusals and ceilings: `ReaderError`, `MAX_PAYLOAD_BYTES`. And the types of the
|
|
159
|
+
`placeLostPassages`, `gluedWordEdits`, `cutParagraphEdits`, `isGluedRepairNoWorse`,
|
|
160
|
+
`isParagraphJoinNoWorse`, `wordKeysOf`, `conservationKey`. Refusals and ceilings: `ReaderError`, `MAX_PAYLOAD_BYTES`. And the types of the
|
|
159
161
|
representation (`IRDoc`, `IRBlock`, `TableData`…).
|
|
160
162
|
- `pdf-skryba/min` and `pdf-skryba/light/min` — the same code, minified.
|
|
161
163
|
|