Optimize PDF using Aspose.PDF for Rust via C++
Contents
[
Hide
]
Optimize PDF Document
Toolkit with Aspose.PDF for Rust via C++ allows you to optimize a PDF document.
This snippet is useful for applications where reducing the size or enhancing the efficiency of PDF files is critical, such as for web uploads, archiving, or sharing over limited bandwidth.
- The open method loads the specified PDF file (sample.pdf) into memory.
- The optimize reduces the file size by performing optimizations like removing unused objects, compressing images, flattening annotations, unembedding fonts, and enabling content reuse. These steps help reduce storage requirements and improve processing speed for the PDF document.
- The save_as method saves the optimized PDF to a new file.
use asposepdf::Document;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Open a PDF-document with filename
let pdf = Document::open("sample.pdf")?;
// Optimize PDF-document content
pdf.optimize()?;
// Save the previously opened PDF-document with new filename
pdf.save_as("sample_optimize.pdf")?;
Ok(())
}