Rust Requires Chilkat v11.7.0+
Rust
Clipped, Off-Page and White-on-White Text in PDF Extraction
See more PDF Text Extraction Examples
Demonstrates the "clippedText", "offPageText" and "obscuredText" filters. Text that a reader never sees - hidden by a clipping path, outside the crop box, or drawn in the same color as the box beneath it - is excluded by default, and the quality report notes what was skipped. Each kind can be included.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The PDF used in this example is available at hidden_text.pdf
let pdf = chilkat::Pdf::new();
if pdf.load_file("qa_data/pdf/hidden_text.pdf").is_err() {
println!("{}", pdf.last_error_text());
return;
}
let json = chilkat::JsonObject::new();
let json_out = chilkat::JsonObject::new();
// The page has a visible paragraph plus three hidden lines: one drawn outside its clipping
// rectangle, one below the crop box, and one in white on a white box.
if pdf.extract_text("text", &json, &json_out).is_err() {
println!("{}", pdf.last_error_text());
return;
}
println!("---- default ----");
println!("{}", json_out.string_of("text").unwrap_or_default());
// The quality report says what was left out.
let mut i = 0;
let count_i = json_out.size_of_array("quality.pages[0].issues");
while i < count_i {
json_out.set_i(i);
println!("issue: {}", json_out.string_of("quality.pages[0].issues[i].code").unwrap_or_default());
i = i + 1;
}
// Include everything.
let _ = json.update_string("clippedText", "include");
let _ = json.update_string("offPageText", "include");
let _ = json.update_string("obscuredText", "include");
if pdf.extract_text("text", &json, &json_out).is_err() {
println!("{}", pdf.last_error_text());
return;
}
println!("---- clippedText, offPageText, obscuredText: include ----");
println!("{}", json_out.string_of("text").unwrap_or_default());
// Sample output:
// ---- default ----
// Visible Text
//
// This paragraph is visible. The page also carries three kinds of text a reader never sees.
//
// End of the visible text.
// issue: obscuredTextSkipped
// issue: clippedTextSkipped
// ---- clippedText, offPageText, obscuredText: include ----
// Visible Text
//
// This paragraph is visible. The page also carries three kinds of text a reader never sees.
//
// CLIPPED: this line is drawn outside its clipping rectangle.
//
// OBSCURED: this line is white on a white box.
//
// End of the visible text.
//
// OFFPAGE: this line sits below the crop box.