Use nodejs.
npm install pdfmake
var pdfMake = require('pdfmake')
then I try this
var docDefinition = { content: 'This is an sample PDF printed with pdfMake' };
const pdfDocGenerator = pdfMake.createPdf(docDefinition);
pdfDocGenerator.getBuffer((buffer) => {
console.log(buffer.toString().lengt());
});
But that does not work.
pdfMake.createPdf is not a function
Would you mind providing some server side examples or the entry point to the api.
(I just took the samples provided and thought that would work for server side as well.
Server side example is here: https://github.com/bpampuch/pdfmake/blob/master/dev-playground/server.js
Thanks @liborm85 , will it work if you don't specify a font.
It would be great if the creators of pdfmake can extend the api and document server side code in the readme.
There are so many uses for this way of creating pdfs, and I can image many of it could be server side.
They seem to focus heavily on the browser client.
@liborm85
When i modify the dev-playground/server.js
https://github.com/bpampuch/pdfmake/blob/master/dev-playground/server.js
to respond to get as follows:
app.get('/pdf', function (req, res) {
var docDefinition = { content: 'This is an sample PDF printed with pdfMake' };
createPdfBinary(docDefinition, function (binary) {
res.contentType('application/pdf');
res.send(binary);
}, function (error) {
res.send('ERROR:' + error);
});
});
and open a browser window:
http://localhost:1234/pdf
I get a "failed to load PDF document" errors in the browser..
Can you please try and tell me why this is not working?
Ok, found the issue,
if you want to stream pdf to the client, the createPdfBinary function needs to have this in.
doc.on('end', function () {
result = Buffer.concat(chunks);
callback(result);
// callback('data:application/pdf;base64,' + result.toString('base64'));
});
You can then save the PDF to a file, attach it to an email and render it to the client app.
Most helpful comment
Thanks @liborm85 , will it work if you don't specify a font.
It would be great if the creators of pdfmake can extend the api and document server side code in the readme.
There are so many uses for this way of creating pdfs, and I can image many of it could be server side.
They seem to focus heavily on the browser client.