Get Permissions using Rust
Contents
[
Hide
]
Get permissions of a password-protected PDF document
This section explains how to read and display the access permissions of a password-protected PDF document in Rust. The PDF is opened with the owner password, which grants full access to the document’s security settings. The currently assigned permissions are then retrieved and printed to the console.
- Open the protected PDF document.
- Call get_permissions to obtain the permission flags that define which operations are allowed.
- Print the retrieved permissions to the console.
use asposepdf::{Document, Permissions};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Open a password-protected PDF-document
let pdf = Document::open_with_password("sample_with_permissions.pdf", "ownerpass")?;
// Get current permissions of PDF-document
let permissions: Permissions = pdf.get_permissions()?;
// Print permissions
println!("Permissions: {}", permissions);
Ok(())
}