2017-09-21 17 views
0

このMeteorサーバーコードは、電子メールに添付するためにpdfを作成しようとします。それは、PDFがOKするが、BLOBにそれをputing場合、このエラーを返し:ストリームからブロブを取得する

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 
    }); 
    }, 
+0

'から来metaData'ん、以下言いましたか? –

答えて

1

としてDocumentationあたり、stream.toBlob()、すなわちapplication/textapplication/pdfをブロブのための出力の種類を期待しています。

あなたは

stream.on('finish', function() { 
//get a blob you can do whatever you like with 
blob = stream.toBlob('application/pdf'); 
return blob; 
}); 

が親切にドキュメントを通過、コードのpeice下回ってみてくださいすることができます。それはから

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 the end 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(); 
+0

私はまだ同じエラーが発生しています。私は行を 'let blob = stream.toBlob( 'application/pdf');に変更しました。 –

+1

質問内でスタックトレースを生成できますか?みんなが何が間違っているのを見ることができるように? –

+0

私の答えをより詳細に更新しました。ドキュメントから適切なガイドラインに従う必要があります。 'doc.pipe'コードを再確認する必要があります。詳細は上記を参照してください。 –

関連する問題