A fast, helpful, and open-source document parser
Keep default JSON output stable: gate content_bounds, API-only creator/producer
Pierre-Loic doulcet65ffc4dc0c82
diff --git a/README.md b/README.mdindex d7db3fd..f9a0e04 100644--- a/README.md+++ b/README.md@@ -255,13 +255,16 @@ link annotations. The field is absent by default; enabled untagged pages contain### Document metadata, content bounds, and XFA packets-Every parse result now carries the document's `/Info` `creator` and `producer`-entries when present, and every page carries `content_bounds` — the union bbox-of the page's top-level content objects in viewport coords (absent for empty-pages). Enable `--extract-xfa-packets` (Rust/Python `extract_xfa_packets`,-JavaScript/WASM `extractXfaPackets`) to add `xfa_packets` with each raw XFA-packet's index, name, byte length, and XML content; non-XFA documents yield an-empty list.+Parse results (Rust/Node/Python APIs) carry the document's `/Info` `creator`+and `producer` entries when present; these are API-only and never appear in+CLI JSON output. Enable `--extract-content-bounds` (Rust/Python+`extract_content_bounds`, JavaScript/WASM `extractContentBounds`) to add a+per-page `content_bounds` — the union bbox of the page's top-level content+objects in viewport coords (absent for empty pages). Enable+`--extract-xfa-packets` (Rust/Python `extract_xfa_packets`, JavaScript/WASM+`extractXfaPackets`) to add `xfa_packets` with each raw XFA packet's index,+name, byte length, and XML content; non-XFA documents yield an empty list.+All of these are off by default, so default JSON output is unchanged.### Screenshot raster signalsdiff --git a/crates/liteparse-napi/src/types.rs b/crates/liteparse-napi/src/types.rsindex 11879eb..57f2142 100644--- a/crates/liteparse-napi/src/types.rs+++ b/crates/liteparse-napi/src/types.rs@@ -65,6 +65,9 @@ pub struct JsLiteParseConfig {/// Extract raw XFA packets (name + XML content) into/// `ParseResult.xfaPackets`. Default false.pub extract_xfa_packets: Option<bool>,+ /// Emit each page's `contentBounds` (union bbox of top-level content+ /// objects, viewport coords). Default false.+ pub extract_content_bounds: Option<bool>,/// Detect solid rectangles/lines in rendered page screenshots and attach/// them to each screenshot result. Default false.pub detect_screenshot_rects: Option<bool>,@@ -182,6 +185,9 @@ impl JsLiteParseConfig {if let Some(v) = self.extract_xfa_packets {cfg.extract_xfa_packets = v;}+ if let Some(v) = self.extract_content_bounds {+ cfg.extract_content_bounds = v;+ }if let Some(v) = self.detect_screenshot_rects {cfg.detect_screenshot_rects = v;}@@ -252,6 +258,7 @@ impl JsLiteParseConfig {extract_form_fields: Some(cfg.extract_form_fields),extract_structure_tree: Some(cfg.extract_structure_tree),extract_xfa_packets: Some(cfg.extract_xfa_packets),+ extract_content_bounds: Some(cfg.extract_content_bounds),detect_screenshot_rects: Some(cfg.detect_screenshot_rects),ocr_failure_fatal: Some(cfg.ocr_failure_fatal),ocr_hedge_delays_ms: Some(diff --git a/crates/liteparse-python/src/cli.rs b/crates/liteparse-python/src/cli.rsindex b031427..cde165a 100644--- a/crates/liteparse-python/src/cli.rs+++ b/crates/liteparse-python/src/cli.rs@@ -88,6 +88,10 @@ struct ParseCommand {/// Include raw XFA packets (name + XML content) in JSON output.#[arg(long)]extract_xfa_packets: bool,+ /// Include each page's content_bounds (union bbox of top-level content+ /// objects, viewport coords) in JSON output.+ #[arg(long)]+ extract_content_bounds: bool,/// Include per-page complexity signals as a `complexity` object on each/// page of JSON output. Off by default.#[arg(long)]@@ -183,6 +187,10 @@ struct BatchParseCommand {/// Include raw XFA packets (name + XML content) in JSON output.#[arg(long)]extract_xfa_packets: bool,+ /// Include each page's content_bounds (union bbox of top-level content+ /// objects, viewport coords) in JSON output.+ #[arg(long)]+ extract_content_bounds: bool,}/// Parse a `Name: Value` header string into a `(name, value)` pair.@@ -266,6 +274,7 @@ pub fn run_cli(args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {extract_form_fields: cmd.extract_form_fields,extract_structure_tree: cmd.extract_structure_tree,extract_xfa_packets: cmd.extract_xfa_packets,+ extract_content_bounds: cmd.extract_content_bounds,include_complexity: cmd.complexity,extract_text_metadata: cmd.extract_text_metadata,extract_vector_graphics: cmd.extract_vector_graphics,@@ -360,6 +369,7 @@ pub fn run_cli(args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {extract_vector_graphics: cmd.extract_vector_graphics,extract_structure_tree: cmd.extract_structure_tree,extract_xfa_packets: cmd.extract_xfa_packets,+ extract_content_bounds: cmd.extract_content_bounds,..Default::default()};if let Some(n) = cmd.num_workers {diff --git a/crates/liteparse-python/src/lib.rs b/crates/liteparse-python/src/lib.rsindex d9707cf..0359968 100644--- a/crates/liteparse-python/src/lib.rs+++ b/crates/liteparse-python/src/lib.rs@@ -992,6 +992,8 @@ struct PyLiteParseConfig {#[pyo3(get)]extract_xfa_packets: bool,#[pyo3(get)]+ extract_content_bounds: bool,+ #[pyo3(get)]detect_screenshot_rects: bool,#[pyo3(get)]ocr_failure_fatal: bool,@@ -1059,6 +1061,7 @@ impl PyLiteParseConfig {extract_form_fields: cfg.extract_form_fields,extract_structure_tree: cfg.extract_structure_tree,extract_xfa_packets: cfg.extract_xfa_packets,+ extract_content_bounds: cfg.extract_content_bounds,detect_screenshot_rects: cfg.detect_screenshot_rects,ocr_failure_fatal: cfg.ocr_failure_fatal,ocr_hedge_delays_ms: cfg.ocr_hedge_delays_ms.clone(),@@ -1114,6 +1117,7 @@ impl LiteParse {extract_form_fields = None,extract_structure_tree = None,extract_xfa_packets = None,+ extract_content_bounds = None,detect_screenshot_rects = None,ocr_failure_fatal = None,ocr_hedge_delays_ms = None,@@ -1146,6 +1150,7 @@ impl LiteParse {extract_form_fields: Option<bool>,extract_structure_tree: Option<bool>,extract_xfa_packets: Option<bool>,+ extract_content_bounds: Option<bool>,detect_screenshot_rects: Option<bool>,ocr_failure_fatal: Option<bool>,ocr_hedge_delays_ms: Option<Vec<u64>>,@@ -1228,6 +1233,9 @@ impl LiteParse {if let Some(v) = extract_xfa_packets {cfg.extract_xfa_packets = v;}+ if let Some(v) = extract_content_bounds {+ cfg.extract_content_bounds = v;+ }if let Some(v) = detect_screenshot_rects {cfg.detect_screenshot_rects = v;}diff --git a/crates/liteparse-wasm/src/lib.rs b/crates/liteparse-wasm/src/lib.rsindex ffe7af4..8e4fe7a 100644--- a/crates/liteparse-wasm/src/lib.rs+++ b/crates/liteparse-wasm/src/lib.rs@@ -62,6 +62,9 @@ pub struct LiteParseConfig {/// Extract raw XFA packets (name + XML content) into/// `ParseResult.xfaPackets`. Default false.extract_xfa_packets: Option<bool>,+ /// Emit each page's `contentBounds` (union bbox of top-level content+ /// objects, viewport coords). Default false.+ extract_content_bounds: Option<bool>,ocr_failure_fatal: Option<bool>,ocr_hedge_delays_ms: Option<Vec<u64>>,preserve_very_small_text: Option<bool>,@@ -160,6 +163,9 @@ impl LiteParseConfig {if let Some(v) = self.extract_xfa_packets {cfg.extract_xfa_packets = v;}+ if let Some(v) = self.extract_content_bounds {+ cfg.extract_content_bounds = v;+ }if let Some(v) = self.ocr_failure_fatal {cfg.ocr_failure_fatal = v;}@@ -229,6 +235,7 @@ impl LiteParseConfig {extract_form_fields: Some(cfg.extract_form_fields),extract_structure_tree: Some(cfg.extract_structure_tree),extract_xfa_packets: Some(cfg.extract_xfa_packets),+ extract_content_bounds: Some(cfg.extract_content_bounds),ocr_failure_fatal: Some(cfg.ocr_failure_fatal),ocr_hedge_delays_ms: Some(cfg.ocr_hedge_delays_ms.clone()),preserve_very_small_text: Some(cfg.preserve_very_small_text),diff --git a/crates/liteparse/src/config.rs b/crates/liteparse/src/config.rsindex b7d348c..688773e 100644--- a/crates/liteparse/src/config.rs+++ b/crates/liteparse/src/config.rs@@ -54,6 +54,13 @@ pub struct LiteParseConfig {/// Extract the tagged-PDF logical structure tree. Default `false`.#[serde(default)]pub extract_structure_tree: bool,+ /// Emit each page's `content_bounds` — the union bbox of its top-level+ /// content objects in viewport coords (visible content extent). Default+ /// `false` to keep the default output shape unchanged. Content bounds are+ /// still computed internally for the white-fill heuristic whenever+ /// `extract_vector_graphics` is on.+ #[serde(default)]+ pub extract_content_bounds: bool,/// Extract raw XFA packets (name + XML content) from XFA form documents/// into `ParseResult.xfa_packets`. Default `false`. Non-XFA documents/// yield an empty list.@@ -187,6 +194,7 @@ impl Default for LiteParseConfig {extract_annotations: false,extract_form_fields: false,extract_structure_tree: false,+ extract_content_bounds: false,extract_xfa_packets: false,detect_screenshot_rects: false,ocr_failure_fatal: true,diff --git a/crates/liteparse/src/extract.rs b/crates/liteparse/src/extract.rsindex db35e4d..0cf8b0e 100644--- a/crates/liteparse/src/extract.rs+++ b/crates/liteparse/src/extract.rs@@ -116,9 +116,15 @@ pub(crate) fn extract_pages_and_images(if extract_links {assign_links(&mut text_items, &page.links(&view_box));}- let content_bounds = page- .content_bounds()- .map(|bounds| rect_from_pdfium(page.bounds_to_viewport(&view_box, &bounds)));+ // Computed when emitted (`extract_content_bounds`) or needed+ // internally by the white-fill heuristic (`extract_vector_graphics`).+ let content_bounds = (output_options.extract_content_bounds+ || output_options.extract_vector_graphics)+ .then(|| {+ page.content_bounds()+ .map(|bounds| rect_from_pdfium(page.bounds_to_viewport(&view_box, &bounds)))+ })+ .flatten();let paths = page.path_objects(&view_box);let graphics = extract_layout_graphics(&paths);let vector_graphics = output_options@@ -192,7 +198,10 @@ pub(crate) fn extract_pages_and_images(page_number: page_number as usize,page_width: page.width(),page_height: page.height(),- content_bounds,+ content_bounds: output_options+ .extract_content_bounds+ .then_some(content_bounds)+ .flatten(),text_items,graphics,vector_graphics,@@ -209,6 +218,7 @@ pub(crate) fn extract_pages_and_images(#[derive(Debug, Clone, Copy, Default)]pub(crate) struct ExtractionOutputOptions {+ pub extract_content_bounds: bool,pub extract_text_metadata: bool,pub extract_images: bool,pub extract_vector_graphics: bool,diff --git a/crates/liteparse/src/main.rs b/crates/liteparse/src/main.rsindex 5b6bdd1..678be9e 100644--- a/crates/liteparse/src/main.rs+++ b/crates/liteparse/src/main.rs@@ -137,6 +137,10 @@ struct ParseCommand {/// Include raw XFA packets (name + XML content) in JSON output.#[arg(long)]extract_xfa_packets: bool,+ /// Include each page's content_bounds (union bbox of top-level content+ /// objects, viewport coords) in JSON output.+ #[arg(long)]+ extract_content_bounds: bool,/// Include per-page complexity signals (the same `is-complex` reports) as a/// `complexity` object on each page of JSON output. Off by default; enabling@@ -264,6 +268,10 @@ struct BatchParseCommand {/// Include raw XFA packets (name + XML content) in JSON output.#[arg(long)]extract_xfa_packets: bool,+ /// Include each page's content_bounds (union bbox of top-level content+ /// objects, viewport coords) in JSON output.+ #[arg(long)]+ extract_content_bounds: bool,}#[derive(Args, Debug)]@@ -387,6 +395,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {extract_form_fields: cmd.extract_form_fields,extract_structure_tree: cmd.extract_structure_tree,extract_xfa_packets: cmd.extract_xfa_packets,+ extract_content_bounds: cmd.extract_content_bounds,include_complexity: cmd.complexity,extract_text_metadata: cmd.extract_text_metadata,extract_vector_graphics: cmd.extract_vector_graphics,@@ -488,6 +497,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {extract_form_fields: cmd.extract_form_fields,extract_structure_tree: cmd.extract_structure_tree,extract_xfa_packets: cmd.extract_xfa_packets,+ extract_content_bounds: cmd.extract_content_bounds,..Default::default()};if let Some(n) = cmd.num_workers {diff --git a/crates/liteparse/src/output/json.rs b/crates/liteparse/src/output/json.rsindex 90f7dd1..a707ab3 100644--- a/crates/liteparse/src/output/json.rs+++ b/crates/liteparse/src/output/json.rs@@ -73,10 +73,10 @@ pub(crate) struct ParseResultJson {pub image_error_count: u32,#[serde(skip_serializing_if = "Option::is_none")]pub form_type: Option<i32>,- #[serde(skip_serializing_if = "Option::is_none")]- pub creator: Option<String>,- #[serde(skip_serializing_if = "Option::is_none")]- pub producer: Option<String>,+ /// Raw XFA packets — present only when `extract_xfa_packets` was+ /// requested, so the default CLI JSON stays stable. The document's+ /// `/Info` creator/producer are deliberately API-only+ /// (`ParseResult.creator`/`.producer`) for the same reason.#[serde(skip_serializing_if = "Option::is_none")]pub xfa_packets: Option<Vec<XfaPacket>>,}@@ -107,8 +107,6 @@ pub(crate) fn build_json(pages: &[ParsedPage], extract_text_metadata: bool) -> Pimages: Vec::new(),image_error_count: 0,form_type: None,- creator: None,- producer: None,xfa_packets: None,pages: pages.iter()@@ -189,8 +187,6 @@ pub fn format_json_result(.collect();json.image_error_count = result.image_error_count;json.form_type = result.form_type;- json.creator = result.creator.clone();- json.producer = result.producer.clone();json.xfa_packets = result.xfa_packets.clone();serde_json::to_string_pretty(&json)}@@ -409,8 +405,8 @@ mod tests {};let value: serde_json::Value =serde_json::from_str(&format_json_result(&result, false).unwrap()).unwrap();- assert_eq!(value["creator"], "LibreOffice");- assert_eq!(value["producer"], "LibreOffice 7.4");+ assert!(value.get("creator").is_none());+ assert!(value.get("producer").is_none());assert_eq!(value["xfa_packets"][0]["name"], "datasets");assert_eq!(value["xfa_packets"][0]["content_length"], 11);assert_eq!(value["images"][0]["bbox"]["x"], 10.0);diff --git a/crates/liteparse/src/parser.rs b/crates/liteparse/src/parser.rsindex 2a4ff1a..5ef938b 100644--- a/crates/liteparse/src/parser.rs+++ b/crates/liteparse/src/parser.rs@@ -431,6 +431,7 @@ impl LiteParse {&& self.config.output_format == crate::config::OutputFormat::Markdown,self.glyph_resolver.as_deref(),extract::ExtractionOutputOptions {+ extract_content_bounds: self.config.extract_content_bounds,extract_images: self.config.extract_images,emit_word_boxes: self.config.emit_word_boxes,extract_text_metadata: self.config.extract_text_metadata,diff --git a/packages/node/README.md b/packages/node/README.mdindex 6d8eb8a..0052176 100644--- a/packages/node/README.md+++ b/packages/node/README.md@@ -66,6 +66,7 @@ const parser = new LiteParse({extractFormFields: false, // Include AcroForm widget fields and valuesextractStructureTree: false, // Include tagged-PDF logical structureextractXfaPackets: false, // Include raw XFA packets (name + XML content)+ extractContentBounds: false, // Include per-page contentBounds union bboxdetectScreenshotRects: false, // Detect solid rects/lines in screenshotspreserveVerySmallText: false, // Keep tiny textextractTextMetadata: false, // Opt in to MCID, font metrics, colors, char codes, and trailingSpaceGenerated@@ -99,7 +100,8 @@ title, typed attributes, MCIDs, children, and referenced link annotations. Untagpages have an empty `roots` array; the field is omitted when disabled.Every result also carries the document's `/Info` `creator`/`producer` when-present, and each page a `contentBounds` union bbox of its top-level content+present (API-level only — not in CLI JSON), and with `extractContentBounds`+each page carries a `contentBounds` union bbox of its top-level contentobjects. With `extractXfaPackets`, `result.xfaPackets` lists each raw XFApacket (index, name, content length, XML content); non-XFA documents yield anempty array. Screenshots draw form-field appearances into the raster anddiff --git a/packages/node/native.d.ts b/packages/node/native.d.tsindex bf935ed..6bb9834 100644--- a/packages/node/native.d.ts+++ b/packages/node/native.d.ts@@ -62,6 +62,11 @@ export interface JsLiteParseConfig {* `ParseResult.xfaPackets`. Default false.*/extractXfaPackets?: boolean+ /**+ * Emit each page's `contentBounds` (union bbox of top-level content+ * objects, viewport coords). Default false.+ */+ extractContentBounds?: boolean/*** Detect solid rectangles/lines in rendered page screenshots and attach* them to each screenshot result. Default false.diff --git a/packages/node/src/cli.ts b/packages/node/src/cli.tsindex 6db7662..146866c 100644--- a/packages/node/src/cli.ts+++ b/packages/node/src/cli.ts@@ -72,6 +72,10 @@ program"--extract-xfa-packets","Include raw XFA packets (name + XML content) in JSON output",)+ .option(+ "--extract-content-bounds",+ "Include each page's content_bounds in JSON output",+ ).option("--ocr-server-url <url>", "HTTP OCR server URL").option("--ocr-server-header <header>",@@ -127,6 +131,7 @@ programif (opts.extractFormFields) config.extractFormFields = true;if (opts.extractStructureTree) config.extractStructureTree = true;if (opts.extractXfaPackets) config.extractXfaPackets = true;+ if (opts.extractContentBounds) config.extractContentBounds = true;if (opts.ocrServerUrl)config.ocrServerUrl = opts.ocrServerUrl as string;if (opts.ocrServerHeader)@@ -331,6 +336,10 @@ program"--extract-xfa-packets","Include raw XFA packets (name + XML content) in JSON output",)+ .option(+ "--extract-content-bounds",+ "Include each page's content_bounds in JSON output",+ ).option("--extract-vector-graphics","Include page-scoped vector shapes and merged horizontal/vertical lines",@@ -362,7 +371,10 @@ programif (opts.extractFormFields) config.extractFormFields = true;if (opts.extractStructureTree) config.extractStructureTree = true;if (opts.extractXfaPackets) config.extractXfaPackets = true;+ if (opts.extractContentBounds) config.extractContentBounds = true;+ if (opts.extractContentBounds) config.extractContentBounds = true;if (opts.extractXfaPackets) config.extractXfaPackets = true;+ if (opts.extractContentBounds) config.extractContentBounds = true;if (opts.extractVectorGraphics) config.extractVectorGraphics = true;const parser = new LiteParse(config);diff --git a/packages/node/src/lib.ts b/packages/node/src/lib.tsindex d53dd96..ed6678b 100644--- a/packages/node/src/lib.ts+++ b/packages/node/src/lib.ts@@ -46,6 +46,8 @@ export interface LiteParseConfig {extractStructureTree: boolean;/** Extract raw XFA packets (name + XML content) into `ParseResult.xfaPackets` (default: false). */extractXfaPackets: boolean;+ /** Emit each page's `contentBounds` (union bbox of top-level content objects) (default: false). */+ extractContentBounds: boolean;/** Detect solid rectangles/lines in rendered page screenshots (default: false). */detectScreenshotRects: boolean;preserveVerySmallText: boolean;@@ -213,6 +215,7 @@ export interface ParsedPage {* Union bbox of the page's top-level content objects in viewport coords* (visible content extent). Absent for empty pages.*/+ /** Present only when `extractContentBounds` is enabled. */contentBounds?: Rect;text: string;markdown: string;@@ -485,6 +488,7 @@ export class LiteParse {extractFormFields: userConfig.extractFormFields,extractStructureTree: userConfig.extractStructureTree,extractXfaPackets: userConfig.extractXfaPackets,+ extractContentBounds: userConfig.extractContentBounds,detectScreenshotRects: userConfig.detectScreenshotRects,preserveVerySmallText: userConfig.preserveVerySmallText,password: userConfig.password,@@ -522,6 +526,7 @@ export class LiteParse {extractFormFields: resolved.extractFormFields ?? false,extractStructureTree: resolved.extractStructureTree ?? false,extractXfaPackets: resolved.extractXfaPackets ?? false,+ extractContentBounds: resolved.extractContentBounds ?? false,detectScreenshotRects: resolved.detectScreenshotRects ?? false,preserveVerySmallText: resolved.preserveVerySmallText ?? false,password: resolved.password ?? undefined,diff --git a/packages/node/src/native.ts b/packages/node/src/native.tsindex 922f8ca..1d5a5e9 100644--- a/packages/node/src/native.ts+++ b/packages/node/src/native.ts@@ -37,6 +37,7 @@ export interface LiteParseNativeConfig {extractFormFields?: boolean;extractStructureTree?: boolean;extractXfaPackets?: boolean;+ extractContentBounds?: boolean;detectScreenshotRects?: boolean;preserveVerySmallText?: boolean;password?: string;diff --git a/packages/python/liteparse/parser.py b/packages/python/liteparse/parser.pyindex c67ca56..9cd68db 100644--- a/packages/python/liteparse/parser.py+++ b/packages/python/liteparse/parser.py@@ -369,6 +369,7 @@ class LiteParse:extract_form_fields: Optional[bool] = None,extract_structure_tree: Optional[bool] = None,extract_xfa_packets: Optional[bool] = None,+ extract_content_bounds: Optional[bool] = None,detect_screenshot_rects: Optional[bool] = None,ocr_failure_fatal: Optional[bool] = None,ocr_hedge_delays_ms: Optional[List[int]] = None,@@ -489,6 +490,8 @@ class LiteParse:kwargs["extract_structure_tree"] = extract_structure_treeif extract_xfa_packets is not None:kwargs["extract_xfa_packets"] = extract_xfa_packets+ if extract_content_bounds is not None:+ kwargs["extract_content_bounds"] = extract_content_boundsif detect_screenshot_rects is not None:kwargs["detect_screenshot_rects"] = detect_screenshot_rectsif ocr_failure_fatal is not None:@@ -667,6 +670,7 @@ class LiteParse:extract_images=cfg.extract_images,extract_vector_graphics=cfg.extract_vector_graphics,extract_xfa_packets=cfg.extract_xfa_packets,+ extract_content_bounds=cfg.extract_content_bounds,detect_screenshot_rects=cfg.detect_screenshot_rects,)diff --git a/packages/python/liteparse/types.py b/packages/python/liteparse/types.pyindex 476f25e..fe0e2b8 100644--- a/packages/python/liteparse/types.py+++ b/packages/python/liteparse/types.py@@ -138,8 +138,9 @@ class ParsedPage:#: Present only when parsing with ``extract_structure_tree=True``.structure_tree: Optional[StructureTree] = None#: Union bbox ``(x, y, width, height)`` of the page's top-level content- #: objects in viewport coords (visible content extent). ``None`` for- #: empty pages.+ #: objects in viewport coords (visible content extent). Present only when+ #: parsing with ``extract_content_bounds=True``; ``None`` otherwise (and+ #: for empty pages).content_bounds: Optional[Tuple[float, float, float, float]] = None@@ -351,6 +352,7 @@ class LiteParseConfig:extract_vector_graphics: bool = Falseextract_xfa_packets: bool = Falsedetect_screenshot_rects: bool = False+ extract_content_bounds: bool = Falseclass ParseError(Exception):