I need to be able to create PDFs in the server side and then send them as attachments by email.
I am using mailgun-js to send emails and that library accepts a Buffer as a valid type for attachments.
I don't want to save the PDFs on my server or in any file system, but I want to generate them on the fly, send them, and forget about them instantly.
The example that looks promising to me is this:
var pdfMake = require('pdfmake');
const pdfDocGenerator = pdfMake.createPdf({content: 'test'});
pdfDocGenerator.getBuffer((buffer) => {
// ...
});
In this way I would be able to use the buffer to send the email. Unfortunately, this crashes and gives me the following error: TypeError: pdfmake.createPdf is not a function.
On server side method createPdf is not supported.
You can use something like that, see example: https://github.com/bpampuch/pdfmake/blob/master/examples/basics.js
and to load into a buffer, is example here: https://github.com/bpampuch/pdfmake/blob/master/src/browser-extensions/pdfMake.js#L41-L55
liborm 85 i will find an err no such for dirctory
Error: ENOENT: no such file or directory, open 'D:\ScorecardProductionInstance\f
onts\Roboto-Regular.ttf'
Is there a reason for server side creation not being supported? It seems to me, if there was a way to provide the fonts for pdfMake.createPdf, there shouldn't be any problems, since that function is basically a wrapper around the printer class.
I'm really frustrated right now, because I've been trying to do exactly that for some hours now and it just won't eat my fonts. The pdfMake class is really great in theory because I can export the PDF in all kinds of encodings (I'm trying to use base64).
I know I could've used (and still could) something like base64-stream, but the whole point of using pdfMake was basically not having to do that and to save time, and I've failed miserably.
Definitely a needed improvement, same functions for server side and for client side!
On server side method
createPdfis not supported.
You can use something like that, see example: https://github.com/bpampuch/pdfmake/blob/master/examples/basics.js
and to load into a buffer, is example here: https://github.com/bpampuch/pdfmake/blob/master/src/browser-extensions/pdfMake.js#L41-L55
@liborm85 I'm confused, the example you linked uses createPdf??
@bpampuch @liborm85 Can someone please look at this issue again?
Issue is too old, and therefore links are to master unreleased version (see notice).
Use documentation: https://pdfmake.github.io/docs/getting-started/server-side/
Most helpful comment
Is there a reason for server side creation not being supported? It seems to me, if there was a way to provide the fonts for pdfMake.createPdf, there shouldn't be any problems, since that function is basically a wrapper around the printer class.
I'm really frustrated right now, because I've been trying to do exactly that for some hours now and it just won't eat my fonts. The pdfMake class is really great in theory because I can export the PDF in all kinds of encodings (I'm trying to use base64).
I know I could've used (and still could) something like base64-stream, but the whole point of using pdfMake was basically not having to do that and to save time, and I've failed miserably.
Definitely a needed improvement, same functions for server side and for client side!