So this particular script is assigned to a "dummy" template. And it should download remote pdf and replace the template output with it?
In this case, you should do everything in the afterRender and set
res.content with the buffer.
You are doing now some magic with
req.data.pdfData.pages. Not sure what it is.
Based on the error this dummy template is about to be prepended into the main one.
The script is evaluated.
However, it crashes in the handlebars.
How is your template additionally configured?
It would save time if you prepare for us a simple demo in the playground.