mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-23 16:05:09 +00:00
26 lines
816 B
TypeScript
26 lines
816 B
TypeScript
![]() |
|
||
|
import { PdfFile } from '../wrappers/PdfFile.js';
|
||
|
import { parsePageIndexSpecification } from './common/pageIndexesUtils'
|
||
|
import { splitPagesByIndex } from './common/splitPagesByIndex.js';
|
||
|
|
||
|
export type SplitPagesParamsType = {
|
||
|
file: PdfFile;
|
||
|
pageIndexes: string | number[];
|
||
|
}
|
||
|
export async function splitPdfByIndex(params: SplitPagesParamsType): Promise<PdfFile[]> {
|
||
|
const { file, pageIndexes } = params;
|
||
|
const pdfLibDocument = await file.pdfLibDocument;
|
||
|
|
||
|
var indexes = pageIndexes;
|
||
|
|
||
|
if (!Array.isArray(indexes)) {
|
||
|
indexes = parsePageIndexSpecification(indexes, pdfLibDocument.getPageCount());
|
||
|
}
|
||
|
|
||
|
const newFiles = await splitPagesByIndex(file, indexes);
|
||
|
for (let i = 0; i < newFiles.length; i++) {
|
||
|
newFiles[i].filename += "_split-"+i;
|
||
|
}
|
||
|
return newFiles;
|
||
|
}
|