Open PDF document programmatically
Contents
[
Hide
]
Open existing PDF document
The code snippet demonstrates essential operations for working with PDFs using Aspose.PDF for Rust. These are opening a file, saving changes, and properly closing resources. This makes it a foundational example for developers handling PDF documents.
The example is straightforward, making it easy to understand and modify. It’s ideal for beginners or as a boilerplate for more complex applications.
The ability to open and save PDF documents is a core requirement in many scenarios, such as generating reports, modifying documents, or creating automated workflows.
This example showcases the API’s ease of use for simple PDF manipulation, which can be expanded to include advanced features like text extraction, annotation, or form filling.
use asposepdf::Document;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Open a PDF-document named "sample.pdf"
let pdf = Document::open("sample.pdf")?;
// Save the previously opened PDF-document with new filename
pdf.save_as("sample_open.pdf")?;
Ok(())
}