pdfkit and blobStream not producing url

Hi

I’m having real problems with getting this npm package working, anyone managed to succeed yet?
My ultimate aim is to display a pdf with data from a collection, so that my users may print/save to local disc.
From my simple code below I’m not even able to generate a url. As you can see I’ve a number of console logs to help with debugging and it appears that the line " const url = stream . toBlobURL ( ‘application/pdf’ ) " is the issue as with this line in, neither of the last 2 logs are generated.
Code is below, which is in a backend .jsw file.

++++++++++++++++++++++++++++++++++++++++++++
import PDFDocument from ‘pdfkit’ ;
import fs from ‘graceful-fs’ ;
import blobStream from ‘blob-stream’

$w.onReady(function () {

});
*/

export function pdfcreate () {
console . log ( “Into backend pdf create” )
// Create a document
const doc = new PDFDocument ();

// Pipe its output somewhere, like to a file or HTTP response
// See below for browser usage
// doc.pipe (fs.createWriteStream(output.pdf’));
const stream = doc . pipe ( blobStream ())

// Embed a font, set the font size, and render some text
doc
// .font(‘fonts/PalatinoBold.ttf’)
. fontSize ( 25 )
. text ( ‘Some text with an embedded font!’ , 100 , 100 );

// Add an image, constrain it to a given size, and center it vertically and horizontally
/** doc.image (‘path/to /image.png’, {
fit: [250, 300],
align: ‘center’,
valign: ‘center’
});
*/
// Add another page
doc
. addPage ()
. fontSize ( 25 )
. text ( ‘Here is some vector graphics…’ , 100 , 100 );

// Finalize PDF file
doc . end ();
console . log ( “File output.pdf should have been created somewhere” );
stream . on ( ‘finish’ , function () {
const url = stream . toBlobURL ( ‘application/pdf’ )

console . log ( "log 1 url is " , url )
})
console . log ( "log 2 outside of stream.on url is " , url )

return
}
++++++++++++++++++++++++++++++++++++++++++++

Any help would be appreciated

Regards

Chris