Compress PDF using Rust

PDF compression programmatically using Aspose.PDF for Rust via C++

Optimize PDF with Rust

Do you need to compress the PDF? Programmatic modification of PDF documents is a crucial component of modern digital workflows. Rust libraries, such as Aspose.PDF, are stand-alone solutions that don’t rely on other software and are ready for commercial use. To compress PDF files, we’ll use Aspose.PDF for Rust via C++, which is an easy and secure toolkit for working with PDFs. To install and use Aspose.PDF for Rust via C++, click on the Download button.

How to Compress PDF using Rust


You need Aspose.PDF for Rust via C++ to try the code in your environment.

  1. Open a PDF document using Document object.
  2. Call the method for optimization on the document object, which removes unnecessary objects and compresses images in the PDF file
  3. Save the optimized document to the new path using the Save() method.

If you want to make it easier and faster to share or store a PDF file, compressing it can help. With this powerful Aspose.PDF Rust via C++ library, you can reduce the size of your PDF while keeping its quality and important details intact. This professional tool uses Rust to compress PDF effectively. The following example demonstrates how to modify a PDF document in Rust:

Compress PDF Files - Rust

This sample code shows how to Optimize PDF Document for the Web - Rust

Input file:

File not added

Output format:

PDF

Output 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(())
}

About Aspose.PDF for Rust via C++ API

Aspose.PDF for Rust via C++ is a powerful toolkit that enables developers to manipulate PDF files directly and perform various tasks on PDFs. It features unique capabilities for converting PDFs to other formats.

You can find more information about Aspose.PDF for Rust via C++ API on Documentation and examples on how to use the tool.