Set the background color for PDF with Rust via C++
Contents
[
Hide
]
- The provided code snippet demonstrates how to set a background color for a PDF file using the Aspose.PDF library in Rust.
- The open method loads the specified PDF file into memory, allowing further manipulations, such as modifying its appearance or content.
- The set_background method applies a new background color to the PDF document. The RGB values allow users to customize the document’s visual style.
- The save_as method saves the updated PDF under a new name.
This code is ideal for applications that need to automate PDF customizations, such as creating branded reports, adding watermarks, or enhancing visual consistency across multiple documents.
use asposepdf::Document;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Open a PDF-document with filename
let pdf = Document::open("sample.pdf")?;
// Set PDF-document background color using RGB values
pdf.set_background(200, 100, 101)?;
// Save the previously opened PDF-document with new filename
pdf.save_as("sample_set_background.pdf")?;
Ok(())
}