Added remove pages

This commit is contained in:
Saud Fatayerji
2023-11-18 19:56:45 +03:00
parent c060b2a4e0
commit 9bca4848f3
3 changed files with 29 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
import { PdfFile } from '../wrappers/PdfFile.js';
import { getPages } from './common/getPagesByIndex.js';
import { invertSelection, parsePageIndexSpecification } from './common/pageIndexesUtils.js';
export type RemovePagesParamsType = {
file: PdfFile;
pageSelector: string;
}
export async function removePages(params: RemovePagesParamsType) {
const { file, pageSelector } = params;
const pdfDoc = await file.pdfLibDocument;
const pageCount = pdfDoc.getPageCount();
const pageSelection = parsePageIndexSpecification(pageSelector, pageCount);
const pagesToKeep = invertSelection(pageSelection, pageCount);
const newFile = await getPages(file, pagesToKeep);
newFile.filename += "_removedPages"
return newFile;
}