Rust Requires Chilkat v11.7.0+
Rust
Tile a Watermark Across a PDF Page
See more PDF Watermark Examples
Demonstrates a tiled watermark, which repeats the stamp over the whole page instead of placing it once. Tiling overrides position.align; tile.spacingX and spacingY set the gaps, and tile.stagger offsets alternate rows by half a tile so the pattern does not line up in columns. A faint tiled stamp carrying the name or address is the usual way to mark a document so that a leaked copy can be traced back, and zOrder back keeps it behind the text where it does not hinder reading.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 long_report.pdf
let pdf = chilkat::Pdf::new();
if pdf.load_file("qa_data/pdf/long_report.pdf").is_err() {
println!("{}", pdf.last_error_text());
return;
}
let json = chilkat::JsonObject::new();
let _ = json.update_string("type", "text");
// {date:FORMAT} is replaced per page when the watermark is added. The other placeholders are
// {page}, {pages} and {filename}; {{ gives a literal brace.
let _ = json.update_string("text", "jdoe@example.com {date:yyyy-MM-dd}");
let _ = json.update_string("id", "trace");
let _ = json.update_string("zOrder", "back");
let _ = json.update_number("font.size", "14");
let _ = json.update_number("opacity", "0.15");
let _ = json.update_number("rotation", "30");
let _ = json.update_bool("tile.enabled", true);
let _ = json.update_number("tile.spacingX", "60");
let _ = json.update_number("tile.spacingY", "80");
let _ = json.update_bool("tile.stagger", true);
let json_out = chilkat::JsonObject::new();
if pdf.watermark("add", &json, &json_out).is_err() {
println!("{}", pdf.last_error_text());
return;
}
println!("id: {} pages: {}", json_out.string_of("id").unwrap_or_default(), json_out.string_of("pages").unwrap_or_default());
if pdf.write_file("qa_output/report_traced.pdf").is_err() {
println!("{}", pdf.last_error_text());
return;
}
// Sample output:
// id: trace pages: 1-3