@llamaindex/liteparse 2.8.1 → 2.9.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 +44 -0
- package/dist/cli-json.d.ts +154 -0
- package/dist/cli-json.d.ts.map +1 -0
- package/dist/cli-json.js +238 -0
- package/dist/cli-json.js.map +1 -0
- package/dist/cli.js +63 -28
- package/dist/cli.js.map +1 -1
- package/dist/lib.d.ts +191 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +98 -0
- package/dist/lib.js.map +1 -1
- package/dist/native.d.ts +147 -0
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js.map +1 -1
- package/liteparse.linux-x64-gnu.node +0 -0
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -58,14 +58,56 @@ const parser = new LiteParse({
|
|
|
58
58
|
dpi: 150, // Rendering DPI
|
|
59
59
|
outputFormat: 'json', // "json" | "text" | "markdown"
|
|
60
60
|
imageMode: 'placeholder', // Markdown image handling: "placeholder" | "off" | "embed"
|
|
61
|
+
extractImages: true, // Extract image bytes + metadata (default: false)
|
|
62
|
+
imageOutputDir: './images', // Write images and return name/path metadata (optional)
|
|
61
63
|
extractLinks: true, // Render [text](url) links in markdown output
|
|
64
|
+
extractVectorGraphics: false, // Opt-in shapes + merged H/V lines per page
|
|
65
|
+
extractAnnotations: false, // Include page annotations in structured output
|
|
66
|
+
extractFormFields: false, // Include AcroForm widget fields and values
|
|
67
|
+
extractStructureTree: false, // Include tagged-PDF logical structure
|
|
68
|
+
extractXfaPackets: false, // Include raw XFA packets (name + XML content)
|
|
69
|
+
extractContentBounds: false, // Include per-page contentBounds union bbox
|
|
70
|
+
detectScreenshotRects: false, // Detect solid rects/lines in screenshots
|
|
62
71
|
preserveVerySmallText: false, // Keep tiny text
|
|
72
|
+
extractTextMetadata: false, // Opt in to MCID, font metrics, colors, char codes, and trailingSpaceGenerated
|
|
63
73
|
password: undefined, // Password for protected documents
|
|
64
74
|
quiet: false, // Suppress progress output
|
|
65
75
|
numWorkers: 4, // Concurrent OCR workers
|
|
66
76
|
});
|
|
67
77
|
```
|
|
68
78
|
|
|
79
|
+
When `extractImages` is true, image extraction is enabled. `imageOutputDir` requires
|
|
80
|
+
that explicit opt-in and writes the extracted bytes to disk. Each
|
|
81
|
+
`result.images` entry includes its page bbox, intrinsic pixel dimensions, rotation,
|
|
82
|
+
format, `name`, and `path`. Valid source JPEGs are preserved, exact duplicates reuse
|
|
83
|
+
one file, and JSON CLI output contains metadata only (no base64 image data).
|
|
84
|
+
`imageMode` controls Markdown presentation only and does not imply extraction. With
|
|
85
|
+
`extractImages: false`, lightweight Markdown placement refs are still collected and
|
|
86
|
+
`result.images` stays empty.
|
|
87
|
+
|
|
88
|
+
The Node CLI uses the same snake_case JSON schema as the Rust CLI; camelCase is
|
|
89
|
+
reserved for the programmatic Node API.
|
|
90
|
+
|
|
91
|
+
When `extractAnnotations` is enabled, each parsed page has an `annotations`
|
|
92
|
+
array containing the subtype, contents, author/title, PDF date strings,
|
|
93
|
+
viewport-space rectangle and quadpoint rectangles, and URI for external link
|
|
94
|
+
annotations. It is independent of `extractLinks`, which controls Markdown link
|
|
95
|
+
rendering. The field is omitted when extraction is disabled.
|
|
96
|
+
|
|
97
|
+
When `extractStructureTree` is enabled, each page has a `structureTree` containing
|
|
98
|
+
all tagged-PDF roots and recursive elements with type, ID, actual/alternate text,
|
|
99
|
+
title, typed attributes, MCIDs, children, and referenced link annotations. Untagged
|
|
100
|
+
pages have an empty `roots` array; the field is omitted when disabled.
|
|
101
|
+
|
|
102
|
+
Every result also carries the document's `/Info` `creator`/`producer` when
|
|
103
|
+
present (API-level only, not in CLI JSON), and with `extractContentBounds`
|
|
104
|
+
each page carries a `contentBounds` union bbox of its top-level content
|
|
105
|
+
objects. With `extractXfaPackets`, `result.xfaPackets` lists each raw XFA
|
|
106
|
+
packet (index, name, content length, XML content); non-XFA documents yield an
|
|
107
|
+
empty array. Screenshots draw form-field appearances into the raster and
|
|
108
|
+
report `isSolidFill` per page, plus detected solid `rects` when
|
|
109
|
+
`detectScreenshotRects` is enabled.
|
|
110
|
+
|
|
69
111
|
## Parsing from Bytes
|
|
70
112
|
|
|
71
113
|
Pass a `Buffer` or `Uint8Array` directly — useful for HTTP responses or in-memory data:
|
|
@@ -133,6 +175,8 @@ The npm package includes the `lit` CLI:
|
|
|
133
175
|
```bash
|
|
134
176
|
lit parse document.pdf
|
|
135
177
|
lit parse document.pdf --format json -o output.json
|
|
178
|
+
lit parse document.pdf --format json --extract-annotations
|
|
179
|
+
lit parse document.pdf --format json --extract-form-fields
|
|
136
180
|
lit screenshot document.pdf -o ./screenshots
|
|
137
181
|
lit batch-parse ./input ./output
|
|
138
182
|
lit is-complex document.pdf
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { ParseResult } from "./lib.js";
|
|
2
|
+
/** Project the camelCase Node API result into the Rust CLI JSON schema. */
|
|
3
|
+
export declare function parseResultToCliJson(result: ParseResult, options?: {
|
|
4
|
+
extractTextMetadata?: boolean;
|
|
5
|
+
}): {
|
|
6
|
+
xfa_packets?: {
|
|
7
|
+
content?: string | undefined;
|
|
8
|
+
content_length: number;
|
|
9
|
+
name?: string | undefined;
|
|
10
|
+
index: number;
|
|
11
|
+
}[] | undefined;
|
|
12
|
+
form_type?: number | undefined;
|
|
13
|
+
image_error_count?: number | undefined;
|
|
14
|
+
images?: {
|
|
15
|
+
duplicate_of?: string | undefined;
|
|
16
|
+
page: number;
|
|
17
|
+
bbox: {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
};
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
rotation: number;
|
|
26
|
+
format: string;
|
|
27
|
+
path?: string | undefined;
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
}[] | undefined;
|
|
31
|
+
pages: {
|
|
32
|
+
structure_tree?: {
|
|
33
|
+
roots: object[];
|
|
34
|
+
} | undefined;
|
|
35
|
+
form_fields?: {
|
|
36
|
+
selected_options?: string[] | undefined;
|
|
37
|
+
options?: string[] | undefined;
|
|
38
|
+
rect?: import("./lib.js").AnnotationRect | undefined;
|
|
39
|
+
checked?: boolean | undefined;
|
|
40
|
+
control_index?: number | undefined;
|
|
41
|
+
control_count?: number | undefined;
|
|
42
|
+
field_flags: number;
|
|
43
|
+
export_value?: string | undefined;
|
|
44
|
+
value?: string | undefined;
|
|
45
|
+
alternate_name?: string | undefined;
|
|
46
|
+
name?: string | undefined;
|
|
47
|
+
object_number?: number | undefined;
|
|
48
|
+
id: string;
|
|
49
|
+
type: string;
|
|
50
|
+
page: number;
|
|
51
|
+
annotation_index: number;
|
|
52
|
+
widget_index: number;
|
|
53
|
+
}[] | undefined;
|
|
54
|
+
annotations?: {
|
|
55
|
+
uri?: string | undefined;
|
|
56
|
+
quadpoint_rects?: {
|
|
57
|
+
x: number;
|
|
58
|
+
y: number;
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
}[] | undefined;
|
|
62
|
+
rect?: import("./lib.js").AnnotationRect | undefined;
|
|
63
|
+
title?: string | undefined;
|
|
64
|
+
modified?: string | undefined;
|
|
65
|
+
created?: string | undefined;
|
|
66
|
+
contents?: string | undefined;
|
|
67
|
+
subtype: string;
|
|
68
|
+
}[] | undefined;
|
|
69
|
+
vector_graphics?: {
|
|
70
|
+
shapes: {
|
|
71
|
+
has_curve: boolean;
|
|
72
|
+
fill_color?: string | undefined;
|
|
73
|
+
fill: boolean;
|
|
74
|
+
stroke_color?: string | undefined;
|
|
75
|
+
bbox: {
|
|
76
|
+
x: number;
|
|
77
|
+
y: number;
|
|
78
|
+
width: number;
|
|
79
|
+
height: number;
|
|
80
|
+
};
|
|
81
|
+
stroke: boolean;
|
|
82
|
+
}[];
|
|
83
|
+
lines: {
|
|
84
|
+
fill_color?: string | undefined;
|
|
85
|
+
fill: boolean;
|
|
86
|
+
stroke_color?: string | undefined;
|
|
87
|
+
stroke_width?: number | undefined;
|
|
88
|
+
x1: number;
|
|
89
|
+
y1: number;
|
|
90
|
+
x2: number;
|
|
91
|
+
y2: number;
|
|
92
|
+
stroke: boolean;
|
|
93
|
+
}[];
|
|
94
|
+
} | undefined;
|
|
95
|
+
complexity?: {
|
|
96
|
+
layout?: {
|
|
97
|
+
column_count: number;
|
|
98
|
+
ruled_table_count: number;
|
|
99
|
+
ruled_table_coverage: number;
|
|
100
|
+
text_table_run_count: number;
|
|
101
|
+
figure_count: number;
|
|
102
|
+
figure_coverage: number;
|
|
103
|
+
is_complex: boolean;
|
|
104
|
+
reasons: string[];
|
|
105
|
+
} | undefined;
|
|
106
|
+
is_garbled: boolean;
|
|
107
|
+
page_area: number;
|
|
108
|
+
needs_ocr: boolean;
|
|
109
|
+
reasons: string[];
|
|
110
|
+
uncovered_vector_area?: number | undefined;
|
|
111
|
+
page_number: number;
|
|
112
|
+
text_length: number;
|
|
113
|
+
text_coverage: number;
|
|
114
|
+
has_substantial_images: boolean;
|
|
115
|
+
image_block_count: number;
|
|
116
|
+
image_coverage: number;
|
|
117
|
+
largest_image_coverage: number;
|
|
118
|
+
full_page_image: boolean;
|
|
119
|
+
} | undefined;
|
|
120
|
+
text: string;
|
|
121
|
+
text_items: {
|
|
122
|
+
confidence?: number | undefined;
|
|
123
|
+
trailing_space_generated?: boolean | undefined;
|
|
124
|
+
char_codes?: number[] | undefined;
|
|
125
|
+
stroke_color?: string | undefined;
|
|
126
|
+
fill_color?: string | undefined;
|
|
127
|
+
mcid?: number | undefined;
|
|
128
|
+
font_is_buggy?: boolean | undefined;
|
|
129
|
+
text_width?: number | undefined;
|
|
130
|
+
font_weight?: number | undefined;
|
|
131
|
+
font_descent?: number | undefined;
|
|
132
|
+
font_ascent?: number | undefined;
|
|
133
|
+
font_height?: number | undefined;
|
|
134
|
+
font_size?: number | undefined;
|
|
135
|
+
font_name?: string | undefined;
|
|
136
|
+
rotation?: number | undefined;
|
|
137
|
+
text: string;
|
|
138
|
+
x: number;
|
|
139
|
+
y: number;
|
|
140
|
+
width: number;
|
|
141
|
+
height: number;
|
|
142
|
+
}[];
|
|
143
|
+
content_bounds?: {
|
|
144
|
+
x: number;
|
|
145
|
+
y: number;
|
|
146
|
+
width: number;
|
|
147
|
+
height: number;
|
|
148
|
+
} | undefined;
|
|
149
|
+
page: number;
|
|
150
|
+
width: number;
|
|
151
|
+
height: number;
|
|
152
|
+
}[];
|
|
153
|
+
};
|
|
154
|
+
//# sourceMappingURL=cli-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-json.d.ts","sourceRoot":"","sources":["../src/cli-json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKV,WAAW,EAKZ,MAAM,UAAU,CAAC;AAmMlB,2EAA2E;AAC3E,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,WAAW,EACnB,OAAO,GAAE;IAAE,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqDhD"}
|
package/dist/cli-json.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
function textItemToCliJson(item, extractTextMetadata) {
|
|
2
|
+
return {
|
|
3
|
+
text: item.text,
|
|
4
|
+
x: item.x,
|
|
5
|
+
y: item.y,
|
|
6
|
+
width: item.width,
|
|
7
|
+
height: item.height,
|
|
8
|
+
...(extractTextMetadata && item.rotation !== undefined
|
|
9
|
+
? { rotation: item.rotation }
|
|
10
|
+
: {}),
|
|
11
|
+
...(item.fontName !== undefined ? { font_name: item.fontName } : {}),
|
|
12
|
+
...(item.fontSize !== undefined ? { font_size: item.fontSize } : {}),
|
|
13
|
+
...(item.fontHeight !== undefined ? { font_height: item.fontHeight } : {}),
|
|
14
|
+
...(item.fontAscent !== undefined ? { font_ascent: item.fontAscent } : {}),
|
|
15
|
+
...(item.fontDescent !== undefined ? { font_descent: item.fontDescent } : {}),
|
|
16
|
+
...(item.fontWeight !== undefined ? { font_weight: item.fontWeight } : {}),
|
|
17
|
+
...(item.textWidth !== undefined ? { text_width: item.textWidth } : {}),
|
|
18
|
+
...(item.fontIsBuggy !== undefined ? { font_is_buggy: item.fontIsBuggy } : {}),
|
|
19
|
+
...(item.mcid !== undefined ? { mcid: item.mcid } : {}),
|
|
20
|
+
...(item.fillColor !== undefined ? { fill_color: item.fillColor } : {}),
|
|
21
|
+
...(item.strokeColor !== undefined ? { stroke_color: item.strokeColor } : {}),
|
|
22
|
+
...(item.charCodes?.length ? { char_codes: item.charCodes } : {}),
|
|
23
|
+
...(item.trailingSpaceGenerated
|
|
24
|
+
? { trailing_space_generated: true }
|
|
25
|
+
: {}),
|
|
26
|
+
...(item.confidence !== undefined ? { confidence: item.confidence } : {}),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function structureTreeElementToCliJson(element) {
|
|
30
|
+
return {
|
|
31
|
+
type: element.type,
|
|
32
|
+
...(element.id !== undefined ? { id: element.id } : {}),
|
|
33
|
+
...(element.actualText !== undefined ? { actual_text: element.actualText } : {}),
|
|
34
|
+
...(element.altText !== undefined ? { alt_text: element.altText } : {}),
|
|
35
|
+
...(element.title !== undefined ? { title: element.title } : {}),
|
|
36
|
+
...(Object.keys(element.attributes).length ? { attributes: element.attributes } : {}),
|
|
37
|
+
marked_content_ids: element.markedContentIds,
|
|
38
|
+
children: element.children.map(structureTreeElementToCliJson),
|
|
39
|
+
annotations: element.annotations.map(annotationToCliJson),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function complexityToCliJson(complexity) {
|
|
43
|
+
return {
|
|
44
|
+
page_number: complexity.pageNumber,
|
|
45
|
+
text_length: complexity.textLength,
|
|
46
|
+
text_coverage: complexity.textCoverage,
|
|
47
|
+
has_substantial_images: complexity.hasSubstantialImages,
|
|
48
|
+
image_block_count: complexity.imageBlockCount,
|
|
49
|
+
image_coverage: complexity.imageCoverage,
|
|
50
|
+
largest_image_coverage: complexity.largestImageCoverage,
|
|
51
|
+
full_page_image: complexity.fullPageImage,
|
|
52
|
+
...(complexity.uncoveredVectorArea !== undefined
|
|
53
|
+
? { uncovered_vector_area: complexity.uncoveredVectorArea }
|
|
54
|
+
: {}),
|
|
55
|
+
is_garbled: complexity.isGarbled,
|
|
56
|
+
page_area: complexity.pageArea,
|
|
57
|
+
needs_ocr: complexity.needsOcr,
|
|
58
|
+
reasons: complexity.reasons,
|
|
59
|
+
...(complexity.layout
|
|
60
|
+
? {
|
|
61
|
+
layout: {
|
|
62
|
+
column_count: complexity.layout.columnCount,
|
|
63
|
+
ruled_table_count: complexity.layout.ruledTableCount,
|
|
64
|
+
ruled_table_coverage: complexity.layout.ruledTableCoverage,
|
|
65
|
+
text_table_run_count: complexity.layout.textTableRunCount,
|
|
66
|
+
figure_count: complexity.layout.figureCount,
|
|
67
|
+
figure_coverage: complexity.layout.figureCoverage,
|
|
68
|
+
is_complex: complexity.layout.isComplex,
|
|
69
|
+
reasons: complexity.layout.reasons,
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
: {}),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function vectorGraphicsToCliJson(vectorGraphics) {
|
|
76
|
+
return {
|
|
77
|
+
shapes: vectorGraphics.shapes.map((shape) => ({
|
|
78
|
+
bbox: {
|
|
79
|
+
x: shape.bbox.x,
|
|
80
|
+
y: shape.bbox.y,
|
|
81
|
+
width: shape.bbox.width,
|
|
82
|
+
height: shape.bbox.height,
|
|
83
|
+
},
|
|
84
|
+
stroke: shape.stroke,
|
|
85
|
+
...(shape.strokeColor !== undefined
|
|
86
|
+
? { stroke_color: shape.strokeColor }
|
|
87
|
+
: {}),
|
|
88
|
+
fill: shape.fill,
|
|
89
|
+
...(shape.fillColor !== undefined
|
|
90
|
+
? { fill_color: shape.fillColor }
|
|
91
|
+
: {}),
|
|
92
|
+
has_curve: shape.hasCurve,
|
|
93
|
+
})),
|
|
94
|
+
lines: vectorGraphics.lines.map((line) => ({
|
|
95
|
+
x1: line.x1,
|
|
96
|
+
y1: line.y1,
|
|
97
|
+
x2: line.x2,
|
|
98
|
+
y2: line.y2,
|
|
99
|
+
stroke: line.stroke,
|
|
100
|
+
...(line.strokeWidth !== undefined
|
|
101
|
+
? { stroke_width: line.strokeWidth }
|
|
102
|
+
: {}),
|
|
103
|
+
...(line.strokeColor !== undefined
|
|
104
|
+
? { stroke_color: line.strokeColor }
|
|
105
|
+
: {}),
|
|
106
|
+
fill: line.fill,
|
|
107
|
+
...(line.fillColor !== undefined ? { fill_color: line.fillColor } : {}),
|
|
108
|
+
})),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function annotationToCliJson(annotation) {
|
|
112
|
+
return {
|
|
113
|
+
subtype: annotation.subtype,
|
|
114
|
+
...(annotation.contents !== undefined
|
|
115
|
+
? { contents: annotation.contents }
|
|
116
|
+
: {}),
|
|
117
|
+
...(annotation.created !== undefined ? { created: annotation.created } : {}),
|
|
118
|
+
...(annotation.modified !== undefined
|
|
119
|
+
? { modified: annotation.modified }
|
|
120
|
+
: {}),
|
|
121
|
+
...(annotation.title !== undefined ? { title: annotation.title } : {}),
|
|
122
|
+
...(annotation.rect !== undefined ? { rect: annotation.rect } : {}),
|
|
123
|
+
...(annotation.quadpointRects.length
|
|
124
|
+
? {
|
|
125
|
+
quadpoint_rects: annotation.quadpointRects.map((rect) => ({
|
|
126
|
+
x: rect.x,
|
|
127
|
+
y: rect.y,
|
|
128
|
+
width: rect.width,
|
|
129
|
+
height: rect.height,
|
|
130
|
+
})),
|
|
131
|
+
}
|
|
132
|
+
: {}),
|
|
133
|
+
...(annotation.uri !== undefined ? { uri: annotation.uri } : {}),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function formFieldToCliJson(field) {
|
|
137
|
+
return {
|
|
138
|
+
id: field.id,
|
|
139
|
+
type: field.type,
|
|
140
|
+
page: field.page,
|
|
141
|
+
annotation_index: field.annotationIndex,
|
|
142
|
+
widget_index: field.widgetIndex,
|
|
143
|
+
...(field.objectNumber !== undefined ? { object_number: field.objectNumber } : {}),
|
|
144
|
+
...(field.name !== undefined ? { name: field.name } : {}),
|
|
145
|
+
...(field.alternateName !== undefined ? { alternate_name: field.alternateName } : {}),
|
|
146
|
+
...(field.value !== undefined ? { value: field.value } : {}),
|
|
147
|
+
...(field.exportValue !== undefined ? { export_value: field.exportValue } : {}),
|
|
148
|
+
field_flags: field.fieldFlags,
|
|
149
|
+
...(field.controlCount !== undefined ? { control_count: field.controlCount } : {}),
|
|
150
|
+
...(field.controlIndex !== undefined ? { control_index: field.controlIndex } : {}),
|
|
151
|
+
...(field.checked !== undefined ? { checked: field.checked } : {}),
|
|
152
|
+
...(field.rect !== undefined ? { rect: field.rect } : {}),
|
|
153
|
+
...(field.options.length ? { options: field.options } : {}),
|
|
154
|
+
...(field.selectedOptions.length ? { selected_options: field.selectedOptions } : {}),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function xfaPacketToCliJson(packet) {
|
|
158
|
+
return {
|
|
159
|
+
index: packet.index,
|
|
160
|
+
...(packet.name !== undefined ? { name: packet.name } : {}),
|
|
161
|
+
content_length: packet.contentLength,
|
|
162
|
+
...(packet.content !== undefined ? { content: packet.content } : {}),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function imageToCliJson(image) {
|
|
166
|
+
return {
|
|
167
|
+
id: image.id,
|
|
168
|
+
name: image.name,
|
|
169
|
+
...(image.path !== undefined ? { path: image.path } : {}),
|
|
170
|
+
page: image.page,
|
|
171
|
+
bbox: {
|
|
172
|
+
x: image.bbox.x,
|
|
173
|
+
y: image.bbox.y,
|
|
174
|
+
width: image.bbox.width,
|
|
175
|
+
height: image.bbox.height,
|
|
176
|
+
},
|
|
177
|
+
width: image.width,
|
|
178
|
+
height: image.height,
|
|
179
|
+
rotation: image.rotation,
|
|
180
|
+
format: image.format,
|
|
181
|
+
...(image.duplicateOf !== undefined
|
|
182
|
+
? { duplicate_of: image.duplicateOf }
|
|
183
|
+
: {}),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/** Project the camelCase Node API result into the Rust CLI JSON schema. */
|
|
187
|
+
export function parseResultToCliJson(result, options = {}) {
|
|
188
|
+
const extractTextMetadata = options.extractTextMetadata ?? false;
|
|
189
|
+
return {
|
|
190
|
+
pages: result.pages.map((page) => ({
|
|
191
|
+
page: page.pageNum,
|
|
192
|
+
width: page.width,
|
|
193
|
+
height: page.height,
|
|
194
|
+
...(page.contentBounds
|
|
195
|
+
? {
|
|
196
|
+
content_bounds: {
|
|
197
|
+
x: page.contentBounds.x,
|
|
198
|
+
y: page.contentBounds.y,
|
|
199
|
+
width: page.contentBounds.width,
|
|
200
|
+
height: page.contentBounds.height,
|
|
201
|
+
},
|
|
202
|
+
}
|
|
203
|
+
: {}),
|
|
204
|
+
text: page.text,
|
|
205
|
+
text_items: page.textItems.map((item) => textItemToCliJson(item, extractTextMetadata)),
|
|
206
|
+
...(page.complexity
|
|
207
|
+
? { complexity: complexityToCliJson(page.complexity) }
|
|
208
|
+
: {}),
|
|
209
|
+
...(page.vectorGraphics
|
|
210
|
+
? { vector_graphics: vectorGraphicsToCliJson(page.vectorGraphics) }
|
|
211
|
+
: {}),
|
|
212
|
+
...(page.annotations !== undefined
|
|
213
|
+
? { annotations: page.annotations.map(annotationToCliJson) }
|
|
214
|
+
: {}),
|
|
215
|
+
...(page.formFields !== undefined
|
|
216
|
+
? { form_fields: page.formFields.map(formFieldToCliJson) }
|
|
217
|
+
: {}),
|
|
218
|
+
...(page.structureTree !== undefined
|
|
219
|
+
? {
|
|
220
|
+
structure_tree: {
|
|
221
|
+
roots: page.structureTree.roots.map(structureTreeElementToCliJson),
|
|
222
|
+
},
|
|
223
|
+
}
|
|
224
|
+
: {}),
|
|
225
|
+
})),
|
|
226
|
+
...(result.images.length
|
|
227
|
+
? { images: result.images.map(imageToCliJson) }
|
|
228
|
+
: {}),
|
|
229
|
+
...(result.imageErrorCount
|
|
230
|
+
? { image_error_count: result.imageErrorCount }
|
|
231
|
+
: {}),
|
|
232
|
+
...(result.formType !== undefined ? { form_type: result.formType } : {}),
|
|
233
|
+
...(result.xfaPackets !== undefined
|
|
234
|
+
? { xfa_packets: result.xfaPackets.map(xfaPacketToCliJson) }
|
|
235
|
+
: {}),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=cli-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-json.js","sourceRoot":"","sources":["../src/cli-json.ts"],"names":[],"mappings":"AAYA,SAAS,iBAAiB,CAAC,IAAc,EAAE,mBAA4B;IACrE,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,CAAC,EAAE,IAAI,CAAC,CAAC;QACT,CAAC,EAAE,IAAI,CAAC,CAAC;QACT,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,GAAG,CAAC,mBAAmB,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS;YACpD,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE;YAC7B,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,GAAG,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS,C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AAU,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE;gBAC1D,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS;gBAClC,CAAC,CAAC;oBACE,cAAc,EAAE;wBACd,KAAK,EAAE,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,6BAA6B,CAAC;qBACnE;iBACF;gBACH,CAAC,CAAC,EAAE,CAAC;SACR,CAAC,CAAC;QACH,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM;YACtB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE;YAC/C,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,MAAM,CAAC,eAAe;YACxB,CAAC,CAAC,EAAE,iBAAiB,EAAE,MAAM,CAAC,eAAe,EAAE;YAC/C,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxE,GAAG,CAAC,MAAM,CAAC,UAAU,KAAK,SAAS;YACjC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE;YAC5D,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { program } from "commander";
|
|
3
3
|
import { LiteParse } from "./lib.js";
|
|
4
|
+
import { parseResultToCliJson } from "./cli-json.js";
|
|
4
5
|
import { readFileSync, writeFileSync, mkdirSync, readdirSync } from "node:fs";
|
|
5
6
|
import { join, relative, parse as parsePath } from "node:path";
|
|
6
7
|
program
|
|
@@ -47,7 +48,13 @@ program
|
|
|
47
48
|
.option("--format <format>", 'Output format: json|text|markdown (default: "text")')
|
|
48
49
|
.option("--image-mode <mode>", "How to surface raster images in markdown: off|placeholder|embed (default: placeholder)")
|
|
49
50
|
.option("--image-output-dir <dir>", "Directory to write embedded images to when --image-mode embed is set")
|
|
51
|
+
.option("--extract-images", "Extract embedded image bytes and metadata")
|
|
50
52
|
.option("--no-links", "Disable hyperlink extraction (emit plain anchor text)")
|
|
53
|
+
.option("--extract-annotations", "Include all PDF annotations in page output")
|
|
54
|
+
.option("--extract-form-fields", "Include AcroForm widget fields and values")
|
|
55
|
+
.option("--extract-structure-tree", "Include the tagged-PDF logical structure tree")
|
|
56
|
+
.option("--extract-xfa-packets", "Include raw XFA packets (name + XML content) in JSON output")
|
|
57
|
+
.option("--extract-content-bounds", "Include each page's content_bounds in JSON output")
|
|
51
58
|
.option("--ocr-server-url <url>", "HTTP OCR server URL")
|
|
52
59
|
.option("--ocr-server-header <header>", 'Extra header for OCR server requests, "Name: Value" (repeatable)', collectHeader)
|
|
53
60
|
.option("--no-ocr", "Disable OCR")
|
|
@@ -56,11 +63,13 @@ program
|
|
|
56
63
|
.option("--target-pages <pages>", 'Pages to parse (e.g., "1-5,10,15-20")')
|
|
57
64
|
.option("--dpi <dpi>", "Rendering DPI", parseFloat)
|
|
58
65
|
.option("--preserve-small-text", "Keep very small text")
|
|
66
|
+
.option("--extract-text-metadata", "Include rich PDF text metadata in text items and JSON output")
|
|
59
67
|
.option("--password <password>", "Password for encrypted documents")
|
|
60
68
|
.option("--config <file>", "JSON config file path")
|
|
61
69
|
.option("-q, --quiet", "Suppress progress output")
|
|
62
70
|
.option("--num-workers <n>", "Number of concurrent OCR workers", parseInt)
|
|
63
71
|
.option("--complexity", "Include per-page complexity signals in JSON output")
|
|
72
|
+
.option("--extract-vector-graphics", "Include page-scoped vector shapes and merged horizontal/vertical lines")
|
|
64
73
|
.action(async (file, opts) => {
|
|
65
74
|
try {
|
|
66
75
|
const config = {};
|
|
@@ -74,8 +83,22 @@ program
|
|
|
74
83
|
config.outputFormat = opts.format;
|
|
75
84
|
if (opts.imageMode)
|
|
76
85
|
config.imageMode = opts.imageMode;
|
|
86
|
+
if (opts.imageOutputDir)
|
|
87
|
+
config.imageOutputDir = opts.imageOutputDir;
|
|
88
|
+
if (opts.extractImages)
|
|
89
|
+
config.extractImages = true;
|
|
77
90
|
if (opts.links === false)
|
|
78
91
|
config.extractLinks = false;
|
|
92
|
+
if (opts.extractAnnotations)
|
|
93
|
+
config.extractAnnotations = true;
|
|
94
|
+
if (opts.extractFormFields)
|
|
95
|
+
config.extractFormFields = true;
|
|
96
|
+
if (opts.extractStructureTree)
|
|
97
|
+
config.extractStructureTree = true;
|
|
98
|
+
if (opts.extractXfaPackets)
|
|
99
|
+
config.extractXfaPackets = true;
|
|
100
|
+
if (opts.extractContentBounds)
|
|
101
|
+
config.extractContentBounds = true;
|
|
79
102
|
if (opts.ocrServerUrl)
|
|
80
103
|
config.ocrServerUrl = opts.ocrServerUrl;
|
|
81
104
|
if (opts.ocrServerHeader)
|
|
@@ -92,6 +115,8 @@ program
|
|
|
92
115
|
config.dpi = opts.dpi;
|
|
93
116
|
if (opts.preserveSmallText)
|
|
94
117
|
config.preserveVerySmallText = true;
|
|
118
|
+
if (opts.extractTextMetadata)
|
|
119
|
+
config.extractTextMetadata = true;
|
|
95
120
|
if (opts.password)
|
|
96
121
|
config.password = opts.password;
|
|
97
122
|
if (opts.quiet)
|
|
@@ -100,32 +125,18 @@ program
|
|
|
100
125
|
config.numWorkers = opts.numWorkers;
|
|
101
126
|
if (opts.complexity)
|
|
102
127
|
config.includeComplexity = true;
|
|
128
|
+
if (opts.extractVectorGraphics)
|
|
129
|
+
config.extractVectorGraphics = true;
|
|
103
130
|
// Default CLI output to text (library defaults to json)
|
|
104
131
|
if (!config.outputFormat)
|
|
105
132
|
config.outputFormat = "text";
|
|
106
133
|
const parser = new LiteParse(config);
|
|
107
134
|
const result = await parser.parse(await resolveInput(file));
|
|
108
135
|
const output = config.outputFormat === "json"
|
|
109
|
-
? JSON.stringify({
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
width: p.width,
|
|
113
|
-
height: p.height,
|
|
114
|
-
text: p.text,
|
|
115
|
-
textItems: p.textItems,
|
|
116
|
-
})),
|
|
117
|
-
}, null, 2)
|
|
136
|
+
? JSON.stringify(parseResultToCliJson(result, {
|
|
137
|
+
extractTextMetadata: config.extractTextMetadata,
|
|
138
|
+
}), null, 2)
|
|
118
139
|
: result.text;
|
|
119
|
-
if (opts.imageOutputDir && result.images.length > 0) {
|
|
120
|
-
const dir = opts.imageOutputDir;
|
|
121
|
-
mkdirSync(dir, { recursive: true });
|
|
122
|
-
for (const img of result.images) {
|
|
123
|
-
writeFileSync(join(dir, `image_${img.id}.${img.format}`), img.bytes);
|
|
124
|
-
}
|
|
125
|
-
if (!opts.quiet) {
|
|
126
|
-
console.error(`[liteparse] wrote ${result.images.length} image(s) to ${dir}`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
140
|
if (opts.output) {
|
|
130
141
|
writeFileSync(opts.output, output, "utf-8");
|
|
131
142
|
}
|
|
@@ -258,6 +269,14 @@ program
|
|
|
258
269
|
.option("--password <password>", "Password for encrypted documents")
|
|
259
270
|
.option("-q, --quiet", "Suppress progress output")
|
|
260
271
|
.option("--num-workers <n>", "Number of concurrent OCR workers", parseInt)
|
|
272
|
+
.option("--extract-text-metadata", "Include rich PDF text metadata in text items and JSON output")
|
|
273
|
+
.option("--extract-images", "Extract embedded image bytes and metadata")
|
|
274
|
+
.option("--extract-annotations", "Include all PDF annotations in page output")
|
|
275
|
+
.option("--extract-form-fields", "Include AcroForm widget fields and values")
|
|
276
|
+
.option("--extract-structure-tree", "Include the tagged-PDF logical structure tree")
|
|
277
|
+
.option("--extract-xfa-packets", "Include raw XFA packets (name + XML content) in JSON output")
|
|
278
|
+
.option("--extract-content-bounds", "Include each page's content_bounds in JSON output")
|
|
279
|
+
.option("--extract-vector-graphics", "Include page-scoped vector shapes and merged horizontal/vertical lines")
|
|
261
280
|
.action(async (inputDir, outputDir, opts) => {
|
|
262
281
|
try {
|
|
263
282
|
const config = {};
|
|
@@ -281,6 +300,28 @@ program
|
|
|
281
300
|
config.quiet = true;
|
|
282
301
|
if (opts.numWorkers)
|
|
283
302
|
config.numWorkers = opts.numWorkers;
|
|
303
|
+
if (opts.extractTextMetadata)
|
|
304
|
+
config.extractTextMetadata = true;
|
|
305
|
+
if (opts.extractImages)
|
|
306
|
+
config.extractImages = true;
|
|
307
|
+
if (opts.extractAnnotations)
|
|
308
|
+
config.extractAnnotations = true;
|
|
309
|
+
if (opts.extractFormFields)
|
|
310
|
+
config.extractFormFields = true;
|
|
311
|
+
if (opts.extractStructureTree)
|
|
312
|
+
config.extractStructureTree = true;
|
|
313
|
+
if (opts.extractXfaPackets)
|
|
314
|
+
config.extractXfaPackets = true;
|
|
315
|
+
if (opts.extractContentBounds)
|
|
316
|
+
config.extractContentBounds = true;
|
|
317
|
+
if (opts.extractContentBounds)
|
|
318
|
+
config.extractContentBounds = true;
|
|
319
|
+
if (opts.extractXfaPackets)
|
|
320
|
+
config.extractXfaPackets = true;
|
|
321
|
+
if (opts.extractContentBounds)
|
|
322
|
+
config.extractContentBounds = true;
|
|
323
|
+
if (opts.extractVectorGraphics)
|
|
324
|
+
config.extractVectorGraphics = true;
|
|
284
325
|
const parser = new LiteParse(config);
|
|
285
326
|
const outExt = format === "json" ? ".json" : format === "markdown" ? ".md" : ".txt";
|
|
286
327
|
mkdirSync(outputDir, { recursive: true });
|
|
@@ -308,15 +349,9 @@ program
|
|
|
308
349
|
try {
|
|
309
350
|
const result = await parser.parse(filePath);
|
|
310
351
|
const output = format === "json"
|
|
311
|
-
? JSON.stringify({
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
width: p.width,
|
|
315
|
-
height: p.height,
|
|
316
|
-
text: p.text,
|
|
317
|
-
textItems: p.textItems,
|
|
318
|
-
})),
|
|
319
|
-
}, null, 2)
|
|
352
|
+
? JSON.stringify(parseResultToCliJson(result, {
|
|
353
|
+
extractTextMetadata: config.extractTextMetadata,
|
|
354
|
+
}), null, 2)
|
|
320
355
|
: result.text;
|
|
321
356
|
writeFileSync(outPath, output, "utf-8");
|
|
322
357
|
success++;
|