Add Pages to PDF using Rust

Insert pages to PDF document programmatically using Aspose.PDF for Rust via C++ Library

How to Add pages to PDF using Rust

Do you need to add pages to PDF documents? To add pages, we’ll use Aspose.PDF for Rust via C++, which is an easy and secure toolkit used to work with PDF. To install and use Aspose.PDF for Rust via C++, click on Download Aspose.PDF for Rust.

Insert Page to PDF using Rust


You need Aspose.PDF for Rust via C++ 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.

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