23 lines
844 B
TypeScript
Raw Normal View History

import { PdfFile } from '../wrappers/PdfFile.js';
import { detectEmptyPages } from './common/detectEmptyPages.js';
import { getPages } from './common/getPagesByIndex.js';
2023-11-17 13:15:20 +03:00
import { invertSelection } from './common/pageIndexesUtils.js';
export type RemoveBlankPagesParamsType = {
file: PdfFile;
whiteThreashold: number;
}
export async function removeBlankPages(params: RemoveBlankPagesParamsType) {
const { file, whiteThreashold } = params;
2023-11-18 19:56:23 +03:00
const pdfDoc = await file.pdfLibDocument;
const pageCount = pdfDoc.getPageCount();
const emptyPages = await detectEmptyPages(file, whiteThreashold);
console.debug("Empty Pages: ", emptyPages);
2023-11-18 19:56:23 +03:00
const pagesToKeep = invertSelection(emptyPages, pageCount)
2023-11-17 00:45:37 +03:00
const newFile = await getPages(file, pagesToKeep);
newFile.filename += "_removedBlanks"
return newFile;
}