mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2024-12-21 19:08:24 +01:00
97e4eab7bb
Split express into different ports for easier migration Typed page ops that had warnings
18 lines
658 B
TypeScript
18 lines
658 B
TypeScript
import { PDFDocument } from 'pdf-lib';
|
|
import { detectEmptyPages } from "./common/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();
|
|
}; |