Set the background color for PDF with Rust via C++

Contents
[ ]
  1. The provided code snippet demonstrates how to set a background color for a PDF file using the Aspose.PDF library in Rust.
  2. The open method loads the specified PDF file into memory, allowing further manipulations, such as modifying its appearance or content.
  3. 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.
  4. 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(())
  }