pdfcpu & wasm update, server side functions init, README.md, CONTRIBUTE.md

This commit is contained in:
Felix Kaspar
2023-10-18 23:56:56 +02:00
parent 21e0385a31
commit c60de02e14
16 changed files with 360 additions and 32 deletions

29
functions/scaleContent.js Normal file
View File

@@ -0,0 +1,29 @@
import { PDFDocument, ParseSpeeds } from 'pdf-lib'
export const scaleContent = async (snapshot, scale_factor) => {
// Load the original PDF file
const pdfDoc = await PDFDocument.load(snapshot, {
parseSpeed: ParseSpeeds.Fastest,
});
const pages = pdfDoc.getPages();
pages.forEach(page => {
const width = page.getWidth();
const height = page.getHeight();
// Scale content
page.scaleContent(scale_factor, scale_factor);
const scaled_diff = {
width: Math.round(width - scale_factor * width),
height: Math.round(height - scale_factor * 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();
};