pdf-parser.js 3.0.8 → 4.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -54
- package/dist/{afm-widths-Dxucrg7D.js → afm-widths-BTu0IDp2.cjs} +1517 -4
- package/dist/{afm-widths-DyDq56Ph.d.cts → afm-widths-CneRyu5l.d.cts} +1 -1
- package/dist/{afm-widths-DyDq56Ph.d.ts → afm-widths-CneRyu5l.d.ts} +1 -1
- package/dist/{afm-widths-BoeTOK2r.cjs → afm-widths-De_QMWgC.js} +1416 -51
- package/dist/afm-widths.cjs +1 -1
- package/dist/afm-widths.d.cts +1 -1
- package/dist/afm-widths.d.ts +1 -1
- package/dist/afm-widths.js +1 -1
- package/dist/annotations.cjs +104 -0
- package/dist/annotations.d.cts +9 -0
- package/dist/annotations.d.ts +9 -0
- package/dist/annotations.js +103 -0
- package/dist/attachments.cjs +65 -0
- package/dist/attachments.d.cts +8 -0
- package/dist/attachments.d.ts +8 -0
- package/dist/attachments.js +64 -0
- package/dist/builtin-encoding.cjs +221 -0
- package/dist/builtin-encoding.d.cts +8 -0
- package/dist/builtin-encoding.d.ts +8 -0
- package/dist/builtin-encoding.js +220 -0
- package/dist/bytes/flate.cjs +1 -1
- package/dist/bytes/flate.js +1 -1
- package/dist/cff.cjs +14 -0
- package/dist/cff.d.cts +4 -1
- package/dist/cff.d.ts +4 -1
- package/dist/cff.js +12 -1
- package/dist/cmap-table.cjs +76 -13
- package/dist/cmap-table.d.cts +9 -1
- package/dist/cmap-table.d.ts +9 -1
- package/dist/cmap-table.js +77 -15
- package/dist/codec.cjs +1 -1
- package/dist/codec.d.cts +134 -0
- package/dist/codec.d.ts +134 -0
- package/dist/codec.js +1 -1
- package/dist/content-read.cjs +1 -1
- package/dist/content-read.d.cts +3 -3
- package/dist/content-read.d.ts +3 -3
- package/dist/content-read.js +1 -1
- package/dist/content-write.cjs +32 -10
- package/dist/content-write.d.cts +12 -5
- package/dist/content-write.d.ts +12 -5
- package/dist/content-write.js +32 -10
- package/dist/crypto/random.cjs +9 -0
- package/dist/crypto/random.d.cts +4 -0
- package/dist/crypto/random.d.ts +4 -0
- package/dist/crypto/random.js +8 -0
- package/dist/diagnostics.d.cts +1 -1
- package/dist/diagnostics.d.ts +1 -1
- package/dist/document.cjs +12 -3
- package/dist/document.d.cts +3 -1
- package/dist/document.d.ts +3 -1
- package/dist/document.js +12 -3
- package/dist/{embedded-font-fREdbxnr.d.ts → embedded-font-B4p9a3O3.d.ts} +3 -1
- package/dist/{embedded-font-BU6Jgcof.d.cts → embedded-font-oc65VGlr.d.cts} +3 -1
- package/dist/embedded-font-write.cjs +1 -1
- package/dist/embedded-font-write.d.cts +3 -3
- package/dist/embedded-font-write.d.ts +3 -3
- package/dist/embedded-font-write.js +1 -1
- package/dist/embedded-font.cjs +46 -15
- package/dist/embedded-font.d.cts +1 -1
- package/dist/embedded-font.d.ts +1 -1
- package/dist/embedded-font.js +46 -15
- package/dist/encoding.cjs +10 -1
- package/dist/encoding.d.cts +10 -1
- package/dist/encoding.d.ts +10 -1
- package/dist/encoding.js +2 -2
- package/dist/encrypt-write.cjs +234 -0
- package/dist/encrypt-write.d.cts +31 -0
- package/dist/encrypt-write.d.ts +31 -0
- package/dist/encrypt-write.js +231 -0
- package/dist/encrypt.cjs +51 -21
- package/dist/encrypt.d.cts +19 -3
- package/dist/encrypt.d.ts +19 -3
- package/dist/encrypt.js +36 -22
- package/dist/filters.cjs +18 -14
- package/dist/filters.d.cts +1 -1
- package/dist/filters.d.ts +1 -1
- package/dist/filters.js +18 -14
- package/dist/font-read.cjs +68 -13
- package/dist/font-read.d.cts +1 -1
- package/dist/font-read.d.ts +1 -1
- package/dist/font-read.js +69 -14
- package/dist/font-registry.cjs +1 -1
- package/dist/font-registry.d.cts +4 -4
- package/dist/font-registry.d.ts +4 -4
- package/dist/font-registry.js +1 -1
- package/dist/font-substitutes.d.cts +1 -1
- package/dist/font-substitutes.d.ts +1 -1
- package/dist/font-tables.cjs +31 -0
- package/dist/font-tables.d.cts +3 -1
- package/dist/font-tables.d.ts +3 -1
- package/dist/font-tables.js +31 -2
- package/dist/fonts.d.cts +2 -2
- package/dist/fonts.d.ts +2 -2
- package/dist/form.cjs +138 -0
- package/dist/form.d.cts +9 -0
- package/dist/form.d.ts +9 -0
- package/dist/form.js +137 -0
- package/dist/gsub-table-BRTQ8EUW.d.ts +10 -0
- package/dist/gsub-table-URczLd85.d.cts +10 -0
- package/dist/gsub-table.cjs +225 -0
- package/dist/gsub-table.d.cts +2 -0
- package/dist/gsub-table.d.ts +2 -0
- package/dist/gsub-table.js +224 -0
- package/dist/image/ccitt-encode.cjs +119 -0
- package/dist/image/ccitt-encode.d.cts +9 -0
- package/dist/image/ccitt-encode.d.ts +9 -0
- package/dist/image/ccitt-encode.js +118 -0
- package/dist/image/ccitt.cjs +3 -0
- package/dist/image/ccitt.d.cts +4 -1
- package/dist/image/ccitt.d.ts +4 -1
- package/dist/image/ccitt.js +1 -1
- package/dist/image/jbig2-bitmap.d.cts +1 -1
- package/dist/image/jbig2-bitmap.d.ts +1 -1
- package/dist/image/jbig2.cjs +3 -1
- package/dist/image/jbig2.js +3 -1
- package/dist/image/jp2-boxes.d.cts +1 -1
- package/dist/image/jp2-boxes.d.ts +1 -1
- package/dist/image/jpeg2000-codestream.d.cts +3 -3
- package/dist/image/jpeg2000-codestream.d.ts +3 -3
- package/dist/image/jpeg2000-t1.d.cts +1 -1
- package/dist/image/jpeg2000-t1.d.ts +1 -1
- package/dist/image/jpeg2000.cjs +1 -0
- package/dist/image/jpeg2000.d.cts +3 -0
- package/dist/image/jpeg2000.d.ts +3 -0
- package/dist/image/jpeg2000.js +1 -0
- package/dist/image/png-decode.cjs +1 -1
- package/dist/image/png-decode.js +1 -1
- package/dist/image/png-filter.d.cts +1 -1
- package/dist/image/png-filter.d.ts +1 -1
- package/dist/images-read.cjs +18 -12
- package/dist/images-read.d.cts +2 -2
- package/dist/images-read.d.ts +2 -2
- package/dist/images-read.js +15 -9
- package/dist/index.cjs +17 -4
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +6 -5
- package/dist/interpret.cjs +178 -56
- package/dist/interpret.d.cts +27 -12
- package/dist/interpret.d.ts +27 -12
- package/dist/interpret.js +178 -56
- package/dist/layout.cjs +149 -2
- package/dist/layout.d.cts +394 -1
- package/dist/layout.d.ts +394 -1
- package/dist/layout.js +140 -4
- package/dist/lexer.d.cts +9 -9
- package/dist/lexer.d.ts +9 -9
- package/dist/math-content-write.cjs +1 -1
- package/dist/math-content-write.js +1 -1
- package/dist/math-font-write.cjs +1 -1
- package/dist/math-font-write.d.cts +1 -1
- package/dist/math-font-write.d.ts +1 -1
- package/dist/math-font-write.js +1 -1
- package/dist/math-font.cjs +2 -2
- package/dist/math-font.d.cts +1 -1
- package/dist/math-font.d.ts +1 -1
- package/dist/math-font.js +2 -2
- package/dist/{math-stretch-a_rHNRvc.d.ts → math-stretch-BbC2o4Br.d.ts} +1 -1
- package/dist/{math-stretch-E26z6byT.d.cts → math-stretch-C2JanDAz.d.cts} +1 -1
- package/dist/math-stretch.d.cts +1 -1
- package/dist/math-stretch.d.ts +1 -1
- package/dist/measure.cjs +1 -1
- package/dist/measure.d.cts +1 -1
- package/dist/measure.d.ts +1 -1
- package/dist/measure.js +1 -1
- package/dist/names.cjs +41 -0
- package/dist/names.d.cts +11 -0
- package/dist/names.d.ts +11 -0
- package/dist/names.js +40 -0
- package/dist/navigation.cjs +210 -0
- package/dist/navigation.d.cts +18 -0
- package/dist/navigation.d.ts +18 -0
- package/dist/navigation.js +207 -0
- package/dist/notes-annotation-author.cjs +5 -0
- package/dist/notes-annotation-author.d.cts +4 -0
- package/dist/notes-annotation-author.d.ts +4 -0
- package/dist/notes-annotation-author.js +4 -0
- package/dist/objects-B7HdMeWS.d.cts +59 -0
- package/dist/objects-B7HdMeWS.d.ts +59 -0
- package/dist/objects.d.cts +1 -58
- package/dist/objects.d.ts +1 -58
- package/dist/optional-content.cjs +63 -0
- package/dist/optional-content.d.cts +12 -0
- package/dist/optional-content.d.ts +12 -0
- package/dist/optional-content.js +62 -0
- package/dist/parse.cjs +1 -1
- package/dist/parse.d.cts +2 -2
- package/dist/parse.d.ts +2 -2
- package/dist/parse.js +1 -1
- package/dist/pdf-text.cjs +21 -0
- package/dist/pdf-text.d.cts +5 -0
- package/dist/pdf-text.d.ts +5 -0
- package/dist/pdf-text.js +19 -0
- package/dist/predictors.d.cts +1 -1
- package/dist/predictors.d.ts +1 -1
- package/dist/read.cjs +287 -72
- package/dist/read.d.cts +2 -4
- package/dist/read.d.ts +2 -4
- package/dist/read.js +284 -67
- package/dist/serialize.cjs +5 -1
- package/dist/serialize.d.cts +3 -2
- package/dist/serialize.d.ts +3 -2
- package/dist/serialize.js +5 -2
- package/dist/sfnt-subset.cjs +10 -3
- package/dist/sfnt-subset.d.cts +1 -1
- package/dist/sfnt-subset.d.ts +1 -1
- package/dist/sfnt-subset.js +10 -3
- package/dist/structure.cjs +184 -0
- package/dist/structure.d.cts +12 -0
- package/dist/structure.d.ts +12 -0
- package/dist/structure.js +183 -0
- package/dist/tounicode.cjs +8 -3
- package/dist/tounicode.d.cts +2 -2
- package/dist/tounicode.d.ts +2 -2
- package/dist/tounicode.js +8 -3
- package/dist/util/base64.cjs +4 -4
- package/dist/util/base64.js +4 -4
- package/dist/winansi.cjs +1 -1
- package/dist/winansi.d.cts +1 -1
- package/dist/winansi.d.ts +1 -1
- package/dist/winansi.js +1 -1
- package/dist/write.cjs +464 -21
- package/dist/write.d.cts +4 -3
- package/dist/write.d.ts +4 -3
- package/dist/write.js +464 -20
- package/dist/xmp.cjs +46 -0
- package/dist/xmp.d.cts +14 -0
- package/dist/xmp.d.ts +14 -0
- package/dist/xmp.js +45 -0
- package/dist/xref.cjs +2 -2
- package/dist/xref.d.cts +3 -3
- package/dist/xref.d.ts +3 -3
- package/dist/xref.js +2 -2
- package/package.json +46 -31
- package/dist/image/png-encode.cjs +0 -64
- package/dist/image/png-encode.d.cts +0 -8
- package/dist/image/png-encode.d.ts +0 -8
- package/dist/image/png-encode.js +0 -63
package/dist/interpret.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.cjs";
|
|
2
|
-
import { PdfDict, PdfObject } from "./objects.cjs";
|
|
3
2
|
import { r as Matrix } from "./matrix-B7_SBKQ5.cjs";
|
|
4
|
-
import {
|
|
3
|
+
import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.cjs";
|
|
4
|
+
import { Color, ContentStrokeStyle } from "document-schema.js";
|
|
5
5
|
//#region src/interpret.d.ts
|
|
6
6
|
interface ExtractedTextRun {
|
|
7
|
-
readonly kind:
|
|
7
|
+
readonly kind: "text";
|
|
8
8
|
readonly codes: Uint8Array<ArrayBuffer>;
|
|
9
9
|
readonly fontResourceName: string;
|
|
10
10
|
readonly resources: PdfDict;
|
|
@@ -12,6 +12,10 @@ interface ExtractedTextRun {
|
|
|
12
12
|
readonly endMatrix: Matrix;
|
|
13
13
|
readonly sizePt: number;
|
|
14
14
|
readonly color: Color;
|
|
15
|
+
readonly layerName?: string;
|
|
16
|
+
readonly actualText?: string;
|
|
17
|
+
readonly alt?: string;
|
|
18
|
+
readonly mcid?: number;
|
|
15
19
|
}
|
|
16
20
|
interface ExtractedPaint {
|
|
17
21
|
readonly fill: Color | undefined;
|
|
@@ -19,36 +23,41 @@ interface ExtractedPaint {
|
|
|
19
23
|
readonly color: Color;
|
|
20
24
|
readonly widthPt: number;
|
|
21
25
|
} | undefined;
|
|
26
|
+
readonly layerName?: string;
|
|
27
|
+
readonly mcid?: number;
|
|
22
28
|
}
|
|
23
29
|
interface ExtractedRect extends ExtractedPaint {
|
|
24
|
-
readonly kind:
|
|
30
|
+
readonly kind: "rect";
|
|
25
31
|
readonly xPt: number;
|
|
26
32
|
readonly yPt: number;
|
|
27
33
|
readonly widthPt: number;
|
|
28
34
|
readonly heightPt: number;
|
|
29
35
|
}
|
|
30
36
|
interface ExtractedEllipse extends ExtractedPaint {
|
|
31
|
-
readonly kind:
|
|
37
|
+
readonly kind: "ellipse";
|
|
32
38
|
readonly xPt: number;
|
|
33
39
|
readonly yPt: number;
|
|
34
40
|
readonly widthPt: number;
|
|
35
41
|
readonly heightPt: number;
|
|
36
42
|
}
|
|
37
43
|
interface ExtractedLine {
|
|
38
|
-
readonly kind:
|
|
44
|
+
readonly kind: "line";
|
|
39
45
|
readonly x1Pt: number;
|
|
40
46
|
readonly y1Pt: number;
|
|
41
47
|
readonly x2Pt: number;
|
|
42
48
|
readonly y2Pt: number;
|
|
43
49
|
readonly color: Color;
|
|
44
50
|
readonly widthPt: number;
|
|
51
|
+
readonly style?: ContentStrokeStyle;
|
|
52
|
+
readonly layerName?: string;
|
|
53
|
+
readonly mcid?: number;
|
|
45
54
|
}
|
|
46
55
|
type ExtractedPathSegment = {
|
|
47
|
-
readonly kind:
|
|
56
|
+
readonly kind: "line";
|
|
48
57
|
readonly xPt: number;
|
|
49
58
|
readonly yPt: number;
|
|
50
59
|
} | {
|
|
51
|
-
readonly kind:
|
|
60
|
+
readonly kind: "cubic";
|
|
52
61
|
readonly c1xPt: number;
|
|
53
62
|
readonly c1yPt: number;
|
|
54
63
|
readonly c2xPt: number;
|
|
@@ -63,21 +72,26 @@ interface ExtractedSubpath {
|
|
|
63
72
|
readonly closed: boolean;
|
|
64
73
|
}
|
|
65
74
|
interface ExtractedPath extends ExtractedPaint {
|
|
66
|
-
readonly kind:
|
|
75
|
+
readonly kind: "path";
|
|
67
76
|
readonly subpaths: readonly ExtractedSubpath[];
|
|
68
|
-
readonly fillRule:
|
|
77
|
+
readonly fillRule: "nonzero" | "evenodd";
|
|
78
|
+
readonly style?: ContentStrokeStyle;
|
|
69
79
|
}
|
|
70
80
|
interface ExtractedImage {
|
|
71
|
-
readonly kind:
|
|
81
|
+
readonly kind: "image";
|
|
72
82
|
readonly resourceName: string;
|
|
73
83
|
readonly resources: PdfDict;
|
|
74
84
|
readonly matrix: Matrix;
|
|
85
|
+
readonly layerName?: string;
|
|
86
|
+
readonly mcid?: number;
|
|
75
87
|
}
|
|
76
88
|
interface ExtractedInlineImage {
|
|
77
|
-
readonly kind:
|
|
89
|
+
readonly kind: "inlineImage";
|
|
78
90
|
readonly dict: PdfDict;
|
|
79
91
|
readonly data: Uint8Array<ArrayBuffer>;
|
|
80
92
|
readonly matrix: Matrix;
|
|
93
|
+
readonly layerName?: string;
|
|
94
|
+
readonly mcid?: number;
|
|
81
95
|
}
|
|
82
96
|
type ExtractedItem = ExtractedTextRun | ExtractedRect | ExtractedEllipse | ExtractedLine | ExtractedPath | ExtractedImage | ExtractedInlineImage;
|
|
83
97
|
interface GlyphAdvance {
|
|
@@ -95,6 +109,7 @@ interface InterpretContext {
|
|
|
95
109
|
readonly fontMetrics: FontMetricsPort;
|
|
96
110
|
readonly resolver: PdfObjectResolver;
|
|
97
111
|
readonly sink: PdfDiagnosticSink;
|
|
112
|
+
readonly layerNameOf?: (obj: PdfObject | undefined) => string | undefined;
|
|
98
113
|
}
|
|
99
114
|
declare function interpretContentStream(bytes: Uint8Array<ArrayBuffer>, resources: PdfDict, context: InterpretContext): ExtractedItem[];
|
|
100
115
|
//#endregion
|
package/dist/interpret.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.js";
|
|
2
|
-
import { PdfDict, PdfObject } from "./objects.js";
|
|
3
2
|
import { r as Matrix } from "./matrix-B7_SBKQ5.js";
|
|
4
|
-
import {
|
|
3
|
+
import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.js";
|
|
4
|
+
import { Color, ContentStrokeStyle } from "document-schema.js";
|
|
5
5
|
//#region src/interpret.d.ts
|
|
6
6
|
interface ExtractedTextRun {
|
|
7
|
-
readonly kind:
|
|
7
|
+
readonly kind: "text";
|
|
8
8
|
readonly codes: Uint8Array<ArrayBuffer>;
|
|
9
9
|
readonly fontResourceName: string;
|
|
10
10
|
readonly resources: PdfDict;
|
|
@@ -12,6 +12,10 @@ interface ExtractedTextRun {
|
|
|
12
12
|
readonly endMatrix: Matrix;
|
|
13
13
|
readonly sizePt: number;
|
|
14
14
|
readonly color: Color;
|
|
15
|
+
readonly layerName?: string;
|
|
16
|
+
readonly actualText?: string;
|
|
17
|
+
readonly alt?: string;
|
|
18
|
+
readonly mcid?: number;
|
|
15
19
|
}
|
|
16
20
|
interface ExtractedPaint {
|
|
17
21
|
readonly fill: Color | undefined;
|
|
@@ -19,36 +23,41 @@ interface ExtractedPaint {
|
|
|
19
23
|
readonly color: Color;
|
|
20
24
|
readonly widthPt: number;
|
|
21
25
|
} | undefined;
|
|
26
|
+
readonly layerName?: string;
|
|
27
|
+
readonly mcid?: number;
|
|
22
28
|
}
|
|
23
29
|
interface ExtractedRect extends ExtractedPaint {
|
|
24
|
-
readonly kind:
|
|
30
|
+
readonly kind: "rect";
|
|
25
31
|
readonly xPt: number;
|
|
26
32
|
readonly yPt: number;
|
|
27
33
|
readonly widthPt: number;
|
|
28
34
|
readonly heightPt: number;
|
|
29
35
|
}
|
|
30
36
|
interface ExtractedEllipse extends ExtractedPaint {
|
|
31
|
-
readonly kind:
|
|
37
|
+
readonly kind: "ellipse";
|
|
32
38
|
readonly xPt: number;
|
|
33
39
|
readonly yPt: number;
|
|
34
40
|
readonly widthPt: number;
|
|
35
41
|
readonly heightPt: number;
|
|
36
42
|
}
|
|
37
43
|
interface ExtractedLine {
|
|
38
|
-
readonly kind:
|
|
44
|
+
readonly kind: "line";
|
|
39
45
|
readonly x1Pt: number;
|
|
40
46
|
readonly y1Pt: number;
|
|
41
47
|
readonly x2Pt: number;
|
|
42
48
|
readonly y2Pt: number;
|
|
43
49
|
readonly color: Color;
|
|
44
50
|
readonly widthPt: number;
|
|
51
|
+
readonly style?: ContentStrokeStyle;
|
|
52
|
+
readonly layerName?: string;
|
|
53
|
+
readonly mcid?: number;
|
|
45
54
|
}
|
|
46
55
|
type ExtractedPathSegment = {
|
|
47
|
-
readonly kind:
|
|
56
|
+
readonly kind: "line";
|
|
48
57
|
readonly xPt: number;
|
|
49
58
|
readonly yPt: number;
|
|
50
59
|
} | {
|
|
51
|
-
readonly kind:
|
|
60
|
+
readonly kind: "cubic";
|
|
52
61
|
readonly c1xPt: number;
|
|
53
62
|
readonly c1yPt: number;
|
|
54
63
|
readonly c2xPt: number;
|
|
@@ -63,21 +72,26 @@ interface ExtractedSubpath {
|
|
|
63
72
|
readonly closed: boolean;
|
|
64
73
|
}
|
|
65
74
|
interface ExtractedPath extends ExtractedPaint {
|
|
66
|
-
readonly kind:
|
|
75
|
+
readonly kind: "path";
|
|
67
76
|
readonly subpaths: readonly ExtractedSubpath[];
|
|
68
|
-
readonly fillRule:
|
|
77
|
+
readonly fillRule: "nonzero" | "evenodd";
|
|
78
|
+
readonly style?: ContentStrokeStyle;
|
|
69
79
|
}
|
|
70
80
|
interface ExtractedImage {
|
|
71
|
-
readonly kind:
|
|
81
|
+
readonly kind: "image";
|
|
72
82
|
readonly resourceName: string;
|
|
73
83
|
readonly resources: PdfDict;
|
|
74
84
|
readonly matrix: Matrix;
|
|
85
|
+
readonly layerName?: string;
|
|
86
|
+
readonly mcid?: number;
|
|
75
87
|
}
|
|
76
88
|
interface ExtractedInlineImage {
|
|
77
|
-
readonly kind:
|
|
89
|
+
readonly kind: "inlineImage";
|
|
78
90
|
readonly dict: PdfDict;
|
|
79
91
|
readonly data: Uint8Array<ArrayBuffer>;
|
|
80
92
|
readonly matrix: Matrix;
|
|
93
|
+
readonly layerName?: string;
|
|
94
|
+
readonly mcid?: number;
|
|
81
95
|
}
|
|
82
96
|
type ExtractedItem = ExtractedTextRun | ExtractedRect | ExtractedEllipse | ExtractedLine | ExtractedPath | ExtractedImage | ExtractedInlineImage;
|
|
83
97
|
interface GlyphAdvance {
|
|
@@ -95,6 +109,7 @@ interface InterpretContext {
|
|
|
95
109
|
readonly fontMetrics: FontMetricsPort;
|
|
96
110
|
readonly resolver: PdfObjectResolver;
|
|
97
111
|
readonly sink: PdfDiagnosticSink;
|
|
112
|
+
readonly layerNameOf?: (obj: PdfObject | undefined) => string | undefined;
|
|
98
113
|
}
|
|
99
114
|
declare function interpretContentStream(bytes: Uint8Array<ArrayBuffer>, resources: PdfDict, context: InterpretContext): ExtractedItem[];
|
|
100
115
|
//#endregion
|
package/dist/interpret.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { asArray, asName, asNumber, dictGet } from "./objects.js";
|
|
2
|
-
import {
|
|
2
|
+
import { decodePdfString } from "./pdf-text.js";
|
|
3
3
|
import { BEZIER_KAPPA, IDENTITY_MATRIX, applyMatrix, multiplyMatrices, translationMatrix } from "./matrix.js";
|
|
4
|
+
import { decodeStream } from "./filters.js";
|
|
4
5
|
import { readContentStream } from "./content-read.js";
|
|
5
6
|
import { COLOR_BLACK } from "document-schema.js";
|
|
6
7
|
//#region src/interpret.ts
|
|
7
8
|
const MAX_FORM_XOBJECT_DEPTH = 12;
|
|
8
9
|
const FALLBACK_GLYPH_WIDTH_PER_1000 = 500;
|
|
9
10
|
const DEFAULT_LINE_WIDTH_PT = 1;
|
|
10
|
-
function
|
|
11
|
+
function initialTextParameters() {
|
|
11
12
|
return {
|
|
12
|
-
tm: IDENTITY_MATRIX,
|
|
13
|
-
tlm: IDENTITY_MATRIX,
|
|
14
13
|
fontResourceName: void 0,
|
|
15
14
|
fontSizePt: 0,
|
|
16
15
|
charSpace: 0,
|
|
@@ -20,20 +19,44 @@ function defaultTextState() {
|
|
|
20
19
|
rise: 0
|
|
21
20
|
};
|
|
22
21
|
}
|
|
23
|
-
function
|
|
22
|
+
function defaultTextObjectState() {
|
|
23
|
+
return {
|
|
24
|
+
tm: IDENTITY_MATRIX,
|
|
25
|
+
tlm: IDENTITY_MATRIX
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function computeTrm(gs, text) {
|
|
24
29
|
const fontMatrix = [
|
|
25
|
-
|
|
30
|
+
gs.fontSizePt * gs.horizScale,
|
|
26
31
|
0,
|
|
27
32
|
0,
|
|
28
|
-
|
|
33
|
+
gs.fontSizePt,
|
|
29
34
|
0,
|
|
30
|
-
|
|
35
|
+
gs.rise
|
|
31
36
|
];
|
|
32
|
-
return multiplyMatrices(multiplyMatrices(fontMatrix,
|
|
37
|
+
return multiplyMatrices(multiplyMatrices(fontMatrix, text.tm), gs.ctm);
|
|
33
38
|
}
|
|
34
39
|
function numAt(operands, index) {
|
|
35
40
|
return asNumber(operands[index]) ?? 0;
|
|
36
41
|
}
|
|
42
|
+
function markedContentProperties(operand, resources, resolver) {
|
|
43
|
+
if (operand?.kind === "dict") return operand;
|
|
44
|
+
if (operand?.kind === "name") {
|
|
45
|
+
const properties = resolver.resolveDict(dictGet(resources, "Properties"));
|
|
46
|
+
return properties === void 0 ? void 0 : resolver.resolveDict(dictGet(properties, operand.name));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function markedContentScopeProps(props) {
|
|
50
|
+
if (props === void 0) return {};
|
|
51
|
+
const actualTextObj = dictGet(props, "ActualText");
|
|
52
|
+
const altObj = dictGet(props, "Alt");
|
|
53
|
+
const mcid = asNumber(dictGet(props, "MCID"));
|
|
54
|
+
return {
|
|
55
|
+
...actualTextObj?.kind === "string" ? { actualText: decodePdfString(actualTextObj.bytes) } : {},
|
|
56
|
+
...altObj?.kind === "string" ? { alt: decodePdfString(altObj.bytes) } : {},
|
|
57
|
+
...mcid !== void 0 && mcid >= 0 ? { mcid } : {}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
37
60
|
function grayColor(value) {
|
|
38
61
|
return {
|
|
39
62
|
r: value,
|
|
@@ -226,7 +249,11 @@ function detectEllipse(subpath, paint) {
|
|
|
226
249
|
stroke: paint.stroke
|
|
227
250
|
};
|
|
228
251
|
}
|
|
229
|
-
function
|
|
252
|
+
function strokeStyleFromDashArray(dashArray) {
|
|
253
|
+
if (dashArray.length === 0) return;
|
|
254
|
+
return dashArray.length === 2 && dashArray[0] === 0 ? "dotted" : "dashed";
|
|
255
|
+
}
|
|
256
|
+
function detectLine(subpath, paint, style) {
|
|
230
257
|
const segment = subpath.segments[0];
|
|
231
258
|
if (subpath.closed || subpath.segments.length !== 1 || segment?.kind !== "line") return;
|
|
232
259
|
if (paint.fill !== void 0 || paint.stroke === void 0) return;
|
|
@@ -237,13 +264,14 @@ function detectLine(subpath, paint) {
|
|
|
237
264
|
x2Pt: segment.xPt,
|
|
238
265
|
y2Pt: segment.yPt,
|
|
239
266
|
color: paint.stroke.color,
|
|
240
|
-
widthPt: paint.stroke.widthPt
|
|
267
|
+
widthPt: paint.stroke.widthPt,
|
|
268
|
+
...style !== void 0 ? { style } : {}
|
|
241
269
|
};
|
|
242
270
|
}
|
|
243
|
-
function classifyShape(subpaths, paint) {
|
|
271
|
+
function classifyShape(subpaths, paint, style) {
|
|
244
272
|
const subpath = subpaths[0];
|
|
245
273
|
if (subpaths.length !== 1 || subpath === void 0) return;
|
|
246
|
-
return detectRect(subpath, paint) ?? detectEllipse(subpath, paint) ?? detectLine(subpath, paint);
|
|
274
|
+
return detectRect(subpath, paint) ?? detectEllipse(subpath, paint) ?? detectLine(subpath, paint, style);
|
|
247
275
|
}
|
|
248
276
|
function interpretContentStream(bytes, resources, context) {
|
|
249
277
|
const items = [];
|
|
@@ -251,8 +279,10 @@ function interpretContentStream(bytes, resources, context) {
|
|
|
251
279
|
ctm: IDENTITY_MATRIX,
|
|
252
280
|
fillColor: COLOR_BLACK,
|
|
253
281
|
strokeColor: COLOR_BLACK,
|
|
254
|
-
lineWidth: DEFAULT_LINE_WIDTH_PT
|
|
255
|
-
|
|
282
|
+
lineWidth: DEFAULT_LINE_WIDTH_PT,
|
|
283
|
+
dashArray: [],
|
|
284
|
+
...initialTextParameters()
|
|
285
|
+
}, context, items, 0, []);
|
|
256
286
|
return items;
|
|
257
287
|
}
|
|
258
288
|
function lastPointOf(subpath) {
|
|
@@ -265,13 +295,45 @@ function lastPointOf(subpath) {
|
|
|
265
295
|
y: last.yPt
|
|
266
296
|
};
|
|
267
297
|
}
|
|
268
|
-
function runContentStream(bytes, resources, initialState, context, items, depth) {
|
|
298
|
+
function runContentStream(bytes, resources, initialState, context, items, depth, markedContent) {
|
|
269
299
|
const operations = readContentStream(bytes, context.sink);
|
|
270
300
|
const gsStack = [];
|
|
271
301
|
let gs = initialState;
|
|
272
|
-
let
|
|
302
|
+
let text = defaultTextObjectState();
|
|
273
303
|
let pathSubpaths = [];
|
|
274
304
|
let currentSubpath;
|
|
305
|
+
const inScope = (key) => {
|
|
306
|
+
for (let i = markedContent.length - 1; i >= 0; i--) {
|
|
307
|
+
const frame = markedContent[i];
|
|
308
|
+
if (frame !== void 0 && key in frame) return frame[key];
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
const pushItem = (item) => {
|
|
312
|
+
if (item.kind === "text") {
|
|
313
|
+
const layer = item.layerName ?? inScope("layerName");
|
|
314
|
+
const actualText = inScope("actualText");
|
|
315
|
+
const alt = inScope("alt");
|
|
316
|
+
const mcid = inScope("mcid");
|
|
317
|
+
items.push({
|
|
318
|
+
...item,
|
|
319
|
+
...layer !== void 0 ? { layerName: layer } : {},
|
|
320
|
+
...actualText !== void 0 ? { actualText } : {},
|
|
321
|
+
...alt !== void 0 ? { alt } : {},
|
|
322
|
+
...mcid !== void 0 ? { mcid } : {}
|
|
323
|
+
});
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const layer = item.layerName ?? inScope("layerName");
|
|
327
|
+
const layerStamped = layer === void 0 ? item : {
|
|
328
|
+
...item,
|
|
329
|
+
layerName: layer
|
|
330
|
+
};
|
|
331
|
+
const mcid = inScope("mcid");
|
|
332
|
+
items.push(mcid === void 0 ? layerStamped : {
|
|
333
|
+
...layerStamped,
|
|
334
|
+
mcid
|
|
335
|
+
});
|
|
336
|
+
};
|
|
275
337
|
const finalizeCurrentSubpath = () => {
|
|
276
338
|
if (currentSubpath !== void 0) {
|
|
277
339
|
pathSubpaths.push(currentSubpath);
|
|
@@ -345,36 +407,40 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
345
407
|
widthPt: gs.lineWidth
|
|
346
408
|
} : void 0
|
|
347
409
|
};
|
|
348
|
-
|
|
410
|
+
const strokeStyle = isStrokeOp ? strokeStyleFromDashArray(gs.dashArray) : void 0;
|
|
411
|
+
pushItem(classifyShape(pathSubpaths, paint, strokeStyle) ?? {
|
|
349
412
|
kind: "path",
|
|
350
413
|
subpaths: pathSubpaths,
|
|
351
414
|
fillRule: paintFillRuleFor(operator),
|
|
352
|
-
...paint
|
|
415
|
+
...paint,
|
|
416
|
+
...strokeStyle !== void 0 ? { style: strokeStyle } : {}
|
|
353
417
|
});
|
|
354
418
|
}
|
|
355
419
|
resetPath();
|
|
356
420
|
};
|
|
357
421
|
const advanceThroughString = (codes) => {
|
|
358
|
-
|
|
422
|
+
const fontResourceName = gs.fontResourceName;
|
|
423
|
+
if (fontResourceName === void 0) return;
|
|
359
424
|
let offset = 0;
|
|
360
425
|
while (offset < codes.length) {
|
|
361
|
-
const glyph = context.fontMetrics.glyphAdvance(
|
|
426
|
+
const glyph = context.fontMetrics.glyphAdvance(fontResourceName, resources, codes, offset);
|
|
362
427
|
if (glyph === void 0) context.sink({
|
|
363
428
|
code: "pdf/font-not-resolved",
|
|
364
429
|
severity: "warning",
|
|
365
|
-
message: `could not resolve font resource /${
|
|
430
|
+
message: `could not resolve font resource /${fontResourceName} to compute a glyph advance; assuming a fallback width`
|
|
366
431
|
});
|
|
367
432
|
const widthPer1000 = glyph?.widthPer1000 ?? FALLBACK_GLYPH_WIDTH_PER_1000;
|
|
368
433
|
const byteLength = glyph?.byteLengthConsumed ?? 1;
|
|
369
434
|
const isSingleByteSpace = byteLength === 1 && codes[offset] === 32;
|
|
370
|
-
const tx = (widthPer1000 / 1e3 *
|
|
371
|
-
|
|
435
|
+
const tx = (widthPer1000 / 1e3 * gs.fontSizePt + gs.charSpace + (isSingleByteSpace ? gs.wordSpace : 0)) * gs.horizScale;
|
|
436
|
+
text.tm = multiplyMatrices(translationMatrix(tx, 0), text.tm);
|
|
372
437
|
offset += byteLength;
|
|
373
438
|
}
|
|
374
439
|
};
|
|
375
440
|
const showTextArray = (elements) => {
|
|
376
|
-
|
|
377
|
-
|
|
441
|
+
const fontResourceName = gs.fontResourceName;
|
|
442
|
+
if (fontResourceName === void 0) return;
|
|
443
|
+
const startMatrix = computeTrm(gs, text);
|
|
378
444
|
const chunks = [];
|
|
379
445
|
let totalLength = 0;
|
|
380
446
|
for (const el of elements) if (el.kind === "string") {
|
|
@@ -382,8 +448,8 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
382
448
|
totalLength += el.bytes.length;
|
|
383
449
|
advanceThroughString(el.bytes);
|
|
384
450
|
} else if (el.kind === "number") {
|
|
385
|
-
const adjustment = -(el.value / 1e3) *
|
|
386
|
-
|
|
451
|
+
const adjustment = -(el.value / 1e3) * gs.fontSizePt * gs.horizScale;
|
|
452
|
+
text.tm = multiplyMatrices(translationMatrix(adjustment, 0), text.tm);
|
|
387
453
|
}
|
|
388
454
|
if (totalLength === 0) return;
|
|
389
455
|
const combined = new Uint8Array(totalLength);
|
|
@@ -392,15 +458,15 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
392
458
|
combined.set(chunk, at);
|
|
393
459
|
at += chunk.length;
|
|
394
460
|
}
|
|
395
|
-
const endMatrix = computeTrm(gs
|
|
396
|
-
|
|
461
|
+
const endMatrix = computeTrm(gs, text);
|
|
462
|
+
pushItem({
|
|
397
463
|
kind: "text",
|
|
398
464
|
codes: combined,
|
|
399
|
-
fontResourceName
|
|
465
|
+
fontResourceName,
|
|
400
466
|
resources,
|
|
401
467
|
startMatrix,
|
|
402
468
|
endMatrix,
|
|
403
|
-
sizePt:
|
|
469
|
+
sizePt: gs.fontSizePt,
|
|
404
470
|
color: gs.fillColor
|
|
405
471
|
});
|
|
406
472
|
};
|
|
@@ -412,8 +478,8 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
412
478
|
}]);
|
|
413
479
|
};
|
|
414
480
|
const nextLine = () => {
|
|
415
|
-
|
|
416
|
-
|
|
481
|
+
text.tlm = multiplyMatrices(translationMatrix(0, -gs.leading), text.tlm);
|
|
482
|
+
text.tm = text.tlm;
|
|
417
483
|
};
|
|
418
484
|
const handleDo = (name) => {
|
|
419
485
|
if (name === void 0) return;
|
|
@@ -428,12 +494,14 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
428
494
|
return;
|
|
429
495
|
}
|
|
430
496
|
const subtype = asName(dictGet(xobj.dict, "Subtype"));
|
|
497
|
+
const ownLayer = context.layerNameOf?.(dictGet(xobj.dict, "OC"));
|
|
431
498
|
if (subtype === "Image") {
|
|
432
|
-
|
|
499
|
+
pushItem({
|
|
433
500
|
kind: "image",
|
|
434
501
|
resourceName: name,
|
|
435
502
|
resources,
|
|
436
|
-
matrix: gs.ctm
|
|
503
|
+
matrix: gs.ctm,
|
|
504
|
+
...ownLayer !== void 0 ? { layerName: ownLayer } : {}
|
|
437
505
|
});
|
|
438
506
|
return;
|
|
439
507
|
}
|
|
@@ -454,12 +522,17 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
454
522
|
...gs,
|
|
455
523
|
ctm: multiplyMatrices(formMatrix, gs.ctm)
|
|
456
524
|
};
|
|
457
|
-
|
|
525
|
+
const formLayer = ownLayer ?? inScope("layerName");
|
|
526
|
+
const formMcid = dictGet(xobj.dict, "StructParents") !== void 0 ? void 0 : inScope("mcid");
|
|
527
|
+
runContentStream(decoded.bytes, formResources, formState, context, items, depth + 1, [{
|
|
528
|
+
...formLayer !== void 0 ? { layerName: formLayer } : {},
|
|
529
|
+
...formMcid !== void 0 ? { mcid: formMcid } : {}
|
|
530
|
+
}]);
|
|
458
531
|
}
|
|
459
532
|
};
|
|
460
533
|
for (const token of operations) {
|
|
461
534
|
if (token.kind === "inlineImage") {
|
|
462
|
-
|
|
535
|
+
pushItem({
|
|
463
536
|
kind: "inlineImage",
|
|
464
537
|
dict: token.image.dict,
|
|
465
538
|
data: token.image.data,
|
|
@@ -639,6 +712,12 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
639
712
|
lineWidth: numAt(operands, 0)
|
|
640
713
|
};
|
|
641
714
|
break;
|
|
715
|
+
case "d":
|
|
716
|
+
gs = {
|
|
717
|
+
...gs,
|
|
718
|
+
dashArray: (asArray(operands[0]) ?? []).map((entry) => asNumber(entry) ?? 0)
|
|
719
|
+
};
|
|
720
|
+
break;
|
|
642
721
|
case "f":
|
|
643
722
|
case "F":
|
|
644
723
|
case "f*":
|
|
@@ -652,39 +731,60 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
652
731
|
emitPaint(operator);
|
|
653
732
|
break;
|
|
654
733
|
case "BT":
|
|
655
|
-
|
|
734
|
+
text = defaultTextObjectState();
|
|
656
735
|
break;
|
|
657
736
|
case "Tf":
|
|
658
|
-
|
|
659
|
-
|
|
737
|
+
gs = {
|
|
738
|
+
...gs,
|
|
739
|
+
fontResourceName: asName(operands[0]),
|
|
740
|
+
fontSizePt: numAt(operands, 1)
|
|
741
|
+
};
|
|
660
742
|
break;
|
|
661
743
|
case "Tc":
|
|
662
|
-
|
|
744
|
+
gs = {
|
|
745
|
+
...gs,
|
|
746
|
+
charSpace: numAt(operands, 0)
|
|
747
|
+
};
|
|
663
748
|
break;
|
|
664
749
|
case "Tw":
|
|
665
|
-
|
|
750
|
+
gs = {
|
|
751
|
+
...gs,
|
|
752
|
+
wordSpace: numAt(operands, 0)
|
|
753
|
+
};
|
|
666
754
|
break;
|
|
667
755
|
case "Tz":
|
|
668
|
-
|
|
756
|
+
gs = {
|
|
757
|
+
...gs,
|
|
758
|
+
horizScale: numAt(operands, 0) / 100
|
|
759
|
+
};
|
|
669
760
|
break;
|
|
670
761
|
case "TL":
|
|
671
|
-
|
|
762
|
+
gs = {
|
|
763
|
+
...gs,
|
|
764
|
+
leading: numAt(operands, 0)
|
|
765
|
+
};
|
|
672
766
|
break;
|
|
673
767
|
case "Ts":
|
|
674
|
-
|
|
768
|
+
gs = {
|
|
769
|
+
...gs,
|
|
770
|
+
rise: numAt(operands, 0)
|
|
771
|
+
};
|
|
675
772
|
break;
|
|
676
773
|
case "Td":
|
|
677
|
-
|
|
678
|
-
|
|
774
|
+
text.tlm = multiplyMatrices(translationMatrix(numAt(operands, 0), numAt(operands, 1)), text.tlm);
|
|
775
|
+
text.tm = text.tlm;
|
|
679
776
|
break;
|
|
680
777
|
case "TD":
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
778
|
+
gs = {
|
|
779
|
+
...gs,
|
|
780
|
+
leading: -numAt(operands, 1)
|
|
781
|
+
};
|
|
782
|
+
text.tlm = multiplyMatrices(translationMatrix(numAt(operands, 0), numAt(operands, 1)), text.tlm);
|
|
783
|
+
text.tm = text.tlm;
|
|
684
784
|
break;
|
|
685
785
|
case "Tm":
|
|
686
|
-
|
|
687
|
-
|
|
786
|
+
text.tlm = matrixFromOperands(operands);
|
|
787
|
+
text.tm = text.tlm;
|
|
688
788
|
break;
|
|
689
789
|
case "T*":
|
|
690
790
|
nextLine();
|
|
@@ -701,8 +801,11 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
701
801
|
break;
|
|
702
802
|
}
|
|
703
803
|
case "\"": {
|
|
704
|
-
|
|
705
|
-
|
|
804
|
+
gs = {
|
|
805
|
+
...gs,
|
|
806
|
+
wordSpace: numAt(operands, 0),
|
|
807
|
+
charSpace: numAt(operands, 1)
|
|
808
|
+
};
|
|
706
809
|
nextLine();
|
|
707
810
|
const str = operands[2];
|
|
708
811
|
if (str?.kind === "string") showText(str.bytes);
|
|
@@ -713,7 +816,26 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
713
816
|
if (array !== void 0) showTextArray(array);
|
|
714
817
|
break;
|
|
715
818
|
}
|
|
716
|
-
case "Do":
|
|
819
|
+
case "Do":
|
|
820
|
+
handleDo(asName(operands[0]));
|
|
821
|
+
break;
|
|
822
|
+
case "BDC": {
|
|
823
|
+
const props = markedContentProperties(operands[1], resources, context.resolver);
|
|
824
|
+
const layerName = context.layerNameOf?.(props === void 0 ? void 0 : dictGet(props, "OC"));
|
|
825
|
+
const scopeProps = {
|
|
826
|
+
...layerName !== void 0 ? { layerName } : {},
|
|
827
|
+
...markedContentScopeProps(props)
|
|
828
|
+
};
|
|
829
|
+
markedContent.push(depth === 0 ? scopeProps : {
|
|
830
|
+
...scopeProps,
|
|
831
|
+
mcid: void 0
|
|
832
|
+
});
|
|
833
|
+
break;
|
|
834
|
+
}
|
|
835
|
+
case "BMC":
|
|
836
|
+
markedContent.push({});
|
|
837
|
+
break;
|
|
838
|
+
case "EMC": markedContent.pop();
|
|
717
839
|
}
|
|
718
840
|
}
|
|
719
841
|
}
|