2023-10-22 00:55:28 +02:00
|
|
|
export async function scalePage(snapshot, pageSize, PDFLib) {
|
2023-10-16 23:11:33 +02:00
|
|
|
// Load the original PDF file
|
2023-10-22 00:55:28 +02:00
|
|
|
const pdfDoc = await PDFLib.PDFDocument.load(snapshot, {
|
|
|
|
parseSpeed: PDFLib.ParseSpeeds.Fastest,
|
2023-10-16 23:11:33 +02:00
|
|
|
});
|
|
|
|
|
2023-10-22 00:55:28 +02:00
|
|
|
const new_size = pageSize;
|
2023-10-16 23:11:33 +02:00
|
|
|
|
|
|
|
const pages = pdfDoc.getPages();
|
|
|
|
|
|
|
|
pages.forEach(page => {
|
|
|
|
// Change page size
|
|
|
|
page.setSize(new_size.width, new_size.height);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Serialize the modified document
|
|
|
|
return pdfDoc.save();
|
|
|
|
};
|
|
|
|
|
|
|
|
export const PageSize = {
|
|
|
|
a4: {
|
|
|
|
width: 594.96,
|
|
|
|
height: 841.92
|
|
|
|
},
|
|
|
|
letter: {
|
|
|
|
width: 612,
|
|
|
|
height: 792
|
|
|
|
}
|
|
|
|
};
|