Sample code for 30+ languages & platforms
Rust

PDF File Encoding to Base64

See more Base64 Examples

Demonstrates how to encode a PDF file to base64, and then decode.

Chilkat Rust Downloads

Rust

let pdf_data = chilkat::BinData::new();

if pdf_data.load_file("qa_data/helloWorld.pdf").is_err() {
    println!("failed to load PDF file.");
    return;
}

// Encode the PDF to base64
// Note: to produce base64 on multiple lines (as it would appear in the MIME of an email),
// pass the string "base64_mime" instead of "base64".
let b64 = pdf_data.get_encoded("base64").unwrap_or_default();
println!("{}", b64);

// Decode from base64 PDF.
let pdf_data2 = chilkat::BinData::new();
let _ = pdf_data2.append_encoded(&b64, "base64");
if pdf_data2.write_file("qa_output/helloWorld2.pdf").is_err() {
    println!("failed to write PDF file.");
    return;
}