mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2024-12-31 00:08:08 +01:00
Cleanup, Documented Impose
This commit is contained in:
parent
432342415e
commit
8a63ebe6cf
@ -7,8 +7,7 @@ import { PdfFile } from "@stirling-pdf/shared-operations/src/wrappers/PdfFile"
|
|||||||
import * as pdfcpuWrapper from "@stirling-pdf/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-browser.js";
|
import * as pdfcpuWrapper from "@stirling-pdf/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-browser.js";
|
||||||
|
|
||||||
async function impose(params: ImposeParamsType): Promise<PdfFile> {
|
async function impose(params: ImposeParamsType): Promise<PdfFile> {
|
||||||
const paramsToUse = { ...params, pdfcpuWrapper: pdfcpuWrapper };
|
return SharedOperations.impose(params, pdfcpuWrapper);
|
||||||
return SharedOperations.impose(paramsToUse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const toExport: OperationsType = {
|
const toExport: OperationsType = {
|
||||||
|
@ -7,8 +7,7 @@ import { PdfFile } from "@stirling-pdf/shared-operations/src/wrappers/PdfFile"
|
|||||||
import * as pdfcpuWrapper from "@stirling-pdf/shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper-node.js";
|
import * as pdfcpuWrapper from "@stirling-pdf/shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper-node.js";
|
||||||
|
|
||||||
async function impose(params: ImposeParamsType): Promise<PdfFile> {
|
async function impose(params: ImposeParamsType): Promise<PdfFile> {
|
||||||
const paramsToUse = { ...params, pdfcpuWrapper: pdfcpuWrapper };
|
return SharedOperations.impose(params, pdfcpuWrapper);
|
||||||
return SharedOperations.impose(paramsToUse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const toExport: OperationsType = {
|
const toExport: OperationsType = {
|
||||||
|
12
shared-operations/declarations/Action.d.ts
vendored
12
shared-operations/declarations/Action.d.ts
vendored
@ -7,3 +7,15 @@ export interface Action {
|
|||||||
export interface WaitAction extends Action {
|
export interface WaitAction extends Action {
|
||||||
values: { id: number }
|
values: { id: number }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ExtractAction extends Action {
|
||||||
|
values: { indecies: string | number[] }
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ImposeAction extends Action {
|
||||||
|
values: { nup: number, format: string }
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WaitAction extends Action {
|
||||||
|
values: { id: number }
|
||||||
|
}
|
@ -5,19 +5,19 @@ import { parsePageIndexSpecification } from './common/pageIndexesUtils'
|
|||||||
|
|
||||||
export type ExtractPagesParamsType = {
|
export type ExtractPagesParamsType = {
|
||||||
file: PdfFile;
|
file: PdfFile;
|
||||||
pageIndexes: string | number[];
|
pageIndecies: string | number[];
|
||||||
}
|
}
|
||||||
export async function extractPages(params: ExtractPagesParamsType): Promise<PdfFile> {
|
export async function extractPages(params: ExtractPagesParamsType): Promise<PdfFile> {
|
||||||
const { file, pageIndexes } = params;
|
const { file, pageIndecies: pageIndecies } = params;
|
||||||
const pdfLibDocument = await file.pdfLibDocument;
|
const pdfLibDocument = await file.pdfLibDocument;
|
||||||
|
|
||||||
var indexes = pageIndexes;
|
var indecies = pageIndecies;
|
||||||
|
|
||||||
if (!Array.isArray(indexes)) {
|
if (!Array.isArray(indecies)) {
|
||||||
indexes = parsePageIndexSpecification(indexes, pdfLibDocument.getPageCount());
|
indecies = parsePageIndexSpecification(indecies, pdfLibDocument.getPageCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
const newFile = await getPages(file, indexes);
|
const newFile = await getPages(file, indecies);
|
||||||
newFile.filename += "_extractedPages"
|
newFile.filename += "_extractedPages"
|
||||||
return newFile;
|
return newFile;
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,16 @@ import { PdfFile, RepresentationType } from "../wrappers/PdfFile";
|
|||||||
|
|
||||||
export type ImposeParamsType = {
|
export type ImposeParamsType = {
|
||||||
file: PdfFile;
|
file: PdfFile;
|
||||||
|
/** Accepted values are 2, 3, 4, 8, 9, 12, 16 - see: {@link https://pdfcpu.io/generate/nup.html#n-up-value} */
|
||||||
nup: number;
|
nup: number;
|
||||||
|
/** A0-A10, other formats available - see: {@link https://pdfcpu.io/paper.html} */
|
||||||
format: string;
|
format: string;
|
||||||
}
|
}
|
||||||
export type ImposeParamsBaseType = {
|
|
||||||
file: PdfFile;
|
/** PDF-Imposition, PDF-N-Up: Put multiple pages of the input document into a single page of the output document. - see: {@link https://en.wikipedia.org/wiki/N-up} */
|
||||||
nup: number;
|
export async function impose(params: ImposeParamsType, pdfcpuWrapper: any): Promise<PdfFile> {
|
||||||
format: string;
|
// https://pdfcpu.io/generate/nup.html
|
||||||
pdfcpuWrapper: any;
|
const uint8Array = await pdfcpuWrapper.oneToOne(
|
||||||
}
|
|
||||||
export async function impose(params: ImposeParamsBaseType): Promise<PdfFile> {
|
|
||||||
const uint8Array = await params.pdfcpuWrapper.oneToOne(
|
|
||||||
[
|
[
|
||||||
"pdfcpu.wasm",
|
"pdfcpu.wasm",
|
||||||
"nup",
|
"nup",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import { arrangePages, ArrangePagesParamsType } from './functions/arrangePages'
|
import { arrangePages, ArrangePagesParamsType } from './functions/arrangePages'
|
||||||
import { extractPages, ExtractPagesParamsType } from "./functions/extractPages";
|
import { extractPages, ExtractPagesParamsType } from "./functions/extractPages";
|
||||||
import { impose, ImposeParamsBaseType, ImposeParamsType } from "./functions/impose";
|
import { impose, ImposeParamsType } from "./functions/impose";
|
||||||
import { mergePDFs, MergeParamsType } from './functions/mergePDFs';
|
import { mergePDFs, MergeParamsType } from './functions/mergePDFs';
|
||||||
import { removeBlankPages, RemoveBlankPagesParamsType } from "./functions/removeBlankPages";
|
import { removeBlankPages, RemoveBlankPagesParamsType } from "./functions/removeBlankPages";
|
||||||
import { rotatePages, RotateParamsType } from './functions/rotatePages';
|
import { rotatePages, RotateParamsType } from './functions/rotatePages';
|
||||||
@ -34,7 +34,7 @@ export default toExport;
|
|||||||
export type OperationsParametersBaseType = {
|
export type OperationsParametersBaseType = {
|
||||||
arrangePages: ArrangePagesParamsType
|
arrangePages: ArrangePagesParamsType
|
||||||
extractPages: ExtractPagesParamsType;
|
extractPages: ExtractPagesParamsType;
|
||||||
impose: ImposeParamsBaseType;
|
impose: ImposeParamsType;
|
||||||
mergePDFs: MergeParamsType;
|
mergePDFs: MergeParamsType;
|
||||||
removeBlankPages: RemoveBlankPagesParamsType;
|
removeBlankPages: RemoveBlankPagesParamsType;
|
||||||
rotatePages: RotateParamsType;
|
rotatePages: RotateParamsType;
|
||||||
|
@ -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, pageIndexes: action.values["pageIndexes"]});
|
const newPdf = await Operations.extractPages({file: input, pageIndecies: action.values["pageIndecies"]});
|
||||||
return newPdf;
|
return newPdf;
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user