Expand description
Add an invisible, searchable text layer to a PDF.
Give the writer a PDF and the OCR boxes for its pages. Each box is drawn at its location in text render mode 3, so the page looks the same and becomes selectable and searchable.
- Pages without drawable boxes are left as they are.
- A box that lands on a word the page already contains is skipped, so a page that mixes native text and a scan is not indexed twice.
- Boxes are given in the upright view of the page. Pages with a
/Rotateentry and boxes with their own rotation are placed along the text direction.
use pdf_textlayer::{Options, ParsedPage, TextBox, write_text_layer};
let pages = vec![ParsedPage {
page_number: 1,
boxes: vec![TextBox::new("Hello world", 72.0, 100.0, 120.0, 12.0)],
}];
let stats = write_text_layer("scan.pdf", &pages, "searchable.pdf", &Options::default())?;
assert_eq!(stats.items_drawn, 1);OCR JSON from a supported tool goes through an Adapter:
use pdf_textlayer::{Adapter, Options, make_searchable_pdf};
let stats = make_searchable_pdf("scan.pdf", "parsed.json", "searchable.pdf", Adapter::Liteparse, &Options::default())?;Re-exports§
pub use adapters::Adapter;
Modules§
- adapters
- Turn an OCR tool’s JSON into
ParsedPages. - cli
- The
pdf-textlayercommand line.
Structs§
- Options
- Drawing options.
- Parsed
Page - The OCR boxes of one page.
- Stats
- What a pass wrote.
- TextBox
- One piece of OCR text to draw, in PDF points.
Enums§
- Error
- Font
Metrics - Which width table sizes the text.
Functions§
- add_
text_ layer - Draw a text layer onto a PDF held in memory and return the new PDF.
- make_
searchable_ pdf - Read the OCR JSON at
sourcewithadapter, draw its boxes onto the PDF atinput, and save the result tooutput. - write_
text_ layer - Draw a text layer onto the PDF at
inputand save it tooutput.