admin管理员组文章数量:1307765
I am using PDFKit and NodeJS to dynamically generate PDF documents, and I would like to attach said document to an email. At this moment I'm using Mandril-API via NPM.
I can generate the PDF without issue and display it in the browser via:
doc.pipe( res );
I can send an email without issue, but I have failed miserably at getting the proper PDF content. I am fairly certain that I am 99% of the way there - but I'm missing something. I have done a ton of reading and testing using Google/StackOverflow etc but I'm stuck.
I am getting content that when I do a base64 decode I get:
%PDF-1.3 % 7 0 obj << /Predictor 15
I have managed to get my PDF attachment to have a valid size of 445KB but this is the content of the email:
--_av-Ti-H6i8tBBHL4BgoXnyC2Q Content-Type: application/pdf Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="mytestPDF.pdf"
PDF1370obj/Predictor15/Colors1/BitsPerComponent8/Columns100e ndobj60obj/Type/XObject/Subtype/Image/BitsPerComponent8/Widt h100/Height19/Filter/FlateDecode/DecodeParms70R/ColorSpace/I ndexed/DeviceRGB25580R/Length1751streamxdSSNEhGIRTRkWbY/nHaO MJln7t+vv89ylF111PlYNB9Nm6e9DENsd9FxLFUbOjrgt+ErRgWtj9vPCTBH oohMHl9oZ7IdpC/hxusjTHFFMcxhwIxPlbNorOB+bH8exrrA1DUnzKzq/UXI xT456nxtB59fQNiIrBT2apETJZieZvltpeThrObiZ4ydtY0koKJ2Epb940A1 iXyehONQVXiZr8jRP/NJ3bmjHA0sygAou4Q=
Although I've messed around for hours on this, my best hunch is that I have line break/new line errors in my PDF content. The way I'm getting my PDF content is by creating an array called buffers, then: doc.on('data', buffers.push.bind(buffers));
I'm supposing that I need to be adding /n or /r etc...but I've been working with NodeJS and AngularJS for a month or so now and I know almost EVERYTHING I do wrong is because I'm over-plicating the matter...so I turn to you folks and hope that there is a simple method to attach the content from the new PDFDocument I create with PDFKit to an email using NodeJS.
Thank you in advance...please forgive my rambling, but I started this about 8 hours ago (it's now 3:25am my time). :)
I am using PDFKit and NodeJS to dynamically generate PDF documents, and I would like to attach said document to an email. At this moment I'm using Mandril-API via NPM.
I can generate the PDF without issue and display it in the browser via:
doc.pipe( res );
I can send an email without issue, but I have failed miserably at getting the proper PDF content. I am fairly certain that I am 99% of the way there - but I'm missing something. I have done a ton of reading and testing using Google/StackOverflow etc but I'm stuck.
I am getting content that when I do a base64 decode I get:
%PDF-1.3 % 7 0 obj << /Predictor 15
I have managed to get my PDF attachment to have a valid size of 445KB but this is the content of the email:
--_av-Ti-H6i8tBBHL4BgoXnyC2Q Content-Type: application/pdf Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="mytestPDF.pdf"
PDF1370obj/Predictor15/Colors1/BitsPerComponent8/Columns100e ndobj60obj/Type/XObject/Subtype/Image/BitsPerComponent8/Widt h100/Height19/Filter/FlateDecode/DecodeParms70R/ColorSpace/I ndexed/DeviceRGB25580R/Length1751streamxdSSNEhGIRTRkWbY/nHaO MJln7t+vv89ylF111PlYNB9Nm6e9DENsd9FxLFUbOjrgt+ErRgWtj9vPCTBH oohMHl9oZ7IdpC/hxusjTHFFMcxhwIxPlbNorOB+bH8exrrA1DUnzKzq/UXI xT456nxtB59fQNiIrBT2apETJZieZvltpeThrObiZ4ydtY0koKJ2Epb940A1 iXyehONQVXiZr8jRP/NJ3bmjHA0sygAou4Q=
Although I've messed around for hours on this, my best hunch is that I have line break/new line errors in my PDF content. The way I'm getting my PDF content is by creating an array called buffers, then: doc.on('data', buffers.push.bind(buffers));
I'm supposing that I need to be adding /n or /r etc...but I've been working with NodeJS and AngularJS for a month or so now and I know almost EVERYTHING I do wrong is because I'm over-plicating the matter...so I turn to you folks and hope that there is a simple method to attach the content from the new PDFDocument I create with PDFKit to an email using NodeJS.
Thank you in advance...please forgive my rambling, but I started this about 8 hours ago (it's now 3:25am my time). :)
Share Improve this question edited Oct 11, 2014 at 19:02 Ian Stapleton Cordasco 28.8k4 gold badges73 silver badges73 bronze badges asked Sep 17, 2014 at 10:12 user2348688user2348688 1531 silver badge11 bronze badges1 Answer
Reset to default 11I recently had the same problem with posting an email pdf attachment to mandrill through node.js but managed to solve it.
Here is what I did:
generatePdf(inputData, function (err, doc) {
if (err) return callback(err);
var bufferChunks = [];
doc.on('readable', function() {
// Store buffer chunk to array
bufferChunks.push(doc.read());
});
doc.on('end', function() {
var pdfBuffer = Buffer.concat(bufferChunks),
pdfBase64String = pdfBuffer.toString('base64');
// This string is perfectly ok to use as an attachment to the mandrillAPI
sendMandrillEmailWithAttachment(pdfBase64String);
});
});
I hope this helps. Ping if you need additional help =)
本文标签: javascriptnodejs pdfkit Attach Dynamically Generated PDF to Email (MandrillAPI)Stack Overflow
版权声明:本文标题:javascript - nodejs pdfkit Attach Dynamically Generated PDF to Email (Mandrill-API) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741775141a2396979.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论