mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2024-12-31 00:08:08 +01:00
Appended operation names to filenames
This commit is contained in:
parent
544a080db4
commit
fa36d5d296
@ -6,7 +6,7 @@ export type ExtractPagesParamsType = {
|
||||
file: PdfFile;
|
||||
pageIndexes: string | number[];
|
||||
}
|
||||
export async function extractPages(params: ExtractPagesParamsType) {
|
||||
export async function extractPages(params: ExtractPagesParamsType): Promise<PdfFile> {
|
||||
const { file, pageIndexes } = params;
|
||||
const pdfLibDocument = await file.pdfLibDocument;
|
||||
|
||||
@ -16,5 +16,7 @@ export async function extractPages(params: ExtractPagesParamsType) {
|
||||
indexes = parsePageIndexSpecification(indexes, pdfLibDocument.getPageCount());
|
||||
}
|
||||
|
||||
return getPages(file, indexes);
|
||||
const newFile = await getPages(file, indexes);
|
||||
newFile.filename += "_extractedPages"
|
||||
return newFile;
|
||||
}
|
||||
|
@ -14,5 +14,8 @@ export async function removeBlankPages(params: RemoveBlankPagesParamsType) {
|
||||
const emptyPages = await detectEmptyPages(file, whiteThreashold);
|
||||
console.debug("Empty Pages: ", emptyPages);
|
||||
const pagesToKeep = invertSelection(emptyPages, pageCount.getPageCount())
|
||||
return getPages(file, pagesToKeep);
|
||||
|
||||
const newFile = await getPages(file, pagesToKeep);
|
||||
newFile.filename += "_removedBlanks"
|
||||
return newFile;
|
||||
}
|
@ -18,5 +18,8 @@ export async function sortPagesWithPreset(params: SortPagesWithPresetParamsType)
|
||||
const sortFunction = sorts[sortPreset];
|
||||
const pageCount = pdfLibDocument.getPageCount();
|
||||
const sortIndexes = sortFunction(pageCount);
|
||||
return getPages(file, sortIndexes);
|
||||
|
||||
const newFile = await getPages(file, sortIndexes);
|
||||
newFile.filename += "_sortedPages"
|
||||
return newFile;
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ export async function * traverseOperations(operations: Action[], input: PdfFile[
|
||||
case "extract":
|
||||
yield* nToN(input, action, async (input) => {
|
||||
const newPdf = await Operations.extractPages({file: input, pageIndexes: action.values["pageIndexes"]});
|
||||
newPdf.filename += "_extractedPages";
|
||||
return newPdf;
|
||||
});
|
||||
break;
|
||||
@ -71,12 +70,24 @@ export async function * traverseOperations(operations: Action[], input: PdfFile[
|
||||
return newPdf;
|
||||
});
|
||||
break;
|
||||
case "removeBlankPages":
|
||||
yield* nToN(input, action, async (input) => {
|
||||
const newPdf = await Operations.removeBlankPages({file: input, whiteThreashold: action.values["whiteThreashold"]});
|
||||
return newPdf;
|
||||
});
|
||||
break;
|
||||
case "rotate":
|
||||
yield* nToN(input, action, async (input) => {
|
||||
const newPdf = await Operations.rotatePages({file: input, rotation: action.values["rotation"]});
|
||||
return newPdf;
|
||||
});
|
||||
break;
|
||||
case "sortPagesWithPreset":
|
||||
yield* nToN(input, action, async (input) => {
|
||||
const newPdf = await Operations.sortPagesWithPreset({file: input, sortPreset: action.values["sortPreset"]});
|
||||
return newPdf;
|
||||
});
|
||||
break;
|
||||
case "split":
|
||||
// TODO: A split might break the done condition, it may count multiple times. Needs further testing!
|
||||
yield* oneToN(input, action, async (input) => {
|
||||
@ -87,27 +98,6 @@ export async function * traverseOperations(operations: Action[], input: PdfFile[
|
||||
return splitResult;
|
||||
});
|
||||
break;
|
||||
case "updateMetadata":
|
||||
yield* nToN(input, action, async (input) => {
|
||||
const newPdf = await Operations.updateMetadata({file: input, ...action.values["metadata"]});
|
||||
newPdf.filename += "_metadataEdited";
|
||||
return newPdf;
|
||||
});
|
||||
break;
|
||||
case "sortPagesWithPreset":
|
||||
yield* nToN(input, action, async (input) => {
|
||||
const newPdf = await Operations.sortPagesWithPreset({file: input, sortPreset: action.values["sortPreset"]});
|
||||
newPdf.filename += "_pagesOrganized";
|
||||
return newPdf;
|
||||
});
|
||||
break;
|
||||
case "removeBlankPages":
|
||||
yield* nToN(input, action, async (input) => {
|
||||
const newPdf = await Operations.removeBlankPages({file: input, whiteThreashold: action.values["whiteThreashold"]});
|
||||
newPdf.filename += "_removedBlanks";
|
||||
return newPdf;
|
||||
});
|
||||
break;
|
||||
case "splitOn":
|
||||
yield* oneToN(input, action, async (input) => {
|
||||
const splitResult = await Operations.splitOn({file: input, type: action.values["type"], whiteThreashold: action.values["whiteThreashold"]});
|
||||
@ -117,9 +107,14 @@ export async function * traverseOperations(operations: Action[], input: PdfFile[
|
||||
return splitResult;
|
||||
});
|
||||
break;
|
||||
case "updateMetadata":
|
||||
yield* nToN(input, action, async (input) => {
|
||||
const newPdf = await Operations.updateMetadata({file: input, ...action.values["metadata"]});
|
||||
return newPdf;
|
||||
});
|
||||
break;
|
||||
default:
|
||||
throw new Error(`${action.type} not implemented yet.`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user