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) {
|
2023-10-22 00:55:28 +02:00
|
|
|
// Load the original PDF file
|
2023-10-26 22:41:48 +02:00
|
|
|
const pdfDoc = await PDFDocument.load(snapshot, {
|
|
|
|
parseSpeed: ParseSpeeds.Fastest,
|
2023-10-22 00:55:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const pages = pdfDoc.getPages();
|
|
|
|
|
|
|
|
pages.forEach(page => {
|
|
|
|
// Change page size
|
2023-10-26 22:41:48 +02:00
|
|
|
page.setRotation(degrees(rotation))
|
2023-10-22 00:55:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Serialize the modified document
|
|
|
|
return pdfDoc.save();
|
|
|
|
};
|