Pdfmake: Saving Generated pdfmake PDF or attaching to email

Created on 8 May 2017  路  5Comments  路  Source: bpampuch/pdfmake

Hi, Thanks to bpampuch for such a great code work.

I have struggled for the past 3 days to get the generated pdf either saved in my local filesystem or emailed as an attachment to the user. I have considered various threads posted here on the issue but none seem to be working in scenario.

I have followed these threads:

https://github.com/bpampuch/pdfmake/issues/489
https://github.com/bpampuch/pdfmake/issues/720

However I'm not winning.

I also suggest that guides on emailing the pdf as attachment be added to the playground repository.

Thanks again for the great code work hope someone can help.

Most helpful comment

In case it's useful for someone I finally made it work.

I wanted to generate a PDF through pdfMake and then send it via mail without storing it. I am working in a meteor stack.

In the client:

            var docDefinition = {
                content: [
                    'First test paragraph'
                ]
              };

            var data;
            pdfMake.createPdf(docDefinition).getBase64(function(encodedString) {
                data = encodedString;
                Meteor.call("sendPDFemail", data);
            });

In the server:

  sendPDFEmail: function(thepdf){
    Email.send({
        to: "receiver",
        from: "sender",
        subject: "Test",
        html: "html",
        attachments: [
            {
                filename: "test.pdf",
                type: "application/pdf",
                content: Buffer.from(thepdf, 'base64')
            }
        ]
    });
  },

All 5 comments

How to save generated pdf into file is shown here: https://github.com/bpampuch/pdfmake/blob/master/examples/basics.js (saving file is in line 22)
And then you can attach this file to the e-mail.

Thanks a mil liborm85 your response was lost in my gmail spam. Thanks a mil for the help. Great stuff.

In case it's useful for someone I finally made it work.

I wanted to generate a PDF through pdfMake and then send it via mail without storing it. I am working in a meteor stack.

In the client:

            var docDefinition = {
                content: [
                    'First test paragraph'
                ]
              };

            var data;
            pdfMake.createPdf(docDefinition).getBase64(function(encodedString) {
                data = encodedString;
                Meteor.call("sendPDFemail", data);
            });

In the server:

  sendPDFEmail: function(thepdf){
    Email.send({
        to: "receiver",
        from: "sender",
        subject: "Test",
        html: "html",
        attachments: [
            {
                filename: "test.pdf",
                type: "application/pdf",
                content: Buffer.from(thepdf, 'base64')
            }
        ]
    });
  },

Thanks @marmeden

what is Buffer @marmeden ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

m-brudi picture m-brudi  路  3Comments

CharlyPoppins picture CharlyPoppins  路  3Comments

Masber picture Masber  路  3Comments

davidyeiser picture davidyeiser  路  3Comments

ValeSauer picture ValeSauer  路  3Comments