Add Pages to PDF Document
Contents
[
Hide
]
Add Page in a PDF File
The provided Rust code snippet demonstrates how to perform the Add Page at the end of the PDF operation using the Aspose.PDF library.
- The open function allows the program to load an existing PDF file (sample.pdf) for manipulation. This is essential for any PDF-related operations, such as editing, adding content, or reading data.
- The page_add method is used to insert a new blank page into the existing PDF document. This is useful for extending a document or preparing it for additional content.
- The save method ensures that modifications to the PDF are written back to the file. This step is crucial for persisting the changes, such as the addition of new pages.
This snippet is a concise and efficient example of how to use the Aspose.PDF Rust library for basic PDF manipulation tasks.
Aspose.PDF for Rust lets you insert a page to a PDF document at any location in the file as well as add pages to the end of a PDF file.
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(())
}
Insert Page in a PDF File
The page_insert method inserts a new page at the specified position. This feature is useful when you need to insert additional pages into an existing document, for example, adding a new section or content to a report or presentation.
use asposepdf::Document;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Open a PDF-document from file
let pdf = Document::open("sample.pdf")?;
// Insert new page at the specified position in PDF-document
pdf.page_insert(1)?;
// Save the previously opened PDF-document
pdf.save()?;
Ok(())
}