PDF Processing API for Rust

Generate, modify, secure, and convert PDF documents to various formats seamlessly within Rust applications

Overview

Aspose.PDF is a PDF document generation library for Rust that makes creating complex, multi-page, printable documents easy.

API is designed to be simple, so generating complex documents has been as simple as a few function calls. As the name suggests, the library is developed based on program code in C++. This allowed us to make it as fast as possible and also made it portable to different operating systems.

Aspose.PDF for Rust via C++ features

How to Manipulate PDF Files on the Backend with Aspose.PDF for Rust via C++

Aspose.PDF for Rust via C++ enables backend manipulation of PDF files. With Aspose.PDF for Rust via C++, you can optimize PDF files, fix corrupted PDFs, add or extract text, and convert PDFs to popular formats.

Extract text from PDF

  • Using Aspose.PDF for Rust via C++ you can extract text from PDF with formatting or as a raw data.

Convert document from PDF to other formats

The library allows to store PDF as

  • Microsoft Office documents (DOCX/DOC, XLSX, PPTX),
  • Images in BMP, PNG, JPEG, TIFF and SVG formats,
  • Various documents (XPS, EPUB, TeX/LaTex).

Organize PDF

Aspose.PDF for Rust via C++ allows you to perform the following document organization functions:

  • Optimize PDF-document content,
  • Convert PDF document using grey shades,
  • Rotate whole pages in PDF document,
  • Set PDF document background color,
  • Repair PDF-document.

Page manipulation

Aspose.PDF for Rust via C++ allows you to

  • Add new pages
  • Remove pages.

Convert PDF to JPG and Other Image Formats

Aspose.PDF for Rust via C++ allows you to render and transform each page of a PDF file into conventional image formats such as BMP, JPG, and PNG with the highest possible fidelity. In addition to images, PDF files can easily be saved to DOC and DOCX formats.

Save PDF pages as JPEG images in Rust

Load an existing PDF document. Convert PDF pages to images and save each page in JPG format.

Convert PDF to JPG using Rust

use asposepdf::Document;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Open a PDF document specified by the filename 'sample.pdf'
    let pdf = match Document::open("sample.pdf") {
        Ok(doc) => doc,
        Err(e) => {
            eprintln!("Failed to open the PDF file: {}", e);
            return Err(Box::new(e));
        }
    };
    // Return page count in PDF-document
    let count = pdf.page_count()?;
    if count > 0 {
        for i in 1..=count {
            // Convert and save the specified page as Jpg-image
            pdf.page_to_jpg(i, 100, &format!("sample_page{}.jpg", i))?;
        }
    } else {
        println!("The PDF is empty, no pages to process.");
    }
    Ok(())
}

Support and Learning Resources