Skip to content

A fast, helpful, and open-source document parser

feat: add option to keep headers/footers, also tighten detection

Logan Markewichee248e931817
diff --git a/Cargo.lock b/Cargo.lock
index cf05ac2..0381b67 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2016,7 +2016,7 @@ checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0"
[[package]]
name = "liteparse"
-version = "2.9.0"
+version = "2.10.0"
dependencies = [
"blake3",
"clap",
@@ -2047,7 +2047,7 @@ dependencies = [
[[package]]
name = "liteparse-napi"
-version = "2.9.0"
+version = "2.10.0"
dependencies = [
"image",
"liteparse",
@@ -2082,7 +2082,7 @@ dependencies = [
[[package]]
name = "liteparse-python"
-version = "2.9.0"
+version = "2.10.0"
dependencies = [
"anyhow",
"clap",
@@ -2098,7 +2098,7 @@ dependencies = [
[[package]]
name = "liteparse-wasm"
-version = "2.9.0"
+version = "2.10.0"
dependencies = [
"console_error_panic_hook",
"js-sys",
diff --git a/README.md b/README.md
index f11568f..70cd2ce 100644
--- a/README.md
+++ b/README.md
@@ -343,6 +343,7 @@ Options:
--extract-text-metadata Include rich PDF text metadata in text items
--extract-vector-graphics Include page vector shapes and merged H/V lines
--no-links Emit link anchor text as plain text (no [text](url)) in markdown
+ --keep-headers-footers Keep running headers/footers in markdown (skip repeated-line stripping)
--extract-annotations Include PDF annotations in page output
--extract-form-fields Include AcroForm widget fields and values
--preserve-small-text Keep very small text
diff --git a/crates/liteparse-napi/Cargo.toml b/crates/liteparse-napi/Cargo.toml
index 2809138..46ef8cf 100644
--- a/crates/liteparse-napi/Cargo.toml
+++ b/crates/liteparse-napi/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "liteparse-napi"
-version = "2.9.0"
+version = "2.10.0"
edition.workspace = true
license.workspace = true
repository.workspace = true
@@ -14,7 +14,7 @@ default = ["tesseract"]
tesseract = ["liteparse/tesseract"]
[dependencies]
-liteparse = { package = "liteparse", version = "2.9.0", path = "../liteparse", default-features = false }
+liteparse = { package = "liteparse", version = "2.10.0", path = "../liteparse", default-features = false }
pdfium-sys = { package = "liteparse-pdfium-sys", version = "1.4.0", path = "../pdfium-sys" }
napi = { version = "2", features = ["async", "serde-json", "napi9"] }
napi-derive = "2"
diff --git a/crates/liteparse-napi/src/types.rs b/crates/liteparse-napi/src/types.rs
index 99b9002..162645e 100644
--- a/crates/liteparse-napi/src/types.rs
+++ b/crates/liteparse-napi/src/types.rs
@@ -56,6 +56,9 @@ pub struct JsLiteParseConfig {
/// Render hyperlink annotations as `[text](url)` in markdown output
/// (default true). Set false for plain anchor text.
pub extract_links: Option<bool>,
+ /// Keep running headers/footers in markdown output instead of stripping
+ /// repeated page-band lines and page chrome (default false).
+ pub keep_headers_footers: Option<bool>,
/// Extract all PDF annotations as page-scoped structured data.
pub extract_annotations: Option<bool>,
/// Extract AcroForm widget fields and values.
@@ -176,6 +179,9 @@ impl JsLiteParseConfig {
if let Some(v) = self.extract_links {
cfg.extract_links = v;
}
+ if let Some(v) = self.keep_headers_footers {
+ cfg.keep_headers_footers = v;
+ }
if let Some(v) = self.extract_annotations {
cfg.extract_annotations = v;
}
@@ -260,6 +266,7 @@ impl JsLiteParseConfig {
extract_images: Some(cfg.extract_images),
image_output_dir: cfg.image_output_dir.clone(),
extract_links: Some(cfg.extract_links),
+ keep_headers_footers: Some(cfg.keep_headers_footers),
extract_annotations: Some(cfg.extract_annotations),
extract_form_fields: Some(cfg.extract_form_fields),
extract_structure_tree: Some(cfg.extract_structure_tree),
diff --git a/crates/liteparse-python/Cargo.toml b/crates/liteparse-python/Cargo.toml
index 0799c67..299a2aa 100644
--- a/crates/liteparse-python/Cargo.toml
+++ b/crates/liteparse-python/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "liteparse-python"
-version = "2.9.0"
+version = "2.10.0"
edition.workspace = true
license.workspace = true
repository.workspace = true
@@ -15,7 +15,7 @@ default = ["tesseract"]
tesseract = ["liteparse/tesseract"]
[dependencies]
-liteparse = { package = "liteparse", version = "2.9.0", path = "../liteparse", default-features = false }
+liteparse = { package = "liteparse", version = "2.10.0", path = "../liteparse", default-features = false }
pdfium-sys = { package = "liteparse-pdfium-sys", version = "1.4.0", path = "../pdfium-sys" }
pdfium = { package = "liteparse-pdfium", version = "1.4.0", path = "../pdfium" }
clap = { version = "4.5.55", features = ["derive"] }
diff --git a/crates/liteparse-python/src/cli.rs b/crates/liteparse-python/src/cli.rs
index 5bff1eb..2a7c128 100644
--- a/crates/liteparse-python/src/cli.rs
+++ b/crates/liteparse-python/src/cli.rs
@@ -76,6 +76,10 @@ struct ParseCommand {
/// `[text](url)` in markdown output; pass this to emit plain anchor text.
#[arg(long)]
no_links: bool,
+ /// Keep running headers/footers in markdown output instead of stripping
+ /// repeated page-band lines and page chrome.
+ #[arg(long)]
+ keep_headers_footers: bool,
/// Include all PDF annotations as page-scoped structured data.
#[arg(long)]
extract_annotations: bool,
@@ -276,6 +280,7 @@ pub fn run_cli(args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
extract_images: cmd.extract_images,
image_output_dir: cmd.image_output_dir.clone(),
extract_links: !cmd.no_links,
+ keep_headers_footers: cmd.keep_headers_footers,
extract_annotations: cmd.extract_annotations,
extract_form_fields: cmd.extract_form_fields,
extract_structure_tree: cmd.extract_structure_tree,
diff --git a/crates/liteparse-python/src/lib.rs b/crates/liteparse-python/src/lib.rs
index 9cf5839..a3ff467 100644
--- a/crates/liteparse-python/src/lib.rs
+++ b/crates/liteparse-python/src/lib.rs
@@ -990,6 +990,8 @@ struct PyLiteParseConfig {
#[pyo3(get)]
extract_links: bool,
#[pyo3(get)]
+ keep_headers_footers: bool,
+ #[pyo3(get)]
extract_annotations: bool,
#[pyo3(get)]
extract_form_fields: bool,
@@ -1065,6 +1067,7 @@ impl PyLiteParseConfig {
ImageMode::Embed => "embed".to_string(),
},
extract_links: cfg.extract_links,
+ keep_headers_footers: cfg.keep_headers_footers,
extract_annotations: cfg.extract_annotations,
extract_form_fields: cfg.extract_form_fields,
extract_structure_tree: cfg.extract_structure_tree,
@@ -1122,6 +1125,7 @@ impl LiteParse {
extract_images = None,
image_output_dir = None,
extract_links = None,
+ keep_headers_footers = None,
extract_annotations = None,
extract_form_fields = None,
extract_structure_tree = None,
@@ -1156,6 +1160,7 @@ impl LiteParse {
extract_images: Option<bool>,
image_output_dir: Option<String>,
extract_links: Option<bool>,
+ keep_headers_footers: Option<bool>,
extract_annotations: Option<bool>,
extract_form_fields: Option<bool>,
extract_structure_tree: Option<bool>,
@@ -1232,6 +1237,9 @@ impl LiteParse {
if let Some(v) = extract_links {
cfg.extract_links = v;
}
+ if let Some(v) = keep_headers_footers {
+ cfg.keep_headers_footers = v;
+ }
if let Some(v) = extract_annotations {
cfg.extract_annotations = v;
}
diff --git a/crates/liteparse-wasm/Cargo.toml b/crates/liteparse-wasm/Cargo.toml
index 7454df7..99b7235 100644
--- a/crates/liteparse-wasm/Cargo.toml
+++ b/crates/liteparse-wasm/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "liteparse-wasm"
-version = "2.9.0"
+version = "2.10.0"
edition.workspace = true
license.workspace = true
repository.workspace = true
diff --git a/crates/liteparse-wasm/src/lib.rs b/crates/liteparse-wasm/src/lib.rs
index 482690a..4a357f7 100644
--- a/crates/liteparse-wasm/src/lib.rs
+++ b/crates/liteparse-wasm/src/lib.rs
@@ -56,6 +56,9 @@ pub struct LiteParseConfig {
image_mode: Option<String>,
extract_images: Option<bool>,
extract_links: Option<bool>,
+ /// Keep running headers/footers in markdown output instead of stripping
+ /// repeated page-band lines and page chrome. Default false.
+ keep_headers_footers: Option<bool>,
extract_annotations: Option<bool>,
extract_form_fields: Option<bool>,
extract_structure_tree: Option<bool>,
@@ -158,6 +161,9 @@ impl LiteParseConfig {
if let Some(v) = self.extract_links {
cfg.extract_links = v;
}
+ if let Some(v) = self.keep_headers_footers {
+ cfg.keep_headers_footers = v;
+ }
if let Some(v) = self.extract_annotations {
cfg.extract_annotations = v;
}
@@ -244,6 +250,7 @@ impl LiteParseConfig {
}),
extract_images: Some(cfg.extract_images),
extract_links: Some(cfg.extract_links),
+ keep_headers_footers: Some(cfg.keep_headers_footers),
extract_annotations: Some(cfg.extract_annotations),
extract_form_fields: Some(cfg.extract_form_fields),
extract_structure_tree: Some(cfg.extract_structure_tree),
diff --git a/crates/liteparse/Cargo.toml b/crates/liteparse/Cargo.toml
index 24eb493..dbd5904 100644
--- a/crates/liteparse/Cargo.toml
+++ b/crates/liteparse/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "liteparse"
-version = "2.9.0"
+version = "2.10.0"
edition.workspace = true
license.workspace = true
repository.workspace = true
diff --git a/crates/liteparse/src/config.rs b/crates/liteparse/src/config.rs
index 74e2699..bffa601 100644
--- a/crates/liteparse/src/config.rs
+++ b/crates/liteparse/src/config.rs
@@ -45,6 +45,14 @@ pub struct LiteParseConfig {
/// markdown output. Default on. Disable for benchmark parity with
/// plain-text ground truth (the GT corpora never use link syntax).
pub extract_links: bool,
+ /// Keep running header/footer chrome in markdown output instead of
+ /// stripping it. By default the markdown renderer removes lines that
+ /// repeat in the top/bottom page bands across pages (and single-page
+ /// chrome like `Page N of M`). Set `true` to retain everything —
+ /// useful for extraction pipelines that would rather deduplicate
+ /// downstream than risk losing content. Only affects Markdown output.
+ #[serde(default)]
+ pub keep_headers_footers: bool,
/// Extract all PDF annotations into each parsed page. Default `false`.
/// This is independent of `extract_links`, which only controls Markdown
/// link reconstruction.
@@ -210,6 +218,7 @@ impl Default for LiteParseConfig {
extract_images: false,
image_output_dir: None,
extract_links: true,
+ keep_headers_footers: false,
extract_annotations: false,
extract_form_fields: false,
extract_structure_tree: false,
diff --git a/crates/liteparse/src/main.rs b/crates/liteparse/src/main.rs
index 3696544..48cb191 100644
--- a/crates/liteparse/src/main.rs
+++ b/crates/liteparse/src/main.rs
@@ -123,6 +123,14 @@ struct ParseCommand {
#[arg(long)]
no_links: bool,
+ /// Keep running headers/footers in markdown output. By default, lines
+ /// that repeat in the top/bottom page bands across pages (and obvious
+ /// page chrome like `Page N of M`) are stripped from markdown. Pass this
+ /// to retain them all — e.g. for extraction pipelines that prefer to
+ /// deduplicate downstream rather than risk losing content.
+ #[arg(long)]
+ keep_headers_footers: bool,
+
/// Include all PDF annotations as page-scoped structured JSON/API data.
#[arg(long)]
extract_annotations: bool,
@@ -391,6 +399,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
extract_images: cmd.extract_images,
image_output_dir: cmd.image_output_dir.clone(),
extract_links: !cmd.no_links,
+ keep_headers_footers: cmd.keep_headers_footers,
extract_annotations: cmd.extract_annotations,
extract_form_fields: cmd.extract_form_fields,
extract_structure_tree: cmd.extract_structure_tree,
diff --git a/crates/liteparse/src/markdown_layout/repetition.rs b/crates/liteparse/src/markdown_layout/repetition.rs
index fc20e14..7c515ec 100644
--- a/crates/liteparse/src/markdown_layout/repetition.rs
+++ b/crates/liteparse/src/markdown_layout/repetition.rs
@@ -19,6 +19,16 @@ const HEADER_FOOTER_MIN_FRACTION: f32 = 0.5;
/// weak to act on.
const HEADER_FOOTER_MIN_PAGES: usize = 2;
+/// Maximum number of distinct repeated lines a band may contain before the
+/// repetition is treated as a content-bearing letterhead rather than running
+/// chrome. Real running headers/footers are 1–3 short lines (running title,
+/// classification mark, page number); ERP/accounting letterheads repeat an
+/// entire block of labeled fields (`Invoice No`, `Terms`, …) at the top of
+/// every page, and stripping those deletes document data from every page.
+/// Lines matching a chrome pattern (`Page N of M`, URLs, © marks) are exempt
+/// from the cap — they strip regardless of how crowded the band is.
+const MAX_REPEATED_LINES_PER_BAND: usize = 3;
+
/// Normalize a line for cross-page header/footer matching. Lowercases,
/// collapses whitespace, and replaces every run of ASCII digits with `#` so
/// `Page 1 of 6` and `Page 2 of 6` collapse to the same key.
@@ -50,14 +60,28 @@ pub(super) fn normalize_for_repetition(s: &str) -> String {
/// page bottom (footer). Header and footer bands are tracked separately so a
/// company name that appears as both a header and a body-section title on
/// different pages isn't stripped from the body.
+///
+/// Letterhead guard: repetition alone is not a license to delete content. If
+/// a band accumulates more than `MAX_REPEATED_LINES_PER_BAND` distinct
+/// repeated lines that *don't* match a chrome pattern, the block is a
+/// content-bearing letterhead (ERP invoices repeat `Invoice No …` on every
+/// page) and those lines are kept everywhere. Pattern-matched lines still
+/// strip.
pub fn compute_header_footer_set(pages: &[ParsedPage]) -> std::collections::HashSet<String> {
use std::collections::{HashMap, HashSet};
let mut set: HashSet<String> = HashSet::new();
if pages.len() < HEADER_FOOTER_MIN_PAGES {
return set;
}
+ struct KeyStats {
+ pages_seen: std::collections::HashSet<usize>,
+ /// Any occurrence's *original* text matched a chrome signature.
+ /// (Checked pre-normalization — `normalize_for_repetition` folds
+ /// digit runs to `#`, which would defeat the pattern checks.)
+ is_chrome_pattern: bool,
+ }
// Two counters keyed by `(band, normalized_text)` — band is `'h'` or `'f'`.
- let mut counts: HashMap<(char, String), HashSet<usize>> = HashMap::new();
+ let mut counts: HashMap<(char, String), KeyStats> = HashMap::new();
for page in pages {
let header_cutoff = page.page_height * HEADER_BAND_FRACTION;
let footer_cutoff = page.page_height * (1.0 - FOOTER_BAND_FRACTION);
@@ -70,29 +94,46 @@ pub fn compute_header_footer_set(pages: &[ParsedPage]) -> std::collections::Hash
if norm.is_empty() {
continue;
}
- // Header band: top of line within the top band.
- if line.bbox.y <= header_cutoff {
- counts
- .entry(('h', norm.clone()))
- .or_default()
- .insert(page.page_number);
- }
- // Footer band: bottom of line at or below the footer cutoff.
+ let is_pattern = matches_chrome_pattern(text);
let line_bottom = line.bbox.y + line.bbox.height;
- if line_bottom >= footer_cutoff {
- counts
- .entry(('f', norm))
- .or_default()
- .insert(page.page_number);
+ for (band, in_band) in [
+ // Header band: top of line within the top band.
+ ('h', line.bbox.y <= header_cutoff),
+ // Footer band: bottom of line at or below the footer cutoff.
+ ('f', line_bottom >= footer_cutoff),
+ ] {
+ if !in_band {
+ continue;
+ }
+ let stats = counts.entry((band, norm.clone())).or_insert(KeyStats {
+ pages_seen: HashSet::new(),
+ is_chrome_pattern: false,
+ });
+ stats.pages_seen.insert(page.page_number);
+ stats.is_chrome_pattern |= is_pattern;
}
}
}
let threshold = (pages.len() as f32 * HEADER_FOOTER_MIN_FRACTION)
.ceil()
.max(HEADER_FOOTER_MIN_PAGES as f32) as usize;
- for ((_, norm), pages_seen) in counts {
- if pages_seen.len() >= threshold {
- set.insert(norm);
+ // Qualify keys per band, then apply the letterhead guard per band.
+ let mut qualified: HashMap<char, Vec<(String, bool)>> = HashMap::new();
+ for ((band, norm), stats) in counts {
+ if stats.pages_seen.len() >= threshold {
+ qualified
+ .entry(band)
+ .or_default()
+ .push((norm, stats.is_chrome_pattern));
+ }
+ }
+ for keys in qualified.into_values() {
+ let non_pattern = keys.iter().filter(|(_, pat)| !pat).count();
+ let letterhead = non_pattern > MAX_REPEATED_LINES_PER_BAND;
+ for (norm, is_pattern) in keys {
+ if is_pattern || !letterhead {
+ set.insert(norm);
+ }
}
}
set
@@ -440,10 +481,74 @@ mod tests {
assert!(!set.contains("shared body text"));
}
- // ----- single-page chrome detector tests -----
-
use super::super::test_helpers::{line, page};
+ /// Build a page (height 792, header band ≤95pt) whose header band holds
+ /// `header_lines` and whose body holds one unique line per page.
+ fn letterhead_page(n: usize, header_lines: &[&str]) -> ParsedPage {
+ let mut lines: Vec<ProjectedLine> = header_lines
+ .iter()
+ .enumerate()
+ .map(|(i, t)| line(t, 50.0, 10.0 + i as f32 * 12.0, 10.0, 10.0))
+ .collect();
+ lines.push(line(&format!("Body text {n}"), 50.0, 300.0, 10.0, 10.0));
+ let mut p = page(lines);
+ p.page_number = n;
+ p
+ }
+
+ #[test]
+ fn letterhead_block_is_kept_not_stripped() {
+ // Five distinct content-bearing lines repeating in the header band —
+ // an ERP invoice letterhead, not running chrome. None may be stripped.
+ let head = [
+ "ACME SUPPLY CO",
+ "Invoice No ACME-00042",
+ "Invoice Date 2026-07-21",
+ "Terms Net 30",
+ "Please Pay From Invoice And Remit To:",
+ ];
+ let pages = vec![letterhead_page(1, &head), letterhead_page(2, &head)];
+ let set = compute_header_footer_set(&pages);
+ assert!(
+ set.is_empty(),
+ "letterhead lines must survive, got {:?}",
+ set
+ );
+ }
+
+ #[test]
+ fn page_number_still_stripped_inside_letterhead() {
+ // A chrome-pattern line rides along with the letterhead: the guard
+ // exempts it, so it strips while the content lines survive.
+ let head = [
+ "ACME SUPPLY CO",
+ "Invoice No ACME-00042",
+ "Invoice Date 2026-07-21",
+ "Terms Net 30",
+ "Page 1 of 2",
+ ];
+ let pages = vec![letterhead_page(1, &head), letterhead_page(2, &head)];
+ let set = compute_header_footer_set(&pages);
+ assert!(set.contains("page # of #"));
+ assert!(!set.contains("acme supply co"));
+ assert!(!set.contains("terms net #"));
+ }
+
+ #[test]
+ fn small_repeated_header_at_cap_still_strips() {
+ // Exactly MAX_REPEATED_LINES_PER_BAND non-pattern lines — normal
+ // running-header territory, still stripped.
+ let head = ["Acme Corp", "Quarterly Report", "Confidential"];
+ let pages = vec![letterhead_page(1, &head), letterhead_page(2, &head)];
+ let set = compute_header_footer_set(&pages);
+ assert!(set.contains("acme corp"));
+ assert!(set.contains("quarterly report"));
+ assert!(set.contains("confidential"));
+ }
+
+ // ----- single-page chrome detector tests -----
+
#[test]
fn chrome_pattern_recognizes_common_signatures() {
assert!(matches_chrome_pattern("http://example.com/foo"));
diff --git a/crates/liteparse/src/output/markdown.rs b/crates/liteparse/src/output/markdown.rs
index e976cec..8d69805 100644
--- a/crates/liteparse/src/output/markdown.rs
+++ b/crates/liteparse/src/output/markdown.rs
@@ -22,7 +22,7 @@ pub fn format_markdown(
outline: &[OutlineTarget],
image_mode: ImageMode,
) -> String {
- format_markdown_pages(pages, outline, image_mode).join("\n\n-----\n\n")
+ format_markdown_pages(pages, outline, image_mode, false).join("\n\n-----\n\n")
}
/// Render each page to its own markdown string, returning one entry per input
@@ -32,10 +32,15 @@ pub fn format_markdown(
/// (body size, heading map, header/footer set) is still computed across all
/// pages so a single page renders identically whether requested alone or as
/// part of the document.
+///
+/// `keep_headers_footers` disables running-chrome suppression entirely (both
+/// the cross-page repetition set and the single-page chrome detector), so
+/// repeated headers/footers and page markers stay in the output.
pub fn format_markdown_pages(
pages: &[ParsedPage],
outline: &[OutlineTarget],
image_mode: ImageMode,
+ keep_headers_footers: bool,
) -> Vec<String> {
if pages.is_empty() {
return Vec::new();
@@ -43,7 +48,11 @@ pub fn format_markdown_pages(
let body_size = compute_body_size(pages);
let heading_map = build_heading_map(pages, body_size);
- let header_footer = compute_header_footer_set(pages);
+ let header_footer = if keep_headers_footers {
+ Default::default()
+ } else {
+ compute_header_footer_set(pages)
+ };
pages
.iter()
@@ -68,7 +77,11 @@ pub fn format_markdown_pages(
.filter(|e| e.page_index == target_index)
.cloned()
.collect();
- let chrome_indices = detect_single_page_chrome(page, body_size);
+ let chrome_indices = if keep_headers_footers {
+ Default::default()
+ } else {
+ detect_single_page_chrome(page, body_size)
+ };
let mut blocks = classify_page_with_filters(
page,
&heading_map,
@@ -268,7 +281,7 @@ mod tests {
let a = page_with(1, vec![line("A page.", 50.0, 80.0, 10.0, 10.0)]);
let b = page_with(2, vec![line("B page.", 50.0, 80.0, 10.0, 10.0)]);
let pages = [a, b];
- let per_page = format_markdown_pages(&pages, &[], ImageMode::Placeholder);
+ let per_page = format_markdown_pages(&pages, &[], ImageMode::Placeholder, false);
assert_eq!(per_page.len(), 2);
assert!(per_page[0].contains("A page."));
assert!(per_page[1].contains("B page."));
diff --git a/crates/liteparse/src/parser.rs b/crates/liteparse/src/parser.rs
index 4f387ac..486f418 100644
--- a/crates/liteparse/src/parser.rs
+++ b/crates/liteparse/src/parser.rs
@@ -589,8 +589,12 @@ impl LiteParse {
));
let mut full_text = if self.config.output_format == crate::config::OutputFormat::Markdown {
- let page_md =
- markdown::format_markdown_pages(&parsed_pages, &outline, self.config.image_mode);
+ let page_md = markdown::format_markdown_pages(
+ &parsed_pages,
+ &outline,
+ self.config.image_mode,
+ self.config.keep_headers_footers,
+ );
let md = page_md.join("\n\n-----\n\n");
for (page, md) in parsed_pages.iter_mut().zip(page_md) {
page.markdown = md;
@@ -647,8 +651,12 @@ impl LiteParse {
let mut parsed_pages = projection::project_pages_to_grid(pages);
let full_text = if self.config.output_format == crate::config::OutputFormat::Markdown {
- let page_md =
- markdown::format_markdown_pages(&parsed_pages, &outline, self.config.image_mode);
+ let page_md = markdown::format_markdown_pages(
+ &parsed_pages,
+ &outline,
+ self.config.image_mode,
+ self.config.keep_headers_footers,
+ );
let md = page_md.join("\n\n-----\n\n");
for (page, md) in parsed_pages.iter_mut().zip(page_md) {
page.markdown = md;
diff --git a/packages/node/README.md b/packages/node/README.md
index f1972ad..94552cb 100644
--- a/packages/node/README.md
+++ b/packages/node/README.md
@@ -61,6 +61,7 @@ const parser = new LiteParse({
extractImages: true, // Extract image bytes + metadata (default: false)
imageOutputDir: './images', // Write images and return name/path metadata (optional)
extractLinks: true, // Render [text](url) links in markdown output
+ keepHeadersFooters: false, // Keep running headers/footers in markdown output
extractVectorGraphics: false, // Opt-in shapes + merged H/V lines per page
extractAnnotations: false, // Include page annotations in structured output
extractFormFields: false, // Include AcroForm widget fields and values
diff --git a/packages/node/package.json b/packages/node/package.json
index c7e04be..af06b1c 100644
--- a/packages/node/package.json
+++ b/packages/node/package.json
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/liteparse",
- "version": "2.9.0",
+ "version": "2.10.0",
"description": "Fast, lightweight PDF and document parsing with spatial text extraction",
"type": "module",
"main": "./dist/lib.js",
@@ -54,13 +54,13 @@
"typescript": "~5.9.2"
},
"optionalDependencies": {
- "@llamaindex/liteparse-darwin-arm64": "2.9.0",
- "@llamaindex/liteparse-darwin-x64": "2.9.0",
- "@llamaindex/liteparse-linux-arm64-gnu": "2.9.0",
- "@llamaindex/liteparse-linux-x64-gnu": "2.9.0",
- "@llamaindex/liteparse-win32-arm64-msvc": "2.9.0",
- "@llamaindex/liteparse-win32-x64-msvc": "2.9.0",
- "@llamaindex/liteparse-linux-x64-musl": "2.9.0"
+ "@llamaindex/liteparse-darwin-arm64": "2.10.0",
+ "@llamaindex/liteparse-darwin-x64": "2.10.0",
+ "@llamaindex/liteparse-linux-arm64-gnu": "2.10.0",
+ "@llamaindex/liteparse-linux-x64-gnu": "2.10.0",
+ "@llamaindex/liteparse-win32-arm64-msvc": "2.10.0",
+ "@llamaindex/liteparse-win32-x64-msvc": "2.10.0",
+ "@llamaindex/liteparse-linux-x64-musl": "2.10.0"
},
"engines": {
"node": ">=18.0.0"
diff --git a/packages/node/src/cli.ts b/packages/node/src/cli.ts
index b183564..3b2a7e8 100644
--- a/packages/node/src/cli.ts
+++ b/packages/node/src/cli.ts
@@ -65,6 +65,10 @@ program
)
.option("--extract-images", "Extract embedded image bytes and metadata")
.option("--no-links", "Disable hyperlink extraction (emit plain anchor text)")
+ .option(
+ "--keep-headers-footers",
+ "Keep running headers/footers in markdown output instead of stripping them",
+ )
.option("--extract-annotations", "Include all PDF annotations in page output")
.option("--extract-form-fields", "Include AcroForm widget fields and values")
.option("--extract-structure-tree", "Include the tagged-PDF logical structure tree")
@@ -127,6 +131,7 @@ program
config.imageOutputDir = opts.imageOutputDir as string;
if (opts.extractImages) config.extractImages = true;
if (opts.links === false) config.extractLinks = false;
+ if (opts.keepHeadersFooters) config.keepHeadersFooters = true;
if (opts.extractAnnotations) config.extractAnnotations = true;
if (opts.extractFormFields) config.extractFormFields = true;
if (opts.extractStructureTree) config.extractStructureTree = true;
diff --git a/packages/node/src/lib.ts b/packages/node/src/lib.ts
index f28e902..c034f8d 100644
--- a/packages/node/src/lib.ts
+++ b/packages/node/src/lib.ts
@@ -38,6 +38,8 @@ export interface LiteParseConfig {
imageOutputDir?: string;
/** Render hyperlink annotations as `[text](url)` in markdown output (default: true). */
extractLinks: boolean;
+ /** Keep running headers/footers in markdown output instead of stripping repeated page-band lines and page chrome (default: false). */
+ keepHeadersFooters: boolean;
/** Extract all PDF annotations into each parsed page (default: false). */
extractAnnotations: boolean;
/** Extract AcroForm widget fields and values (default: false). */
@@ -486,6 +488,7 @@ export class LiteParse {
extractImages: userConfig.extractImages,
imageOutputDir: userConfig.imageOutputDir,
extractLinks: userConfig.extractLinks,
+ keepHeadersFooters: userConfig.keepHeadersFooters,
extractAnnotations: userConfig.extractAnnotations,
extractFormFields: userConfig.extractFormFields,
extractStructureTree: userConfig.extractStructureTree,
@@ -525,6 +528,7 @@ export class LiteParse {
extractImages: resolved.extractImages ?? false,
imageOutputDir: resolved.imageOutputDir ?? undefined,
extractLinks: resolved.extractLinks ?? true,
+ keepHeadersFooters: resolved.keepHeadersFooters ?? false,
extractAnnotations: resolved.extractAnnotations ?? false,
extractFormFields: resolved.extractFormFields ?? false,
extractStructureTree: resolved.extractStructureTree ?? false,
diff --git a/packages/node/src/native.ts b/packages/node/src/native.ts
index cb4d06f..247ceeb 100644
--- a/packages/node/src/native.ts
+++ b/packages/node/src/native.ts
@@ -33,6 +33,7 @@ export interface LiteParseNativeConfig {
extractImages?: boolean;
imageOutputDir?: string;
extractLinks?: boolean;
+ keepHeadersFooters?: boolean;
extractAnnotations?: boolean;
extractFormFields?: boolean;
extractStructureTree?: boolean;
diff --git a/packages/python/README.md b/packages/python/README.md
index c552ad3..208dec7 100644
--- a/packages/python/README.md
+++ b/packages/python/README.md
@@ -60,6 +60,7 @@ parser = LiteParse(
extract_images=True, # Extract image bytes + metadata (default: False)
image_output_dir="./images", # Write images and return name/path metadata (optional)
extract_links=True, # Render [text](url) links in markdown output
+ keep_headers_footers=False, # Keep running headers/footers in markdown output
extract_vector_graphics=False, # Opt-in shapes + merged H/V lines per page
extract_annotations=False, # Include page annotations in structured output
extract_form_fields=False, # Include AcroForm widget fields and values
diff --git a/packages/python/liteparse/parser.py b/packages/python/liteparse/parser.py
index 3b78f9a..54849d7 100644
--- a/packages/python/liteparse/parser.py
+++ b/packages/python/liteparse/parser.py
@@ -365,6 +365,7 @@ class LiteParse:
extract_images: Optional[bool] = None,
image_output_dir: Optional[Union[str, Path]] = None,
extract_links: Optional[bool] = None,
+ keep_headers_footers: Optional[bool] = None,
extract_annotations: Optional[bool] = None,
extract_form_fields: Optional[bool] = None,
extract_structure_tree: Optional[bool] = None,
@@ -401,6 +402,9 @@ class LiteParse:
num_workers: Number of concurrent OCR workers (default: CPU cores - 1)
extract_links: Render hyperlink annotations as ``[text](url)`` in
markdown output (default: True). Set False for plain anchor text.
+ keep_headers_footers: Keep running headers/footers in markdown
+ output instead of stripping repeated page-band lines and page
+ chrome (default: False).
image_output_dir: Directory where extracted embedded images are
written. Requires ``extract_images=True`` and returns file
names/paths in each ``ExtractedImage``.
@@ -483,6 +487,8 @@ class LiteParse:
kwargs["image_output_dir"] = str(image_output_dir)
if extract_links is not None:
kwargs["extract_links"] = extract_links
+ if keep_headers_footers is not None:
+ kwargs["keep_headers_footers"] = keep_headers_footers
if extract_annotations is not None:
kwargs["extract_annotations"] = extract_annotations
if extract_form_fields is not None:
@@ -660,6 +666,7 @@ class LiteParse:
image_mode=cfg.image_mode,
image_output_dir=cfg.image_output_dir,
extract_links=cfg.extract_links,
+ keep_headers_footers=cfg.keep_headers_footers,
extract_annotations=cfg.extract_annotations,
extract_form_fields=cfg.extract_form_fields,
extract_structure_tree=cfg.extract_structure_tree,
diff --git a/packages/python/liteparse/types.py b/packages/python/liteparse/types.py
index 247e8e1..9074e3a 100644
--- a/packages/python/liteparse/types.py
+++ b/packages/python/liteparse/types.py
@@ -348,6 +348,9 @@ class LiteParseConfig:
skip_diagonal_text: bool
include_complexity: bool
extract_text_metadata: bool = False
+ #: Keep running headers/footers in markdown output instead of stripping
+ #: repeated page-band lines and page chrome.
+ keep_headers_footers: bool = False
extract_images: bool = False
extract_vector_graphics: bool = False
extract_xfa_packets: bool = False
diff --git a/packages/python/pyproject.toml b/packages/python/pyproject.toml
index f29ff12..6315730 100644
--- a/packages/python/pyproject.toml
+++ b/packages/python/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "maturin"
[project]
name = "liteparse"
-version = "2.9.0"
+version = "2.10.0"
description = "Python bindings for LiteParse - fast, lightweight PDF and document parsing"
readme = "README.md"
license = "Apache-2.0"
diff --git a/packages/wasm/package.json b/packages/wasm/package.json
index 60f232b..5dd32fe 100644
--- a/packages/wasm/package.json
+++ b/packages/wasm/package.json
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/liteparse-wasm",
- "version": "2.9.0",
+ "version": "2.10.0",
"description": "Fast, lightweight PDF parsing with spatial text extraction — WebAssembly build for browsers",
"type": "module",
"main": "./pkg/liteparse_wasm.js",