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

19 lines
462 B
JavaScript
Raw Normal View History

2023-10-26 20:53:02 +02:00
import PDFLib from 'pdf-lib';
export async function rotatePages (snapshot, rotation) {
// 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();
};