Added remove pages
This commit is contained in:
21
shared-operations/src/functions/removePages.ts
Normal file
21
shared-operations/src/functions/removePages.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user