Set page rotation to 90, 180, or 270 degrees. Rotate a single page, a range, or the whole document in a few lines of Rust.
use pdfluent::{PdfDocument, Rotation};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut doc = PdfDocument::open("scan.pdf")?;
// Rotate all pages 90 degrees clockwise
for i in 0..doc.page_count() {
doc.page_mut(i)?.set_rotation(Rotation::Clockwise90);
}
doc.save("scan_rotated.pdf")?;
Ok(())
}Add the pdfluent crate to Cargo.toml.
[dependencies]
pdfluent = "0.9"Load the file you want to rotate.
use pdfluent::PdfDocument;
let mut doc = PdfDocument::open("scanned_contract.pdf")?;Get a mutable reference to the page and call set_rotation(). The Rotation enum has variants for 0, 90, 180, and 270 degrees.
use pdfluent::Rotation;
// Rotate page 3 (index 2) 90 degrees clockwise
doc.page_mut(2)?.set_rotation(Rotation::Clockwise90);
// Rotate page 4 upside-down
doc.page_mut(3)?.set_rotation(Rotation::Degrees180);Loop over a range of page indices to rotate a contiguous section.
// Rotate pages 5 through 8 (indices 4-7)
for i in 4..8 {
doc.page_mut(i)?.set_rotation(Rotation::CounterClockwise90);
}Iterate over all pages and apply the same rotation, then write the output.
let count = doc.page_count();
for i in 0..count {
doc.page_mut(i)?.set_rotation(Rotation::Clockwise90);
}
doc.save("document_rotated.pdf")?;
println!("Rotated {} pages", count);No JVM, no runtime, no DLL dependencies. Ships as a single native binary or WASM module.
Rust's ownership model prevents buffer overflows and use-after-free. No segfaults in PDF parsing.
Same code runs server-side, in Docker, on AWS Lambda, on Cloudflare Workers, or in the browser via WASM.