The loadWithGlobalPool function is established to load and evaluate script from a script object with a pool to store the script context.
var runscript=`
var pdfDataUri;
for(var i=0;i<10;i++){
var pdfDoc=await(PDFLib.PDFDocument.create());
var page = pdfDoc.addPage([350, 400]);
page.moveTo(110, 200);
page.drawText(msg);
pdfDataUri=await(pdfDoc.saveAsBase64({ dataUri: true }));
}
pdfDataUri;
`;
var pdfDataUri=loadWithGlobalPool({
name:"pdf-lib",
max:3,
initializer:"load(_eventfolder+'/pdf-lib.min.js');",
script:runscript,
context:{msg:"Hello World!"},
engine:"nashorn",
returnVar:"pdfDataUri"
});
return new Result().eval("$('"+params.pdf+"')[0].src='" +pdfDataUri +"'");
Parameters | Type | Description |
---|---|---|
name | String | The name of the pool. |
max | Number | The max size of the pool. |
initializer | String | Script string executed by the pool when initializing the script context. |
script | String | Script string executed by the pool on call. |
context | Object | The attributes of the context parameter will be set into the global of the script context. |
engine | String | The name of the engines in the pool.Only "nashorn" or "javet". |
returnVar | String | The var name to get the return value. |