@llamaindex/liteparse 2.8.1 → 2.10.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 +45 -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 +66 -28
- package/dist/cli.js.map +1 -1
- package/dist/lib.d.ts +193 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +100 -0
- package/dist/lib.js.map +1 -1
- package/dist/native.d.ts +148 -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,57 @@ 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
|
+
keepHeadersFooters: false, // Keep running headers/footers in markdown output
|
|
65
|
+
extractVectorGraphics: false, // Opt-in shapes + merged H/V lines per page
|
|
66
|
+
extractAnnotations: false, // Include page annotations in structured output
|
|
67
|
+
extractFormFields: false, // Include AcroForm widget fields and values
|
|
68
|
+
extractStructureTree: false, // Include tagged-PDF logical structure
|
|
69
|
+
extractXfaPackets: false, // Include raw XFA packets (name + XML content)
|
|
70
|
+
extractContentBounds: false, // Include per-page contentBounds union bbox
|
|
71
|
+
detectScreenshotRects: false, // Detect solid rects/lines in screenshots
|
|
62
72
|
preserveVerySmallText: false, // Keep tiny text
|
|
73
|
+
extractTextMetadata: false, // Opt in to MCID, font metrics, colors, char codes, and trailingSpaceGenerated
|
|
63
74
|
password: undefined, // Password for protected documents
|
|
64
75
|
quiet: false, // Suppress progress output
|
|
65
76
|
numWorkers: 4, // Concurrent OCR workers
|
|
66
77
|
});
|
|
67
78
|
```
|
|
68
79
|
|
|
80
|
+
When `extractImages` is true, image extraction is enabled. `imageOutputDir` requires
|
|
81
|
+
that explicit opt-in and writes the extracted bytes to disk. Each
|
|
82
|
+
`result.images` entry includes its page bbox, intrinsic pixel dimensions, rotation,
|
|
83
|
+
format, `name`, and `path`. Valid source JPEGs are preserved, exact duplicates reuse
|
|
84
|
+
one file, and JSON CLI output contains metadata only (no base64 image data).
|
|
85
|
+
`imageMode` controls Markdown presentation only and does not imply extraction. With
|
|
86
|
+
`extractImages: false`, lightweight Markdown placement refs are still collected and
|
|
87
|
+
`result.images` stays empty.
|
|
88
|
+
|
|
89
|
+
The Node CLI uses the same snake_case JSON schema as the Rust CLI; camelCase is
|
|
90
|
+
reserved for the programmatic Node API.
|
|
91
|
+
|
|
92
|
+
When `extractAnnotations` is enabled, each parsed page has an `annotations`
|
|
93
|
+
array containing the subtype, contents, author/title, PDF date strings,
|
|
94
|
+
viewport-space rectangle and quadpoint rectangles, and URI for external link
|
|
95
|
+
annotations. It is independent of `extractLinks`, which controls Markdown link
|
|
96
|
+
rendering. The field is omitted when extraction is disabled.
|
|
97
|
+
|
|
98
|
+
When `extractStructureTree` is enabled, each page has a `structureTree` containing
|
|
99
|
+
all tagged-PDF roots and recursive elements with type, ID, actual/alternate text,
|
|
100
|
+
title, typed attributes, MCIDs, children, and referenced link annotations. Untagged
|
|
101
|
+
pages have an empty `roots` array; the field is omitted when disabled.
|
|
102
|
+
|
|
103
|
+
Every result also carries the document's `/Info` `creator`/`producer` when
|
|
104
|
+
present (API-level only, not in CLI JSON), and with `extractContentBounds`
|
|
105
|
+
each page carries a `contentBounds` union bbox of its top-level content
|
|
106
|
+
objects. With `extractXfaPackets`, `result.xfaPackets` lists each raw XFA
|
|
107
|
+
packet (index, name, content length, XML content); non-XFA documents yield an
|
|
108
|
+
empty array. Screenshots draw form-field appearances into the raster and
|
|
109
|
+
report `isSolidFill` per page, plus detected solid `rects` when
|
|
110
|
+
`detectScreenshotRects` is enabled.
|
|
111
|
+
|
|
69
112
|
## Parsing from Bytes
|
|
70
113
|
|
|
71
114
|
Pass a `Buffer` or `Uint8Array` directly — useful for HTTP responses or in-memory data:
|
|
@@ -133,6 +176,8 @@ The npm package includes the `lit` CLI:
|
|
|
133
176
|
```bash
|
|
134
177
|
lit parse document.pdf
|
|
135
178
|
lit parse document.pdf --format json -o output.json
|
|
179
|
+
lit parse document.pdf --format json --extract-annotations
|
|
180
|
+
lit parse document.pdf --format json --extract-form-fields
|
|
136
181
|
lit screenshot document.pdf -o ./screenshots
|
|
137
182
|
lit batch-parse ./input ./output
|
|
138
183
|
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;QACp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B,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,UAAU,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,14 @@ 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("--keep-headers-footers", "Keep running headers/footers in markdown output instead of stripping them")
|
|
54
|
+
.option("--extract-annotations", "Include all PDF annotations in page output")
|
|
55
|
+
.option("--extract-form-fields", "Include AcroForm widget fields and values")
|
|
56
|
+
.option("--extract-structure-tree", "Include the tagged-PDF logical structure tree")
|
|
57
|
+
.option("--extract-xfa-packets", "Include raw XFA packets (name + XML content) in JSON output")
|
|
58
|
+
.option("--extract-content-bounds", "Include each page's content_bounds in JSON output")
|
|
51
59
|
.option("--ocr-server-url <url>", "HTTP OCR server URL")
|
|
52
60
|
.option("--ocr-server-header <header>", 'Extra header for OCR server requests, "Name: Value" (repeatable)', collectHeader)
|
|
53
61
|
.option("--no-ocr", "Disable OCR")
|
|
@@ -56,11 +64,13 @@ program
|
|
|
56
64
|
.option("--target-pages <pages>", 'Pages to parse (e.g., "1-5,10,15-20")')
|
|
57
65
|
.option("--dpi <dpi>", "Rendering DPI", parseFloat)
|
|
58
66
|
.option("--preserve-small-text", "Keep very small text")
|
|
67
|
+
.option("--extract-text-metadata", "Include rich PDF text metadata in text items and JSON output")
|
|
59
68
|
.option("--password <password>", "Password for encrypted documents")
|
|
60
69
|
.option("--config <file>", "JSON config file path")
|
|
61
70
|
.option("-q, --quiet", "Suppress progress output")
|
|
62
71
|
.option("--num-workers <n>", "Number of concurrent OCR workers", parseInt)
|
|
63
72
|
.option("--complexity", "Include per-page complexity signals in JSON output")
|
|
73
|
+
.option("--extract-vector-graphics", "Include page-scoped vector shapes and merged horizontal/vertical lines")
|
|
64
74
|
.action(async (file, opts) => {
|
|
65
75
|
try {
|
|
66
76
|
const config = {};
|
|
@@ -74,8 +84,24 @@ program
|
|
|
74
84
|
config.outputFormat = opts.format;
|
|
75
85
|
if (opts.imageMode)
|
|
76
86
|
config.imageMode = opts.imageMode;
|
|
87
|
+
if (opts.imageOutputDir)
|
|
88
|
+
config.imageOutputDir = opts.imageOutputDir;
|
|
89
|
+
if (opts.extractImages)
|
|
90
|
+
config.extractImages = true;
|
|
77
91
|
if (opts.links === false)
|
|
78
92
|
config.extractLinks = false;
|
|
93
|
+
if (opts.keepHeadersFooters)
|
|
94
|
+
config.keepHeadersFooters = true;
|
|
95
|
+
if (opts.extractAnnotations)
|
|
96
|
+
config.extractAnnotations = true;
|
|
97
|
+
if (opts.extractFormFields)
|
|
98
|
+
config.extractFormFields = true;
|
|
99
|
+
if (opts.extractStructureTree)
|
|
100
|
+
config.extractStructureTree = true;
|
|
101
|
+
if (opts.extractXfaPackets)
|
|
102
|
+
config.extractXfaPackets = true;
|
|
103
|
+
if (opts.extractContentBounds)
|
|
104
|
+
config.extractContentBounds = true;
|
|
79
105
|
if (opts.ocrServerUrl)
|
|
80
106
|
config.ocrServerUrl = opts.ocrServerUrl;
|
|
81
107
|
if (opts.ocrServerHeader)
|
|
@@ -92,6 +118,8 @@ program
|
|
|
92
118
|
config.dpi = opts.dpi;
|
|
93
119
|
if (opts.preserveSmallText)
|
|
94
120
|
config.preserveVerySmallText = true;
|
|
121
|
+
if (opts.extractTextMetadata)
|
|
122
|
+
config.extractTextMetadata = true;
|
|
95
123
|
if (opts.password)
|
|
96
124
|
config.password = opts.password;
|
|
97
125
|
if (opts.quiet)
|
|
@@ -100,32 +128,18 @@ program
|
|
|
100
128
|
config.numWorkers = opts.numWorkers;
|
|
101
129
|
if (opts.complexity)
|
|
102
130
|
config.includeComplexity = true;
|
|
131
|
+
if (opts.extractVectorGraphics)
|
|
132
|
+
config.extractVectorGraphics = true;
|
|
103
133
|
// Default CLI output to text (library defaults to json)
|
|
104
134
|
if (!config.outputFormat)
|
|
105
135
|
config.outputFormat = "text";
|
|
106
136
|
const parser = new LiteParse(config);
|
|
107
137
|
const result = await parser.parse(await resolveInput(file));
|
|
108
138
|
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)
|
|
139
|
+
? JSON.stringify(parseResultToCliJson(result, {
|
|
140
|
+
extractTextMetadata: config.extractTextMetadata,
|
|
141
|
+
}), null, 2)
|
|
118
142
|
: 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
143
|
if (opts.output) {
|
|
130
144
|
writeFileSync(opts.output, output, "utf-8");
|
|
131
145
|
}
|
|
@@ -258,6 +272,14 @@ program
|
|
|
258
272
|
.option("--password <password>", "Password for encrypted documents")
|
|
259
273
|
.option("-q, --quiet", "Suppress progress output")
|
|
260
274
|
.option("--num-workers <n>", "Number of concurrent OCR workers", parseInt)
|
|
275
|
+
.option("--extract-text-metadata", "Include rich PDF text metadata in text items and JSON output")
|
|
276
|
+
.option("--extract-images", "Extract embedded image bytes and metadata")
|
|
277
|
+
.option("--extract-annotations", "Include all PDF annotations in page output")
|
|
278
|
+
.option("--extract-form-fields", "Include AcroForm widget fields and values")
|
|
279
|
+
.option("--extract-structure-tree", "Include the tagged-PDF logical structure tree")
|
|
280
|
+
.option("--extract-xfa-packets", "Include raw XFA packets (name + XML content) in JSON output")
|
|
281
|
+
.option("--extract-content-bounds", "Include each page's content_bounds in JSON output")
|
|
282
|
+
.option("--extract-vector-graphics", "Include page-scoped vector shapes and merged horizontal/vertical lines")
|
|
261
283
|
.action(async (inputDir, outputDir, opts) => {
|
|
262
284
|
try {
|
|
263
285
|
const config = {};
|
|
@@ -281,6 +303,28 @@ program
|
|
|
281
303
|
config.quiet = true;
|
|
282
304
|
if (opts.numWorkers)
|
|
283
305
|
config.numWorkers = opts.numWorkers;
|
|
306
|
+
if (opts.extractTextMetadata)
|
|
307
|
+
config.extractTextMetadata = true;
|
|
308
|
+
if (opts.extractImages)
|
|
309
|
+
config.extractImages = true;
|
|
310
|
+
if (opts.extractAnnotations)
|
|
311
|
+
config.extractAnnotations = true;
|
|
312
|
+
if (opts.extractFormFields)
|
|
313
|
+
config.extractFormFields = true;
|
|
314
|
+
if (opts.extractStructureTree)
|
|
315
|
+
config.extractStructureTree = true;
|
|
316
|
+
if (opts.extractXfaPackets)
|
|
317
|
+
config.extractXfaPackets = true;
|
|
318
|
+
if (opts.extractContentBounds)
|
|
319
|
+
config.extractContentBounds = true;
|
|
320
|
+
if (opts.extractContentBounds)
|
|
321
|
+
config.extractContentBounds = true;
|
|
322
|
+
if (opts.extractXfaPackets)
|
|
323
|
+
config.extractXfaPackets = true;
|
|
324
|
+
if (opts.extractContentBounds)
|
|
325
|
+
config.extractContentBounds = true;
|
|
326
|
+
if (opts.extractVectorGraphics)
|
|
327
|
+
config.extractVectorGraphics = true;
|
|
284
328
|
const parser = new LiteParse(config);
|
|
285
329
|
const outExt = format === "json" ? ".json" : format === "markdown" ? ".md" : ".txt";
|
|
286
330
|
mkdirSync(outputDir, { recursive: true });
|
|
@@ -308,15 +352,9 @@ program
|
|
|
308
352
|
try {
|
|
309
353
|
const result = await parser.parse(filePath);
|
|
310
354
|
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)
|
|
355
|
+
? JSON.stringify(parseResultToCliJson(result, {
|
|
356
|
+
extractTextMetadata: config.extractTextMetadata,
|
|
357
|
+
}), null, 2)
|
|
320
358
|
: result.text;
|
|
321
359
|
writeFileSync(outPath, output, "utf-8");
|
|
322
360
|
success++;
|