mirror of
				https://github.com/Frooodle/Stirling-PDF.git
				synced 2025-11-01 01:21:18 +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
 | 
					//Auto Split Pages
 | 
				
			||||||
//Adjust Colours/Contrast
 | 
					//Adjust Colours/Contrast
 | 
				
			||||||
//Crop
 | 
					//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
 | 
					//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 {
 | 
					export interface ExtractAction extends Action {
 | 
				
			||||||
    values: { indecies: string | number[] }
 | 
					    values: { indexes: string | number[] }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface ImposeAction extends Action {
 | 
					export interface ImposeAction extends Action {
 | 
				
			||||||
 | 
				
			|||||||
@ -5,19 +5,19 @@ import { parsePageIndexSpecification } from './common/pageIndexesUtils'
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export type ExtractPagesParamsType = {
 | 
					export type ExtractPagesParamsType = {
 | 
				
			||||||
    file: PdfFile;
 | 
					    file: PdfFile;
 | 
				
			||||||
    pageIndecies: string | number[];
 | 
					    pageIndexes: string | number[];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
export async function extractPages(params: ExtractPagesParamsType): Promise<PdfFile> {
 | 
					export async function extractPages(params: ExtractPagesParamsType): Promise<PdfFile> {
 | 
				
			||||||
    const { file, pageIndecies: pageIndecies } = params;
 | 
					    const { file, pageIndexes } = params;
 | 
				
			||||||
    const pdfLibDocument = await file.pdfLibDocument;
 | 
					    const pdfLibDocument = await file.pdfLibDocument;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var indecies = pageIndecies;
 | 
					    var indexes = pageIndexes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!Array.isArray(indecies)) {
 | 
					    if (!Array.isArray(indexes)) {
 | 
				
			||||||
        indecies = parsePageIndexSpecification(indecies, pdfLibDocument.getPageCount());
 | 
					        indexes = parsePageIndexSpecification(indexes, pdfLibDocument.getPageCount());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const newFile = await getPages(file, indecies);
 | 
					    const newFile = await getPages(file, indexes);
 | 
				
			||||||
    newFile.filename += "_extractedPages"
 | 
					    newFile.filename += "_extractedPages"
 | 
				
			||||||
    return newFile;
 | 
					    return newFile;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -54,7 +54,7 @@ export async function * traverseOperations(operations: Action[], input: PdfFile[
 | 
				
			|||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case "extract":
 | 
					            case "extract":
 | 
				
			||||||
                yield* nToN(input, action, async (input) => {
 | 
					                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;
 | 
					                    return newPdf;
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user