Extract Text from PDF using Rust
Contents
[
Hide
]
Extract Text From PDF Document
Extracting text from the PDF document is a very common and useful task. PDFs often contain critical information that needs to be accessed, analyzed, or processed for various purposes. Extracting text enables easier reuse in databases, reports, or other documents.
Extracting text makes PDF content searchable, allowing users to locate specific information quickly without manually reviewing the entire document.
In case you want to extract text from PDF document, you can use extract_text function. Please check following code snippet in order to extract text from PDF file using Rust via C++.
- Open a PDF document with the given filename.
- extract_text extracts the text content from the PDF document.
- Print the extracted text to the console.
use asposepdf::Document;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Open a PDF-document with filename
let pdf = Document::open("sample.pdf")?;
// Return the PDF-document contents as plain text
let txt = pdf.extract_text()?;
// Print extracted text
println!("Extracted text:\n{}", txt);
Ok(())
}