The Rust file of the “The embedded ICC profile” example.
The ICC profile the library embeds in a PDF/A file.
Rust
35 lines
What this example is for
This entry is a download, not a page to look at. A file meant for archiving is obliged to carry a colour profile describing the device its colours are meant for, and the usual answer is to ship somebody else's: a hundred kilobytes or more, with a licence attached, copied into every document you ever produce.
What this example shows
A complete sRGB profile built by the library, not shipped with it.
The profile every PDF/A file gets when none is named.
A download rather than a page: inspect it with specialist software. The library alone writes it, and no request to the server hands it back.
//! Writes the ICC profile the library embeds in a PDF/A file.//!//! Our own tests can only say the bytes look right to us. Whether they are an//! ICC profile — and whether that profile is really sRGB rather than something//! wearing its name — is a question for a colour engine, which is what//! `scripts/check_icc_profile.py` uses this for.//!//! Usage: `cargo run --example write_icc -- tmp/srgb.icc`usestd::env;usestd::fs;usestd::path::Path;#[path = "shared/failure.rs"]modfailure;fnmain()->std::process::ExitCode{failure::reported(run())}fnrun()->Result<(),Box<dynstd::error::Error>>{letout=env::args().nth(1).unwrap_or_else(||"tmp/srgb.icc".to_owned());letprofile=hqf_pdf::color::icc::srgb();ifletSome(parent)=Path::new(&out).parent(){fs::create_dir_all(parent)?;}fs::write(&out,&profile)?;println!("wrote {out}: {} bytes",profile.len());Ok(())}