Sample code for 30+ languages & platforms
Rust

Sign PDF with Invisible Signature

See more PDF Signatures Examples

Demonstrates how to sign a PDF with an invisible signature.

Note: This example requires Chilkat v9.5.0.85 or greater.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let pdf = chilkat::Pdf::new();

// Load a PDF to be signed.
// The "hello.pdf" is available at https://chilkatsoft.com/hello.pdf
if pdf.load_file("qa_data/pdf/hello.pdf").is_err() {
    println!("{}", pdf.last_error_text());
    return;
}

// Options for signing are specified in JSON.
let json = chilkat::JsonObject::new();

// In most cases, the signingCertificateV2 and signingTime attributes are required.
let _ = json.update_int("signingCertificateV2", 1);
let _ = json.update_int("signingTime", 1);

// Indicate that the signature will be invisible.
let _ = json.update_bool("invisibleSignature", true);

// Load the signing certificate. (Use your own certificate.)
let cert = chilkat::Cert::new();
if cert.load_pfx_file("qa_data/pfx/myPdfSigningCert.pfx", "secret").is_err() {
    println!("{}", cert.last_error_text());
    return;
}

// Tell the pdf object to use the certificate for signing.
if pdf.set_signing_cert(&cert).is_err() {
    println!("{}", pdf.last_error_text());
    return;
}

if pdf.sign_pdf(&json, "qa_output/hello_signed.pdf").is_err() {
    println!("{}", pdf.last_error_text());
    return;
}

println!("PDF successfully signed with an invisible signature.");

// An invisible signature has no appearance within the PDF document itself,
// but Adobe Acrobat will indicate the document is signed in a toolbar, as shown here:
// (image:https://example-code.com/images/invisible_signature.jpg/endImage)