2017-09-21 3 views
0

이 Meteor 서버 코드는 전자 메일에 첨부하기 위해 pdf를 만들려고합니다. 그것은 PDF를 확인하게하지만 방울로 퍼 팅하는 경우,이 오류를 반환스트림에서 블롭 가져 오기

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

으로 Documentationstream.toBlob(), 즉 application/text, application/pdf를 BLOB에 대한 출력의 유형을 기대하고있다.

당신은
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' 코드를 다시 확인해야합니다. 더 많은 것을 위해 위에 참조하십시오. –

관련 문제