Skip to content

Commit d37af54

Browse files
committed
fix Cargo.toml and add example
1 parent ad4ab03 commit d37af54

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "pdf_text"
33
version = "0.1.0"
44
edition = "2021"
5-
authors = ["Sebastian Köln <[email protected]>"]"
5+
authors = ["Sebastian Köln <[email protected]>"]
66
keywords = ["pdf", "text", "extract"]
77
license = "MIT"
88
description = "PDF text extraction"

examples/text.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use itertools::Itertools;
2+
use pdf::file::FileOptions;
3+
4+
fn main() {
5+
let input = std::env::args_os().nth(1).expect("no file given");
6+
let file = FileOptions::cached().open(&input).expect("can't read PDF");
7+
8+
for (page_nr, page) in file.pages().enumerate() {
9+
let page = page.expect("can't read page");
10+
let flow = pdf_text::run(&file, &page).expect("can't render page");
11+
println!("# page {}", page_nr + 1);
12+
for run in flow.runs {
13+
for line in run.lines {
14+
println!("{}", line.words.iter().map(|w| &w.text).format(" "));
15+
}
16+
println!();
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)