Stirling-PDF/shared-operations/functions/rotatePages.js

19 lines
471 B
JavaScript
Raw Normal View History

2023-10-26 20:53:02 +02:00
2023-10-26 22:41:48 +02:00
import { PDFDocument, ParseSpeeds, degrees } from 'pdf-lib';
2023-10-26 20:53:02 +02:00
2023-10-26 22:41:48 +02:00
export async function rotatePages(snapshot, rotation) {
// Load the original PDF file
2023-10-26 22:41:48 +02:00
const pdfDoc = await PDFDocument.load(snapshot, {
parseSpeed: ParseSpeeds.Fastest,
});
const pages = pdfDoc.getPages();
pages.forEach(page => {
// Change page size
2023-10-26 22:41:48 +02:00
page.setRotation(degrees(rotation))
});
// Serialize the modified document
return pdfDoc.save();
};