mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-22 23:45:02 +00:00
24 lines
741 B
TypeScript
24 lines
741 B
TypeScript
|
|
import { PdfFile } from "../wrappers/PdfFile.js";
|
|
import { getPages } from "./common/getPagesByIndex.js";
|
|
import { parsePageIndexSpecification } from "./common/pageIndexesUtils";
|
|
|
|
export interface ExtractPagesParamsType {
|
|
file: PdfFile;
|
|
pageIndexes: string | number[];
|
|
}
|
|
export async function extractPages(params: ExtractPagesParamsType): Promise<PdfFile> {
|
|
const { file, pageIndexes } = params;
|
|
const pdfLibDocument = await file.pdfLibDocument;
|
|
|
|
let indexes = pageIndexes;
|
|
|
|
if (!Array.isArray(indexes)) {
|
|
indexes = parsePageIndexSpecification(indexes, pdfLibDocument.getPageCount());
|
|
}
|
|
|
|
const newFile = await getPages(file, indexes);
|
|
newFile.filename += "_extractedPages";
|
|
return newFile;
|
|
}
|