Migrating shared-operations to TS (WIP)

This commit is contained in:
Saud Fatayerji
2023-11-08 03:33:22 +03:00
parent 0a43660e55
commit 0f35c77074
19 changed files with 622 additions and 230 deletions

View File

@@ -0,0 +1,18 @@
import { PDFDocument } from 'pdf-lib';
import { detectEmptyPages } from "./detectEmptyPages.js";
export async function removeBlankPages(snapshot, whiteThreashold) {
const emptyPages = await detectEmptyPages(snapshot, whiteThreashold);
console.log("Empty Pages: ", emptyPages);
const pdfDoc = await PDFDocument.load(snapshot);
// Reverse the array before looping in order to keep the indecies at the right pages. E.g. if you delete page 5 page 7 becomes page 6, if you delete page 7 page 5 remains page 5
emptyPages.reverse().forEach(pageIndex => {
pdfDoc.removePage(pageIndex);
})
return pdfDoc.save();
};