This Meteor server code tries to create a pdf in order to attach it to an email. It make the pdf Ok but when puting it into a blob, it returns this error:
TypeError: Blob is not a function
"use strict";
let PDFDocument = require('pdfkit');
let blobStream = require('blob-stream');
'make': function () {
let doc = new PDFDocument(metaData); // readable Node streams
let stream = doc.pipe(blobStream());
doc.fontSize('14')
.text('some text')
.end();
stream.on('finish', function (blob) {
return stream.toBlob(blob); //<=== error line
});
},
This Meteor server code tries to create a pdf in order to attach it to an email. It make the pdf Ok but when puting it into a blob, it returns this error:
TypeError: Blob is not a function
"use strict";
let PDFDocument = require('pdfkit');
let blobStream = require('blob-stream');
'make': function () {
let doc = new PDFDocument(metaData); // readable Node streams
let stream = doc.pipe(blobStream());
doc.fontSize('14')
.text('some text')
.end();
stream.on('finish', function (blob) {
return stream.toBlob(blob); //<=== error line
});
},
Share
Improve this question
asked Sep 21, 2017 at 2:02
Fred J.Fred J.
6,04913 gold badges60 silver badges113 bronze badges
1
-
from where does
metaData
e from? – Ankur Soni Commented Sep 21, 2017 at 2:28
1 Answer
Reset to default 3As per Documentation , stream.toBlob()
is expecting type of output for blob, i.e. application/text
, application/pdf
.
Can you please try below peice of code,
stream.on('finish', function () {
//get a blob you can do whatever you like with
blob = stream.toBlob('application/pdf');
return blob;
});
Kindly go through the Documentation. It says below,
PDFDocument instances are readable Node streams. They don't get saved anywhere automatically, but you can call the
pipe
method to send the output of the PDF document to another writable Node stream as it is being written. When you're done with your document, call theend
method to finalize it. Here is an example showing how to pipe to a file or an HTTP response.
doc.pipe fs.createWriteStream('/path/to/file.pdf') # write to PDF
doc.pipe res # HTTP response
# add stuff to PDF here using methods described below...
# finalize the PDF and end the stream
doc.end();