24 lines
758 B
TypeScript
Raw Normal View History

import { PdfFile } from '../wrappers/PdfFile.js';
import { getPages } from './common/getPagesByIndex.js';
2023-11-17 13:15:20 +03:00
import { parsePageIndexSpecification } from './common/pageIndexesUtils'
export type ExtractPagesParamsType = {
file: PdfFile;
2023-11-17 20:38:45 +01:00
pageIndecies: string | number[];
}
2023-11-17 00:45:37 +03:00
export async function extractPages(params: ExtractPagesParamsType): Promise<PdfFile> {
2023-11-17 20:38:45 +01:00
const { file, pageIndecies: pageIndecies } = params;
const pdfLibDocument = await file.pdfLibDocument;
2023-11-17 20:38:45 +01:00
var indecies = pageIndecies;
2023-11-17 20:38:45 +01:00
if (!Array.isArray(indecies)) {
indecies = parsePageIndexSpecification(indecies, pdfLibDocument.getPageCount());
}
2023-11-17 20:38:45 +01:00
const newFile = await getPages(file, indecies);
2023-11-17 00:45:37 +03:00
newFile.filename += "_extractedPages"
return newFile;
}