pdf-codec 3.1.3 → 3.2.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/README.md +2 -2
- 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/bytes/flate.cjs +1 -1
- package/dist/bytes/flate.js +1 -1
- package/dist/codec.d.cts +109 -0
- package/dist/codec.d.ts +109 -0
- package/dist/content-read.cjs +1 -1
- package/dist/content-read.js +1 -1
- package/dist/content-write.cjs +2 -2
- package/dist/content-write.js +2 -2
- package/dist/document.cjs +12 -3
- package/dist/document.d.cts +2 -0
- package/dist/document.d.ts +2 -0
- package/dist/document.js +12 -3
- package/dist/embedded-font-write.cjs +1 -1
- package/dist/embedded-font-write.js +1 -1
- package/dist/encrypt.cjs +1 -1
- package/dist/encrypt.js +1 -1
- package/dist/filters.cjs +1 -1
- package/dist/filters.js +1 -1
- package/dist/font-read.cjs +1 -1
- package/dist/font-read.js +1 -1
- package/dist/font-registry.cjs +1 -1
- package/dist/font-registry.js +1 -1
- 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/image/png-decode.cjs +1 -1
- package/dist/image/png-decode.js +1 -1
- package/dist/image/png-encode.cjs +1 -1
- package/dist/image/png-encode.js +1 -1
- package/dist/index.cjs +12 -2
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/interpret.cjs +70 -10
- package/dist/interpret.d.cts +9 -1
- package/dist/interpret.d.ts +9 -1
- package/dist/interpret.js +70 -10
- package/dist/layout.cjs +132 -2
- package/dist/layout.d.cts +335 -1
- package/dist/layout.d.ts +335 -1
- package/dist/layout.js +124 -4
- package/dist/math-content-write.cjs +1 -1
- package/dist/math-content-write.js +1 -1
- package/dist/math-font.cjs +1 -1
- package/dist/math-font.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/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 +1 -1
- package/dist/parse.d.ts +1 -1
- 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/read.cjs +128 -58
- package/dist/read.d.cts +2 -4
- package/dist/read.d.ts +2 -4
- package/dist/read.js +125 -53
- 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/write.cjs +51 -5
- package/dist/write.js +51 -5
- 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.js +2 -2
- package/package.json +2 -2
package/dist/form.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { asArray, asName, asNumber, dictGet } from "./objects.js";
|
|
2
|
+
import { decodePdfString } from "./pdf-text.js";
|
|
3
|
+
//#region src/form.ts
|
|
4
|
+
const FLAG_READ_ONLY = 1;
|
|
5
|
+
const FLAG_PUSHBUTTON = 4;
|
|
6
|
+
const FLAG_RADIO = 32768;
|
|
7
|
+
const FLAG_COMBO = 131072;
|
|
8
|
+
function readAcroForm(catalog, resolver, pageIndex, sink) {
|
|
9
|
+
const acroForm = resolver.resolveDict(dictGet(catalog, "AcroForm"));
|
|
10
|
+
if (acroForm === void 0) return [];
|
|
11
|
+
const fields = [];
|
|
12
|
+
const visited = /* @__PURE__ */ new Set();
|
|
13
|
+
for (const fieldRef of asArray(resolver.resolve(dictGet(acroForm, "Fields"))) ?? []) {
|
|
14
|
+
const fieldDict = resolver.resolveDict(fieldRef);
|
|
15
|
+
if (fieldDict !== void 0) readField(fieldDict, "", resolver, pageIndex, sink, fields, visited);
|
|
16
|
+
}
|
|
17
|
+
return fields;
|
|
18
|
+
}
|
|
19
|
+
function readField(node, parentName, resolver, pageIndex, sink, out, visited) {
|
|
20
|
+
if (visited.has(node)) {
|
|
21
|
+
sink({
|
|
22
|
+
code: "pdf/form-field-cycle",
|
|
23
|
+
severity: "warning",
|
|
24
|
+
message: "the AcroForm field tree contains a cycle; stopping descent at the repeated field"
|
|
25
|
+
});
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
visited.add(node);
|
|
29
|
+
const ownName = annotText(node, "T");
|
|
30
|
+
const name = ownName === void 0 ? parentName : parentName.length > 0 ? `${parentName}.${ownName}` : ownName;
|
|
31
|
+
const fieldObj = dictGet(node, "FT");
|
|
32
|
+
const fieldType = asName(fieldObj);
|
|
33
|
+
if (fieldType === void 0) {
|
|
34
|
+
const children = [];
|
|
35
|
+
for (const kidRef of asArray(resolver.resolve(dictGet(node, "Kids"))) ?? []) {
|
|
36
|
+
const kid = resolver.resolveDict(kidRef);
|
|
37
|
+
if (kid !== void 0) readField(kid, name, resolver, pageIndex, sink, children, visited);
|
|
38
|
+
}
|
|
39
|
+
out.push({
|
|
40
|
+
name,
|
|
41
|
+
fieldType: "group",
|
|
42
|
+
widgets: [],
|
|
43
|
+
children
|
|
44
|
+
});
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const flags = asNumber(resolver.resolve(dictGet(node, "Ff"))) ?? 0;
|
|
48
|
+
const value = fieldValue(node, resolver);
|
|
49
|
+
const options = fieldOptions(node, resolver);
|
|
50
|
+
const alias = annotText(node, "TU");
|
|
51
|
+
const widgets = [];
|
|
52
|
+
for (const kidRef of asArray(resolver.resolve(dictGet(node, "Kids"))) ?? []) {
|
|
53
|
+
const kid = resolver.resolveDict(kidRef);
|
|
54
|
+
if (kid === void 0 || dictGet(kid, "FT") !== void 0) continue;
|
|
55
|
+
const widget = widgetPlacement(kid, pageIndex);
|
|
56
|
+
if (widget !== void 0) widgets.push(widget);
|
|
57
|
+
}
|
|
58
|
+
if (widgets.length === 0 && dictGet(node, "Rect") !== void 0) {
|
|
59
|
+
const widget = widgetPlacement(node, pageIndex);
|
|
60
|
+
if (widget !== void 0) widgets.push(widget);
|
|
61
|
+
}
|
|
62
|
+
out.push({
|
|
63
|
+
name,
|
|
64
|
+
fieldType: mapFieldType(fieldType, flags),
|
|
65
|
+
...valueFields(fieldType, value),
|
|
66
|
+
...options !== void 0 ? { options } : {},
|
|
67
|
+
...alias !== void 0 ? { alias } : {},
|
|
68
|
+
...(flags & FLAG_READ_ONLY) !== 0 ? { readOnly: true } : {},
|
|
69
|
+
widgets,
|
|
70
|
+
children: []
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function mapFieldType(fieldType, flags) {
|
|
74
|
+
if (fieldType === "Tx") return "text";
|
|
75
|
+
if (fieldType === "Btn") {
|
|
76
|
+
if ((flags & FLAG_PUSHBUTTON) !== 0) return "button";
|
|
77
|
+
if ((flags & FLAG_RADIO) !== 0) return "radio";
|
|
78
|
+
return "checkbox";
|
|
79
|
+
}
|
|
80
|
+
if (fieldType === "Ch") return (flags & FLAG_COMBO) !== 0 ? "combobox" : "listbox";
|
|
81
|
+
return "signature";
|
|
82
|
+
}
|
|
83
|
+
function valueFields(fieldType, value) {
|
|
84
|
+
if (value === void 0) return {};
|
|
85
|
+
if (fieldType === "Btn") return {
|
|
86
|
+
checked: value !== "Off",
|
|
87
|
+
...value !== "Off" ? { value } : {}
|
|
88
|
+
};
|
|
89
|
+
if (fieldType === "Sig") return {};
|
|
90
|
+
return { value };
|
|
91
|
+
}
|
|
92
|
+
function fieldValue(node, resolver) {
|
|
93
|
+
const value = resolver.resolve(dictGet(node, "V"));
|
|
94
|
+
if (value?.kind === "string") return decodePdfString(value.bytes);
|
|
95
|
+
if (value?.kind === "name") return value.name;
|
|
96
|
+
if (value?.kind === "number") return String(value.value);
|
|
97
|
+
}
|
|
98
|
+
function fieldOptions(node, resolver) {
|
|
99
|
+
const opts = asArray(resolver.resolve(dictGet(node, "Opt")));
|
|
100
|
+
if (opts === void 0) return;
|
|
101
|
+
const values = [];
|
|
102
|
+
for (const opt of opts) {
|
|
103
|
+
const resolved = resolver.resolve(opt);
|
|
104
|
+
if (resolved?.kind === "string") values.push(decodePdfString(resolved.bytes));
|
|
105
|
+
else if (resolved?.kind === "array") {
|
|
106
|
+
const first = resolved.items[0];
|
|
107
|
+
const exportValue = first?.kind === "string" ? decodePdfString(first.bytes) : first?.kind === "name" ? first.name : void 0;
|
|
108
|
+
if (exportValue !== void 0) values.push(exportValue);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return values.length > 0 ? values : void 0;
|
|
112
|
+
}
|
|
113
|
+
function widgetPlacement(widget, pageIndex) {
|
|
114
|
+
const pageNo = pageIndex(dictGet(widget, "P"));
|
|
115
|
+
if (pageNo === void 0) return;
|
|
116
|
+
return rectWidget(asArray(dictGet(widget, "Rect")), pageNo);
|
|
117
|
+
}
|
|
118
|
+
function rectWidget(rect, pageNo) {
|
|
119
|
+
if (rect === void 0) return;
|
|
120
|
+
const x1 = asNumber(rect[0]) ?? 0;
|
|
121
|
+
const y1 = asNumber(rect[1]) ?? 0;
|
|
122
|
+
const x2 = asNumber(rect[2]) ?? 0;
|
|
123
|
+
const y2 = asNumber(rect[3]) ?? 0;
|
|
124
|
+
return {
|
|
125
|
+
pageIndex: pageNo,
|
|
126
|
+
xPt: Math.min(x1, x2),
|
|
127
|
+
yPt: Math.min(y1, y2),
|
|
128
|
+
widthPt: Math.abs(x2 - x1),
|
|
129
|
+
heightPt: Math.abs(y2 - y1)
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function annotText(dict, key) {
|
|
133
|
+
const obj = dictGet(dict, key);
|
|
134
|
+
return obj?.kind === "string" ? decodePdfString(obj.bytes) : void 0;
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
export { readAcroForm };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_bytes_crc32 = require("../bytes/crc32.cjs");
|
|
3
2
|
const require_bytes_writer = require("../bytes/writer.cjs");
|
|
4
3
|
const require_bytes_flate = require("../bytes/flate.cjs");
|
|
5
4
|
const require_image_png_filter = require("./png-filter.cjs");
|
|
5
|
+
const require_bytes_crc32 = require("../bytes/crc32.cjs");
|
|
6
6
|
//#region src/image/png-decode.ts
|
|
7
7
|
const PNG_SIGNATURE = [
|
|
8
8
|
137,
|
package/dist/image/png-decode.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { crc32 } from "../bytes/crc32.js";
|
|
2
1
|
import { concatBytes } from "../bytes/writer.js";
|
|
3
2
|
import { inflateTolerant } from "../bytes/flate.js";
|
|
4
3
|
import { unfilterScanlines } from "./png-filter.js";
|
|
4
|
+
import { crc32 } from "../bytes/crc32.js";
|
|
5
5
|
//#region src/image/png-decode.ts
|
|
6
6
|
const PNG_SIGNATURE = [
|
|
7
7
|
137,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_bytes_crc32 = require("../bytes/crc32.cjs");
|
|
3
2
|
const require_bytes_writer = require("../bytes/writer.cjs");
|
|
4
3
|
const require_bytes_flate = require("../bytes/flate.cjs");
|
|
5
4
|
const require_image_png_filter = require("./png-filter.cjs");
|
|
5
|
+
const require_bytes_crc32 = require("../bytes/crc32.cjs");
|
|
6
6
|
//#region src/image/png-encode.ts
|
|
7
7
|
const PNG_SIGNATURE = new Uint8Array([
|
|
8
8
|
137,
|
package/dist/image/png-encode.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { crc32 } from "../bytes/crc32.js";
|
|
2
1
|
import { ByteWriter, concatBytes } from "../bytes/writer.js";
|
|
3
2
|
import { deflate } from "../bytes/flate.js";
|
|
4
3
|
import { filterScanlines } from "./png-filter.js";
|
|
4
|
+
import { crc32 } from "../bytes/crc32.js";
|
|
5
5
|
//#region src/image/png-encode.ts
|
|
6
6
|
const PNG_SIGNATURE = new Uint8Array([
|
|
7
7
|
137,
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_afm_widths = require("./afm-widths-BoeTOK2r.cjs");
|
|
3
|
-
const require_layout = require("./layout.cjs");
|
|
4
|
-
const require_diagnostics = require("./diagnostics.cjs");
|
|
5
3
|
const require_image_ccitt = require("./image/ccitt.cjs");
|
|
6
4
|
const require_image_jbig2_errors = require("./image/jbig2-errors.cjs");
|
|
7
5
|
const require_image_jbig2 = require("./image/jbig2.cjs");
|
|
8
6
|
const require_image_png_filter = require("./image/png-filter.cjs");
|
|
7
|
+
const require_layout = require("./layout.cjs");
|
|
8
|
+
const require_diagnostics = require("./diagnostics.cjs");
|
|
9
9
|
const require_fonts = require("./fonts.cjs");
|
|
10
10
|
const require_image_jpeg2000_errors = require("./image/jpeg2000-errors.cjs");
|
|
11
11
|
const require_image_jp2_boxes = require("./image/jp2-boxes.cjs");
|
|
@@ -25,13 +25,23 @@ exports.Jbig2UnsupportedError = require_image_jbig2_errors.Jbig2UnsupportedError
|
|
|
25
25
|
exports.Jpeg2000ParseError = require_image_jpeg2000_errors.Jpeg2000ParseError;
|
|
26
26
|
exports.Jpeg2000UnsupportedError = require_image_jpeg2000_errors.Jpeg2000UnsupportedError;
|
|
27
27
|
exports.LAYOUT_FORMAT_VERSION = require_layout.LAYOUT_FORMAT_VERSION;
|
|
28
|
+
exports.LayoutAnnotationQuadSchema = require_layout.LayoutAnnotationQuadSchema;
|
|
29
|
+
exports.LayoutAnnotationSchema = require_layout.LayoutAnnotationSchema;
|
|
30
|
+
exports.LayoutAttachmentSchema = require_layout.LayoutAttachmentSchema;
|
|
31
|
+
exports.LayoutDestinationSchema = require_layout.LayoutDestinationSchema;
|
|
32
|
+
exports.LayoutDestinationTargetSchema = require_layout.LayoutDestinationTargetSchema;
|
|
28
33
|
exports.LayoutDocumentSchema = require_layout.LayoutDocumentSchema;
|
|
29
34
|
exports.LayoutEllipseSchema = require_layout.LayoutEllipseSchema;
|
|
35
|
+
exports.LayoutFormFieldSchema = require_layout.LayoutFormFieldSchema;
|
|
36
|
+
exports.LayoutFormWidgetSchema = require_layout.LayoutFormWidgetSchema;
|
|
30
37
|
exports.LayoutImageAssetSchema = require_layout.LayoutImageAssetSchema;
|
|
31
38
|
exports.LayoutImageSchema = require_layout.LayoutImageSchema;
|
|
39
|
+
exports.LayoutInternalLinkSchema = require_layout.LayoutInternalLinkSchema;
|
|
32
40
|
exports.LayoutItemSchema = require_layout.LayoutItemSchema;
|
|
41
|
+
exports.LayoutLayerSchema = require_layout.LayoutLayerSchema;
|
|
33
42
|
exports.LayoutLineSchema = require_layout.LayoutLineSchema;
|
|
34
43
|
exports.LayoutLinkSchema = require_layout.LayoutLinkSchema;
|
|
44
|
+
exports.LayoutOutlineItemSchema = require_layout.LayoutOutlineItemSchema;
|
|
35
45
|
exports.LayoutPageSchema = require_layout.LayoutPageSchema;
|
|
36
46
|
exports.LayoutPathSchema = require_layout.LayoutPathSchema;
|
|
37
47
|
exports.LayoutPathSegmentSchema = require_layout.LayoutPathSegmentSchema;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { n as STANDARD_METRICS, r as StandardFontName, t as FontMetrics } from "./afm-widths-DyDq56Ph.cjs";
|
|
2
|
-
import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.cjs";
|
|
3
2
|
import { NOOP_DIAGNOSTIC_SINK, PdfDiagnostic, PdfDiagnosticSeverity, PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError } from "./diagnostics.cjs";
|
|
3
|
+
import { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema } from "./layout.cjs";
|
|
4
|
+
import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.cjs";
|
|
4
5
|
import { PdfBytesSchema, pdfCodec } from "./codec.cjs";
|
|
5
|
-
import { LAYOUT_FORMAT_VERSION, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutItem, LayoutItemSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema } from "./layout.cjs";
|
|
6
6
|
import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-BU6Jgcof.cjs";
|
|
7
7
|
import { WinAnsiSubstitution } from "./winansi.cjs";
|
|
8
8
|
import { FontFace, FontFaceParseError, readFontFace } from "./font-face.cjs";
|
|
@@ -24,4 +24,4 @@ import { LoadedMathFont, MathFont, MathFontDescriptorMetrics, loadMathFont } fro
|
|
|
24
24
|
import { DEFAULT_VERTICAL_METRIC_POLICY, FontMeasurerOptions, StandardFontMeasurerOptions, VerticalMetricPolicy, createFontMeasurer, createStandardFontMeasurer } from "./measure.cjs";
|
|
25
25
|
import { FontRegistryOptions, FontSubstitution, MathAssembledGlyphs, MathBox, MathColor, MathFontMetrics, MathGlyphMetrics, MathGlyphPlacement, MathGlyphRun, MathLayoutItem, MathRule, MathStretchAxis, MathStretchGlyph, MathStretchResult, MathStroke, Point, PositionedFormula, ProvidedFont, StyledFragment, StyledRun, TextMeasurer, UnderlineMetrics, WrapOptions, WrappedLine } from "document-schema.js";
|
|
26
26
|
export * from "byte-codec";
|
|
27
|
-
export { type CcittFaxImage, type CcittFaxOptions, DEFAULT_VERTICAL_METRIC_POLICY, type EmbeddedFace, type EmbeddedFaceMetrics, type EmbeddedFaceSubstitution, type FontFace, FontFaceParseError, type FontMeasurerOptions, type FontMetrics, type FontRegistry, type FontRegistryOptions, type FontSubstitution, type GlyphInkBounds, type Jbig2DecodeOptions, type Jbig2Image, Jbig2ParseError, Jbig2UnsupportedError, type Jp2ChannelDefinition, type Jp2ColourSpace, type Jp2Container, type Jp2ImageHeader, type Jpeg2000ComponentMetadata, type Jpeg2000DecodeOptions, type Jpeg2000Image, type Jpeg2000Metadata, Jpeg2000ParseError, type Jpeg2000ProgressionOrder, type Jpeg2000QuantizationStyle, type Jpeg2000Transform, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutItem, LayoutItemSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema, type LoadedMathFont, type MathAssembledGlyphs, type MathBox, type MathColor, type MathFont, type MathFontDescriptorMetrics, type MathFontMetrics, type MathGlyphAssembly, type MathGlyphConstruction, type MathGlyphMetrics, type MathGlyphPart, type MathGlyphPlacement, type MathGlyphRun, type MathGlyphVariant, type MathLayoutItem, type MathRule, type MathStretchAxis, type MathStretchConstruction, type MathStretchGlyph, type MathStretchOptions, type MathStretchPlacement, type MathStretchResult, type MathStroke, type MathVariants, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, type Point, type PositionedFormula, type ProvidedFont, type ReadPdfOptions, type ResolvedFace, type ResolvedFont, STANDARD_METRICS, type StandardFontMeasurerOptions, type StandardFontName, type StyledFragment, type StyledRun, type TextMeasurer, type UnderlineMetrics, type VerticalMetricPolicy, type WinAnsiSubstitution, type WrapOptions, type WrappedLine, type WritePdfOptions, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
|
|
27
|
+
export { type CcittFaxImage, type CcittFaxOptions, DEFAULT_VERTICAL_METRIC_POLICY, type EmbeddedFace, type EmbeddedFaceMetrics, type EmbeddedFaceSubstitution, type FontFace, FontFaceParseError, type FontMeasurerOptions, type FontMetrics, type FontRegistry, type FontRegistryOptions, type FontSubstitution, type GlyphInkBounds, type Jbig2DecodeOptions, type Jbig2Image, Jbig2ParseError, Jbig2UnsupportedError, type Jp2ChannelDefinition, type Jp2ColourSpace, type Jp2Container, type Jp2ImageHeader, type Jpeg2000ComponentMetadata, type Jpeg2000DecodeOptions, type Jpeg2000Image, type Jpeg2000Metadata, Jpeg2000ParseError, type Jpeg2000ProgressionOrder, type Jpeg2000QuantizationStyle, type Jpeg2000Transform, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema, type LoadedMathFont, type MathAssembledGlyphs, type MathBox, type MathColor, type MathFont, type MathFontDescriptorMetrics, type MathFontMetrics, type MathGlyphAssembly, type MathGlyphConstruction, type MathGlyphMetrics, type MathGlyphPart, type MathGlyphPlacement, type MathGlyphRun, type MathGlyphVariant, type MathLayoutItem, type MathRule, type MathStretchAxis, type MathStretchConstruction, type MathStretchGlyph, type MathStretchOptions, type MathStretchPlacement, type MathStretchResult, type MathStroke, type MathVariants, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, type Point, type PositionedFormula, type ProvidedFont, type ReadPdfOptions, type ResolvedFace, type ResolvedFont, STANDARD_METRICS, type StandardFontMeasurerOptions, type StandardFontName, type StyledFragment, type StyledRun, type TextMeasurer, type UnderlineMetrics, type VerticalMetricPolicy, type WinAnsiSubstitution, type WrapOptions, type WrappedLine, type WritePdfOptions, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { n as STANDARD_METRICS, r as StandardFontName, t as FontMetrics } from "./afm-widths-DyDq56Ph.js";
|
|
2
|
-
import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.js";
|
|
3
2
|
import { NOOP_DIAGNOSTIC_SINK, PdfDiagnostic, PdfDiagnosticSeverity, PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError } from "./diagnostics.js";
|
|
3
|
+
import { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema } from "./layout.js";
|
|
4
|
+
import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.js";
|
|
4
5
|
import { PdfBytesSchema, pdfCodec } from "./codec.js";
|
|
5
|
-
import { LAYOUT_FORMAT_VERSION, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutItem, LayoutItemSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema } from "./layout.js";
|
|
6
6
|
import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-fREdbxnr.js";
|
|
7
7
|
import { WinAnsiSubstitution } from "./winansi.js";
|
|
8
8
|
import { FontFace, FontFaceParseError, readFontFace } from "./font-face.js";
|
|
@@ -24,4 +24,4 @@ import { LoadedMathFont, MathFont, MathFontDescriptorMetrics, loadMathFont } fro
|
|
|
24
24
|
import { DEFAULT_VERTICAL_METRIC_POLICY, FontMeasurerOptions, StandardFontMeasurerOptions, VerticalMetricPolicy, createFontMeasurer, createStandardFontMeasurer } from "./measure.js";
|
|
25
25
|
import { FontRegistryOptions, FontSubstitution, MathAssembledGlyphs, MathBox, MathColor, MathFontMetrics, MathGlyphMetrics, MathGlyphPlacement, MathGlyphRun, MathLayoutItem, MathRule, MathStretchAxis, MathStretchGlyph, MathStretchResult, MathStroke, Point, PositionedFormula, ProvidedFont, StyledFragment, StyledRun, TextMeasurer, UnderlineMetrics, WrapOptions, WrappedLine } from "document-schema.js";
|
|
26
26
|
export * from "byte-codec";
|
|
27
|
-
export { type CcittFaxImage, type CcittFaxOptions, DEFAULT_VERTICAL_METRIC_POLICY, type EmbeddedFace, type EmbeddedFaceMetrics, type EmbeddedFaceSubstitution, type FontFace, FontFaceParseError, type FontMeasurerOptions, type FontMetrics, type FontRegistry, type FontRegistryOptions, type FontSubstitution, type GlyphInkBounds, type Jbig2DecodeOptions, type Jbig2Image, Jbig2ParseError, Jbig2UnsupportedError, type Jp2ChannelDefinition, type Jp2ColourSpace, type Jp2Container, type Jp2ImageHeader, type Jpeg2000ComponentMetadata, type Jpeg2000DecodeOptions, type Jpeg2000Image, type Jpeg2000Metadata, Jpeg2000ParseError, type Jpeg2000ProgressionOrder, type Jpeg2000QuantizationStyle, type Jpeg2000Transform, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutItem, LayoutItemSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema, type LoadedMathFont, type MathAssembledGlyphs, type MathBox, type MathColor, type MathFont, type MathFontDescriptorMetrics, type MathFontMetrics, type MathGlyphAssembly, type MathGlyphConstruction, type MathGlyphMetrics, type MathGlyphPart, type MathGlyphPlacement, type MathGlyphRun, type MathGlyphVariant, type MathLayoutItem, type MathRule, type MathStretchAxis, type MathStretchConstruction, type MathStretchGlyph, type MathStretchOptions, type MathStretchPlacement, type MathStretchResult, type MathStroke, type MathVariants, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, type Point, type PositionedFormula, type ProvidedFont, type ReadPdfOptions, type ResolvedFace, type ResolvedFont, STANDARD_METRICS, type StandardFontMeasurerOptions, type StandardFontName, type StyledFragment, type StyledRun, type TextMeasurer, type UnderlineMetrics, type VerticalMetricPolicy, type WinAnsiSubstitution, type WrapOptions, type WrappedLine, type WritePdfOptions, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
|
|
27
|
+
export { type CcittFaxImage, type CcittFaxOptions, DEFAULT_VERTICAL_METRIC_POLICY, type EmbeddedFace, type EmbeddedFaceMetrics, type EmbeddedFaceSubstitution, type FontFace, FontFaceParseError, type FontMeasurerOptions, type FontMetrics, type FontRegistry, type FontRegistryOptions, type FontSubstitution, type GlyphInkBounds, type Jbig2DecodeOptions, type Jbig2Image, Jbig2ParseError, Jbig2UnsupportedError, type Jp2ChannelDefinition, type Jp2ColourSpace, type Jp2Container, type Jp2ImageHeader, type Jpeg2000ComponentMetadata, type Jpeg2000DecodeOptions, type Jpeg2000Image, type Jpeg2000Metadata, Jpeg2000ParseError, type Jpeg2000ProgressionOrder, type Jpeg2000QuantizationStyle, type Jpeg2000Transform, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema, type LoadedMathFont, type MathAssembledGlyphs, type MathBox, type MathColor, type MathFont, type MathFontDescriptorMetrics, type MathFontMetrics, type MathGlyphAssembly, type MathGlyphConstruction, type MathGlyphMetrics, type MathGlyphPart, type MathGlyphPlacement, type MathGlyphRun, type MathGlyphVariant, type MathLayoutItem, type MathRule, type MathStretchAxis, type MathStretchConstruction, type MathStretchGlyph, type MathStretchOptions, type MathStretchPlacement, type MathStretchResult, type MathStroke, type MathVariants, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, type Point, type PositionedFormula, type ProvidedFont, type ReadPdfOptions, type ResolvedFace, type ResolvedFont, STANDARD_METRICS, type StandardFontMeasurerOptions, type StandardFontName, type StyledFragment, type StyledRun, type TextMeasurer, type UnderlineMetrics, type VerticalMetricPolicy, type WinAnsiSubstitution, type WrapOptions, type WrappedLine, type WritePdfOptions, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as STANDARD_METRICS } from "./afm-widths-Dxucrg7D.js";
|
|
2
|
-
import { LAYOUT_FORMAT_VERSION, LayoutDocumentSchema, LayoutEllipseSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutItemSchema, LayoutLineSchema, LayoutLinkSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutSubpathSchema, LayoutTextSchema } from "./layout.js";
|
|
3
|
-
import { NOOP_DIAGNOSTIC_SINK, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError } from "./diagnostics.js";
|
|
4
2
|
import { decodeCcittFax } from "./image/ccitt.js";
|
|
5
3
|
import { Jbig2ParseError, Jbig2UnsupportedError } from "./image/jbig2-errors.js";
|
|
6
4
|
import { decodeJbig2Embedded } from "./image/jbig2.js";
|
|
7
5
|
import { filterScanlines, unfilterScanlines } from "./image/png-filter.js";
|
|
6
|
+
import { LAYOUT_FORMAT_VERSION, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachmentSchema, LayoutDestinationSchema, LayoutDestinationTargetSchema, LayoutDocumentSchema, LayoutEllipseSchema, LayoutFormFieldSchema, LayoutFormWidgetSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLinkSchema, LayoutItemSchema, LayoutLayerSchema, LayoutLineSchema, LayoutLinkSchema, LayoutOutlineItemSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutSubpathSchema, LayoutTextSchema } from "./layout.js";
|
|
7
|
+
import { NOOP_DIAGNOSTIC_SINK, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError } from "./diagnostics.js";
|
|
8
8
|
import { resolveStandardFont } from "./fonts.js";
|
|
9
9
|
import { Jpeg2000ParseError, Jpeg2000UnsupportedError } from "./image/jpeg2000-errors.js";
|
|
10
10
|
import { looksLikeBareCodestream, parseJp2Container } from "./image/jp2-boxes.js";
|
|
@@ -18,4 +18,4 @@ import { writePdf } from "./write.js";
|
|
|
18
18
|
import { PdfBytesSchema, pdfCodec } from "./codec.js";
|
|
19
19
|
import { FontFaceParseError, readFontFace } from "./font-face.js";
|
|
20
20
|
export * from "byte-codec";
|
|
21
|
-
export { DEFAULT_VERTICAL_METRIC_POLICY, FontFaceParseError, Jbig2ParseError, Jbig2UnsupportedError, Jpeg2000ParseError, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutDocumentSchema, LayoutEllipseSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutItemSchema, LayoutLineSchema, LayoutLinkSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutSubpathSchema, LayoutTextSchema, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, STANDARD_METRICS, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
|
|
21
|
+
export { DEFAULT_VERTICAL_METRIC_POLICY, FontFaceParseError, Jbig2ParseError, Jbig2UnsupportedError, Jpeg2000ParseError, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachmentSchema, LayoutDestinationSchema, LayoutDestinationTargetSchema, LayoutDocumentSchema, LayoutEllipseSchema, LayoutFormFieldSchema, LayoutFormWidgetSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLinkSchema, LayoutItemSchema, LayoutLayerSchema, LayoutLineSchema, LayoutLinkSchema, LayoutOutlineItemSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutSubpathSchema, LayoutTextSchema, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, STANDARD_METRICS, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
|
package/dist/interpret.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_objects = require("./objects.cjs");
|
|
3
|
-
const
|
|
3
|
+
const require_pdf_text = require("./pdf-text.cjs");
|
|
4
4
|
const require_matrix = require("./matrix.cjs");
|
|
5
|
+
const require_filters = require("./filters.cjs");
|
|
5
6
|
const require_content_read = require("./content-read.cjs");
|
|
6
7
|
let document_schema_js = require("document-schema.js");
|
|
7
8
|
//#region src/interpret.ts
|
|
@@ -35,6 +36,22 @@ function computeTrm(ctm, ts) {
|
|
|
35
36
|
function numAt(operands, index) {
|
|
36
37
|
return require_objects.asNumber(operands[index]) ?? 0;
|
|
37
38
|
}
|
|
39
|
+
function markedContentProperties(operand, resources, resolver) {
|
|
40
|
+
if (operand?.kind === "dict") return operand;
|
|
41
|
+
if (operand?.kind === "name") {
|
|
42
|
+
const properties = resolver.resolveDict(require_objects.dictGet(resources, "Properties"));
|
|
43
|
+
return properties === void 0 ? void 0 : resolver.resolveDict(require_objects.dictGet(properties, operand.name));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function markedContentStrings(props) {
|
|
47
|
+
if (props === void 0) return {};
|
|
48
|
+
const actualTextObj = require_objects.dictGet(props, "ActualText");
|
|
49
|
+
const altObj = require_objects.dictGet(props, "Alt");
|
|
50
|
+
return {
|
|
51
|
+
...actualTextObj?.kind === "string" ? { actualText: require_pdf_text.decodePdfString(actualTextObj.bytes) } : {},
|
|
52
|
+
...altObj?.kind === "string" ? { alt: require_pdf_text.decodePdfString(altObj.bytes) } : {}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
38
55
|
function grayColor(value) {
|
|
39
56
|
return {
|
|
40
57
|
r: value,
|
|
@@ -253,7 +270,7 @@ function interpretContentStream(bytes, resources, context) {
|
|
|
253
270
|
fillColor: document_schema_js.COLOR_BLACK,
|
|
254
271
|
strokeColor: document_schema_js.COLOR_BLACK,
|
|
255
272
|
lineWidth: DEFAULT_LINE_WIDTH_PT
|
|
256
|
-
}, context, items, 0);
|
|
273
|
+
}, context, items, 0, []);
|
|
257
274
|
return items;
|
|
258
275
|
}
|
|
259
276
|
function lastPointOf(subpath) {
|
|
@@ -266,13 +283,38 @@ function lastPointOf(subpath) {
|
|
|
266
283
|
y: last.yPt
|
|
267
284
|
};
|
|
268
285
|
}
|
|
269
|
-
function runContentStream(bytes, resources, initialState, context, items, depth) {
|
|
286
|
+
function runContentStream(bytes, resources, initialState, context, items, depth, markedContent) {
|
|
270
287
|
const operations = require_content_read.readContentStream(bytes, context.sink);
|
|
271
288
|
const gsStack = [];
|
|
272
289
|
let gs = initialState;
|
|
273
290
|
let ts = defaultTextState();
|
|
274
291
|
let pathSubpaths = [];
|
|
275
292
|
let currentSubpath;
|
|
293
|
+
const inScope = (key) => {
|
|
294
|
+
for (let i = markedContent.length - 1; i >= 0; i--) {
|
|
295
|
+
const value = markedContent[i]?.[key];
|
|
296
|
+
if (value !== void 0) return value;
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
const pushItem = (item) => {
|
|
300
|
+
if (item.kind === "text") {
|
|
301
|
+
const layer = item.layerName ?? inScope("layerName");
|
|
302
|
+
const actualText = inScope("actualText");
|
|
303
|
+
const alt = inScope("alt");
|
|
304
|
+
items.push({
|
|
305
|
+
...item,
|
|
306
|
+
...layer !== void 0 ? { layerName: layer } : {},
|
|
307
|
+
...actualText !== void 0 ? { actualText } : {},
|
|
308
|
+
...alt !== void 0 ? { alt } : {}
|
|
309
|
+
});
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const layer = item.layerName ?? inScope("layerName");
|
|
313
|
+
items.push(layer === void 0 ? item : {
|
|
314
|
+
...item,
|
|
315
|
+
layerName: layer
|
|
316
|
+
});
|
|
317
|
+
};
|
|
276
318
|
const finalizeCurrentSubpath = () => {
|
|
277
319
|
if (currentSubpath !== void 0) {
|
|
278
320
|
pathSubpaths.push(currentSubpath);
|
|
@@ -346,7 +388,7 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
346
388
|
widthPt: gs.lineWidth
|
|
347
389
|
} : void 0
|
|
348
390
|
};
|
|
349
|
-
|
|
391
|
+
pushItem(classifyShape(pathSubpaths, paint) ?? {
|
|
350
392
|
kind: "path",
|
|
351
393
|
subpaths: pathSubpaths,
|
|
352
394
|
fillRule: paintFillRuleFor(operator),
|
|
@@ -394,7 +436,7 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
394
436
|
at += chunk.length;
|
|
395
437
|
}
|
|
396
438
|
const endMatrix = computeTrm(gs.ctm, ts);
|
|
397
|
-
|
|
439
|
+
pushItem({
|
|
398
440
|
kind: "text",
|
|
399
441
|
codes: combined,
|
|
400
442
|
fontResourceName: ts.fontResourceName,
|
|
@@ -429,12 +471,14 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
429
471
|
return;
|
|
430
472
|
}
|
|
431
473
|
const subtype = require_objects.asName(require_objects.dictGet(xobj.dict, "Subtype"));
|
|
474
|
+
const ownLayer = context.layerNameOf?.(require_objects.dictGet(xobj.dict, "OC"));
|
|
432
475
|
if (subtype === "Image") {
|
|
433
|
-
|
|
476
|
+
pushItem({
|
|
434
477
|
kind: "image",
|
|
435
478
|
resourceName: name,
|
|
436
479
|
resources,
|
|
437
|
-
matrix: gs.ctm
|
|
480
|
+
matrix: gs.ctm,
|
|
481
|
+
...ownLayer !== void 0 ? { layerName: ownLayer } : {}
|
|
438
482
|
});
|
|
439
483
|
return;
|
|
440
484
|
}
|
|
@@ -455,12 +499,13 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
455
499
|
...gs,
|
|
456
500
|
ctm: require_matrix.multiplyMatrices(formMatrix, gs.ctm)
|
|
457
501
|
};
|
|
458
|
-
|
|
502
|
+
const formLayer = ownLayer ?? inScope("layerName");
|
|
503
|
+
runContentStream(decoded.bytes, formResources, formState, context, items, depth + 1, [formLayer !== void 0 ? { layerName: formLayer } : {}]);
|
|
459
504
|
}
|
|
460
505
|
};
|
|
461
506
|
for (const token of operations) {
|
|
462
507
|
if (token.kind === "inlineImage") {
|
|
463
|
-
|
|
508
|
+
pushItem({
|
|
464
509
|
kind: "inlineImage",
|
|
465
510
|
dict: token.image.dict,
|
|
466
511
|
data: token.image.data,
|
|
@@ -714,7 +759,22 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
714
759
|
if (array !== void 0) showTextArray(array);
|
|
715
760
|
break;
|
|
716
761
|
}
|
|
717
|
-
case "Do":
|
|
762
|
+
case "Do":
|
|
763
|
+
handleDo(require_objects.asName(operands[0]));
|
|
764
|
+
break;
|
|
765
|
+
case "BDC": {
|
|
766
|
+
const props = markedContentProperties(operands[1], resources, context.resolver);
|
|
767
|
+
const layerName = context.layerNameOf?.(props === void 0 ? void 0 : require_objects.dictGet(props, "OC"));
|
|
768
|
+
markedContent.push({
|
|
769
|
+
...layerName !== void 0 ? { layerName } : {},
|
|
770
|
+
...markedContentStrings(props)
|
|
771
|
+
});
|
|
772
|
+
break;
|
|
773
|
+
}
|
|
774
|
+
case "BMC":
|
|
775
|
+
markedContent.push({});
|
|
776
|
+
break;
|
|
777
|
+
case "EMC": markedContent.pop();
|
|
718
778
|
}
|
|
719
779
|
}
|
|
720
780
|
}
|
package/dist/interpret.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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";
|
|
3
|
+
import { PdfDict, PdfObject } from "./objects.cjs";
|
|
4
4
|
import { Color } from "document-schema.js";
|
|
5
5
|
//#region src/interpret.d.ts
|
|
6
6
|
interface ExtractedTextRun {
|
|
@@ -12,6 +12,9 @@ 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;
|
|
15
18
|
}
|
|
16
19
|
interface ExtractedPaint {
|
|
17
20
|
readonly fill: Color | undefined;
|
|
@@ -19,6 +22,7 @@ interface ExtractedPaint {
|
|
|
19
22
|
readonly color: Color;
|
|
20
23
|
readonly widthPt: number;
|
|
21
24
|
} | undefined;
|
|
25
|
+
readonly layerName?: string;
|
|
22
26
|
}
|
|
23
27
|
interface ExtractedRect extends ExtractedPaint {
|
|
24
28
|
readonly kind: 'rect';
|
|
@@ -42,6 +46,7 @@ interface ExtractedLine {
|
|
|
42
46
|
readonly y2Pt: number;
|
|
43
47
|
readonly color: Color;
|
|
44
48
|
readonly widthPt: number;
|
|
49
|
+
readonly layerName?: string;
|
|
45
50
|
}
|
|
46
51
|
type ExtractedPathSegment = {
|
|
47
52
|
readonly kind: 'line';
|
|
@@ -72,12 +77,14 @@ interface ExtractedImage {
|
|
|
72
77
|
readonly resourceName: string;
|
|
73
78
|
readonly resources: PdfDict;
|
|
74
79
|
readonly matrix: Matrix;
|
|
80
|
+
readonly layerName?: string;
|
|
75
81
|
}
|
|
76
82
|
interface ExtractedInlineImage {
|
|
77
83
|
readonly kind: 'inlineImage';
|
|
78
84
|
readonly dict: PdfDict;
|
|
79
85
|
readonly data: Uint8Array<ArrayBuffer>;
|
|
80
86
|
readonly matrix: Matrix;
|
|
87
|
+
readonly layerName?: string;
|
|
81
88
|
}
|
|
82
89
|
type ExtractedItem = ExtractedTextRun | ExtractedRect | ExtractedEllipse | ExtractedLine | ExtractedPath | ExtractedImage | ExtractedInlineImage;
|
|
83
90
|
interface GlyphAdvance {
|
|
@@ -95,6 +102,7 @@ interface InterpretContext {
|
|
|
95
102
|
readonly fontMetrics: FontMetricsPort;
|
|
96
103
|
readonly resolver: PdfObjectResolver;
|
|
97
104
|
readonly sink: PdfDiagnosticSink;
|
|
105
|
+
readonly layerNameOf?: (obj: PdfObject | undefined) => string | undefined;
|
|
98
106
|
}
|
|
99
107
|
declare function interpretContentStream(bytes: Uint8Array<ArrayBuffer>, resources: PdfDict, context: InterpretContext): ExtractedItem[];
|
|
100
108
|
//#endregion
|
package/dist/interpret.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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";
|
|
3
|
+
import { PdfDict, PdfObject } from "./objects.js";
|
|
4
4
|
import { Color } from "document-schema.js";
|
|
5
5
|
//#region src/interpret.d.ts
|
|
6
6
|
interface ExtractedTextRun {
|
|
@@ -12,6 +12,9 @@ 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;
|
|
15
18
|
}
|
|
16
19
|
interface ExtractedPaint {
|
|
17
20
|
readonly fill: Color | undefined;
|
|
@@ -19,6 +22,7 @@ interface ExtractedPaint {
|
|
|
19
22
|
readonly color: Color;
|
|
20
23
|
readonly widthPt: number;
|
|
21
24
|
} | undefined;
|
|
25
|
+
readonly layerName?: string;
|
|
22
26
|
}
|
|
23
27
|
interface ExtractedRect extends ExtractedPaint {
|
|
24
28
|
readonly kind: 'rect';
|
|
@@ -42,6 +46,7 @@ interface ExtractedLine {
|
|
|
42
46
|
readonly y2Pt: number;
|
|
43
47
|
readonly color: Color;
|
|
44
48
|
readonly widthPt: number;
|
|
49
|
+
readonly layerName?: string;
|
|
45
50
|
}
|
|
46
51
|
type ExtractedPathSegment = {
|
|
47
52
|
readonly kind: 'line';
|
|
@@ -72,12 +77,14 @@ interface ExtractedImage {
|
|
|
72
77
|
readonly resourceName: string;
|
|
73
78
|
readonly resources: PdfDict;
|
|
74
79
|
readonly matrix: Matrix;
|
|
80
|
+
readonly layerName?: string;
|
|
75
81
|
}
|
|
76
82
|
interface ExtractedInlineImage {
|
|
77
83
|
readonly kind: 'inlineImage';
|
|
78
84
|
readonly dict: PdfDict;
|
|
79
85
|
readonly data: Uint8Array<ArrayBuffer>;
|
|
80
86
|
readonly matrix: Matrix;
|
|
87
|
+
readonly layerName?: string;
|
|
81
88
|
}
|
|
82
89
|
type ExtractedItem = ExtractedTextRun | ExtractedRect | ExtractedEllipse | ExtractedLine | ExtractedPath | ExtractedImage | ExtractedInlineImage;
|
|
83
90
|
interface GlyphAdvance {
|
|
@@ -95,6 +102,7 @@ interface InterpretContext {
|
|
|
95
102
|
readonly fontMetrics: FontMetricsPort;
|
|
96
103
|
readonly resolver: PdfObjectResolver;
|
|
97
104
|
readonly sink: PdfDiagnosticSink;
|
|
105
|
+
readonly layerNameOf?: (obj: PdfObject | undefined) => string | undefined;
|
|
98
106
|
}
|
|
99
107
|
declare function interpretContentStream(bytes: Uint8Array<ArrayBuffer>, resources: PdfDict, context: InterpretContext): ExtractedItem[];
|
|
100
108
|
//#endregion
|