Work with Pages in PDF using Rust

Manage PDF pages in document programmaticaly using Aspose.PDF for Rust via C++ Library

Aspose.PDF for Rust via C++ Logo

Most popular action with Pages in Rust

How to Insert pages to PDF Document using Rust

In order to add page in PDF file, we’ll use Aspose.PDF API which is a feature-rich, powerful and easy to use document manipulation API for rust-cpp platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Add Page to PDF using Rust


You need Aspose.PDF library to try the code in your environment.

  1. Create a Document object with the input PDF file.

  2. Call the PageCollection collection’s Insert method with specified index.

  3. Save the output PDF using the Save method.

Add New Page to PDF

use asposepdf::Document;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Open a PDF-document from file
    let pdf = Document::open("sample.pdf")?;

    // Add new page in PDF-document
    pdf.page_add()?;

    // Save the previously opened PDF-document
    pdf.save()?;

    Ok(())
}