Stirling-PDF/public/functions/rotatePDF.js

18 lines
466 B
JavaScript
Raw Normal View History

2023-10-17 03:40:54 +02:00
const { PDFDocument, ParseSpeeds, degrees } = PDFLib;
export const rotatePages = async (snapshot, rotation) => {
// Load the original PDF file
const pdfDoc = await PDFDocument.load(snapshot, {
parseSpeed: ParseSpeeds.Fastest,
});
const pages = pdfDoc.getPages();
pages.forEach(page => {
// Change page size
page.setRotation(degrees(rotation))
});
// Serialize the modified document
return pdfDoc.save();
};