mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-12-30 20:06:30 +01:00
24 lines
974 B
TypeScript
24 lines
974 B
TypeScript
import { PdfFile } from "../wrappers/PdfFile";
|
|
import { Operator, Progress, oneToOne } from ".";
|
|
import { getPages } from "./common/getPagesByIndex";
|
|
|
|
import { invertSelection } from "./common/pageIndexesUtils";
|
|
|
|
export class RemovePages extends Operator {
|
|
/** PDF extraction, specify pages from one pdf and output them to a new pdf */
|
|
async run(input: PdfFile[], progressCallback: (state: Progress) => void): Promise<PdfFile[]> {
|
|
return oneToOne<PdfFile, PdfFile>(input, async (input, index, max) => {
|
|
|
|
const pdfDoc = await input.pdfLibDocument;
|
|
const pageCount = pdfDoc.getPageCount();
|
|
|
|
const pagesToKeep = invertSelection(this.actionValues.pageIndexes, pageCount);
|
|
|
|
const newFile = await getPages(input, pagesToKeep);
|
|
newFile.filename += "_removedPages";
|
|
progressCallback({ curFileProgress: 1, operationProgress: index/max });
|
|
|
|
return newFile;
|
|
});
|
|
}
|
|
} |