Rotate PDF Pages with Rust via C++

Contents
[ ]

This section describes how to change the page orientation from landscape to portrait and vice versa in an existing PDF file using Rust.

Rotating pages ensures proper alignment for printing or displaying PDFs in professional settings

  1. Open the PDF Document.
  2. Rotate PDF Pages. The rotate function applies a specific rotation (in this case, 180 degrees) to a given page.
  3. Save Changes to a New File. The save_as function creates a new PDF file to preserve the original while storing the updated version.

In this example, you rotate a specific page in a PDF document:


    use asposepdf::{Document, Rotation};

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

        // Rotate PDF-document
        pdf.rotate(Rotation::On270)?;

        // Save the previously opened PDF-document with new filename
        pdf.save_as("sample_rotate.pdf")?;

        Ok(())
    }