Quickstart
Turn a scanned PDF into a searchable one in three steps — run OCR with LiteParse, install pdf-textlayer, and write the text layer.
You need a PDF and OCR results for it. This guide uses LiteParse, whose JSON pdf-textlayer reads out of the box. Boxes from any other OCR engine work too; see Adapters.
Run OCR
LiteParse OCRs the pages that need it and writes JSON with a box for every word. --extract-text-metadata adds each word’s rotation.
lit parse scan.pdf --format json --extract-text-metadata -o parsed.jsonInstall pdf-textlayer
Install whichever package fits your project. Each one includes the pdf-textlayer command.
pip install pdf-textlayernpm install pdf-textlayercargo install pdf-textlayerWrite the text layer
Run the command, or call the library from your code.
pdf-textlayer scan.pdf parsed.json searchable.pdffrom pdf_textlayer import make_searchable_pdf
stats = make_searchable_pdf("scan.pdf", "parsed.json", "searchable.pdf")
print(stats) # {'pages': 1, 'ocr_pages': [1], 'items_drawn': 15}import { makeSearchablePdf } from "pdf-textlayer";
const stats = await makeSearchablePdf("scan.pdf", "parsed.json", "searchable.pdf");
console.log(stats); // { pages: 1, ocrPages: [ 1 ], itemsDrawn: 15 }use pdf_textlayer::{Adapter, Options, make_searchable_pdf};
let stats = make_searchable_pdf("scan.pdf", "parsed.json", "searchable.pdf", Adapter::Liteparse, &Options::default())?;
println!("{stats:?}");Open searchable.pdf. It looks the same as scan.pdf, and search now finds its words.