restructured project (shared-operations)

This commit is contained in:
Felix Kaspar
2023-11-07 01:40:00 +01:00
parent 7186c6c3e0
commit 47e0092378
36 changed files with 36 additions and 23 deletions

View File

@@ -0,0 +1,27 @@
export async function scaleContent(snapshot, scaleFactor, PDFLib) {
// Load the original PDF file
const pdfDoc = await PDFLib.PDFDocument.load(snapshot, {
parseSpeed: PDFLib.ParseSpeeds.Fastest,
});
const pages = pdfDoc.getPages();
pages.forEach(page => {
const width = page.getWidth();
const height = page.getHeight();
// Scale content
page.scaleContent(scaleFactor, scaleFactor);
const scaled_diff = {
width: Math.round(width - scaleFactor * width),
height: Math.round(height - scaleFactor * height),
};
// Center content in new page format
page.translateContent(Math.round(scaled_diff.width / 2), Math.round(scaled_diff.height / 2));
});
// Serialize the modified document
return pdfDoc.save();
};