mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2024-12-21 19:08:24 +01:00
added endpoint: extract-pages. changed indecies to indexes
This commit is contained in:
parent
facf1553ec
commit
a7545b017f
@ -90,7 +90,12 @@ registerEndpoint("/scale-pages", "", upload.single("file"), Operations.scalePage
|
||||
//Auto Split Pages
|
||||
//Adjust Colours/Contrast
|
||||
//Crop
|
||||
//Extract Pages
|
||||
|
||||
registerEndpoint("/extract-pages", "", upload.single("file"), Operations.extractPages, Joi.object({
|
||||
file: PdfFileSchema.required(),
|
||||
pageIndexes: Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.number())).required(),
|
||||
}).required());
|
||||
|
||||
//PDF to Single large Page
|
||||
|
||||
|
||||
|
2
shared-operations/declarations/Action.d.ts
vendored
2
shared-operations/declarations/Action.d.ts
vendored
@ -9,7 +9,7 @@ export interface WaitAction extends Action {
|
||||
}
|
||||
|
||||
export interface ExtractAction extends Action {
|
||||
values: { indecies: string | number[] }
|
||||
values: { indexes: string | number[] }
|
||||
}
|
||||
|
||||
export interface ImposeAction extends Action {
|
||||
|
@ -5,19 +5,19 @@ import { parsePageIndexSpecification } from './common/pageIndexesUtils'
|
||||
|
||||
export type ExtractPagesParamsType = {
|
||||
file: PdfFile;
|
||||
pageIndecies: string | number[];
|
||||
pageIndexes: string | number[];
|
||||
}
|
||||
export async function extractPages(params: ExtractPagesParamsType): Promise<PdfFile> {
|
||||
const { file, pageIndecies: pageIndecies } = params;
|
||||
const { file, pageIndexes } = params;
|
||||
const pdfLibDocument = await file.pdfLibDocument;
|
||||
|
||||
var indecies = pageIndecies;
|
||||
var indexes = pageIndexes;
|
||||
|
||||
if (!Array.isArray(indecies)) {
|
||||
indecies = parsePageIndexSpecification(indecies, pdfLibDocument.getPageCount());
|
||||
if (!Array.isArray(indexes)) {
|
||||
indexes = parsePageIndexSpecification(indexes, pdfLibDocument.getPageCount());
|
||||
}
|
||||
|
||||
const newFile = await getPages(file, indecies);
|
||||
const newFile = await getPages(file, indexes);
|
||||
newFile.filename += "_extractedPages"
|
||||
return newFile;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ export async function * traverseOperations(operations: Action[], input: PdfFile[
|
||||
break;
|
||||
case "extract":
|
||||
yield* nToN(input, action, async (input) => {
|
||||
const newPdf = await Operations.extractPages({file: input, pageIndecies: action.values["pageIndecies"]});
|
||||
const newPdf = await Operations.extractPages({file: input, pageIndexes: action.values["pageIndexes"]});
|
||||
return newPdf;
|
||||
});
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user