Stirling-PDF/shared-operations/functions/rotatePages.js
2023-11-07 01:40:00 +01:00

16 lines
438 B
JavaScript

export async function rotatePages (snapshot, rotation, PDFLib) {
// Load the original PDF file
const pdfDoc = await PDFLib.PDFDocument.load(snapshot, {
parseSpeed: PDFLib.ParseSpeeds.Fastest,
});
const pages = pdfDoc.getPages();
pages.forEach(page => {
// Change page size
page.setRotation(PDFLib.degrees(rotation))
});
// Serialize the modified document
return pdfDoc.save();
};