2023-11-15 00:24:04 +01:00
import { PdfFile , RepresentationType } from "../wrappers/PdfFile" ;
2023-11-14 03:26:42 +03:00
export type ImposeParamsType = {
2023-11-15 00:24:04 +01:00
file : PdfFile ;
2023-11-17 20:38:45 +01:00
/** Accepted values are 2, 3, 4, 8, 9, 12, 16 - see: {@link https://pdfcpu.io/generate/nup.html#n-up-value} */
2023-11-14 03:26:42 +03:00
nup : number ;
2023-11-17 20:38:45 +01:00
/** A0-A10, other formats available - see: {@link https://pdfcpu.io/paper.html} */
2023-11-14 03:26:42 +03:00
format : string ;
}
2023-11-17 20:38:45 +01:00
/** 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} */
export async function impose ( params : ImposeParamsType , pdfcpuWrapper : any ) : Promise < PdfFile > {
// https://pdfcpu.io/generate/nup.html
const uint8Array = await pdfcpuWrapper . oneToOne (
2023-11-16 02:24:10 +03:00
[
2023-10-18 23:56:56 +02:00
"pdfcpu.wasm" ,
"nup" ,
"-c" ,
"disable" ,
2023-11-14 03:26:42 +03:00
'f:' + params . format ,
2023-10-18 23:56:56 +02:00
"/output.pdf" ,
2023-11-14 03:26:42 +03:00
String ( params . nup ) ,
2023-10-18 23:56:56 +02:00
"input.pdf" ,
2023-11-16 02:24:10 +03:00
] ,
await params . file . uint8Array
) ;
const result = new PdfFile (
params . file . originalFilename ,
uint8Array ,
RepresentationType . Uint8Array ,
params . file . filename + "_imposed"
) ;
2023-11-15 00:24:04 +01:00
console . log ( "ImposeResult: " , result ) ;
return result ;
2023-10-18 01:20:31 +02:00
}