Rotate Pages Utility
The rotatePages function allows you to rotate all pages or specific page indices by 90, 180, or 270 degrees.
API Signature
function rotatePages(
file: File | Blob | ArrayBuffer | Uint8Array,
degreesToRotate: 90 | 180 | 270,
specificPages?: number[]
): Promise<Uint8Array>
Parameters
file: The input PDF file or buffer.degreesToRotate: Angle of rotation. Must be90,180, or270.specificPages: Optional array of 0-indexed page numbers to rotate. If not provided, all pages will be rotated.
Code Example
import { rotatePages } from "@manojcoder/pdf-utils";
async function rotateFirstPage(file: File) {
try {
// Rotates page 1 (index 0) by 90 degrees clockwise
const rotatedBytes = await rotatePages(file, 90, [0]);
const blob = new Blob([rotatedBytes], { type: "application/pdf" });
// Process rotated document...
} catch (error) {
console.error("Rotation operation failed:", error);
}
}
Orientation Alignment: The rotation angle is cumulative and is added to the page's current rotation value.