Pdfkit: I'm using the browser only. How can i force the browser so save / generate my PDF

Created on 30 Jun 2016  路  4Comments  路  Source: foliojs/pdfkit

title says it all

Most helpful comment

Download these:

blob-stream.js from https://github.com/devongovett/blob-stream/releases
FileSaver.js from https://github.com/eligrey/FileSaver.js/
pdfkit.js from http://pdfkit.org/

Then include them in your webpage in that order.

Start your Javascript like this:

    var doc = new PDFDocument();
    var stream = doc.pipe(blobStream());

.....Do your PDF code here, and end with....

    doc.end();
    stream.on('finish', function() {
        blob = stream.toBlob('application/pdf');
        // Line below uses FileSaver.js
        saveAs(blob, 'MyFile.pdf');
    });

All 4 comments

Download these:

blob-stream.js from https://github.com/devongovett/blob-stream/releases
FileSaver.js from https://github.com/eligrey/FileSaver.js/
pdfkit.js from http://pdfkit.org/

Then include them in your webpage in that order.

Start your Javascript like this:

    var doc = new PDFDocument();
    var stream = doc.pipe(blobStream());

.....Do your PDF code here, and end with....

    doc.end();
    stream.on('finish', function() {
        blob = stream.toBlob('application/pdf');
        // Line below uses FileSaver.js
        saveAs(blob, 'MyFile.pdf');
    });

i'm getting "Uncaught TypeError: Invalid non-string/buffer chunk" on "blob-stream.js:3380 "

I want to save my generated pdf by calling the api from a download method in UI. I have tried this but not working, instead getting an error stating that stream.on is not a function. Can anyone please help me on this ?

@lokeshdasari please send a sample of the code

You can look also at pdfmake implementation of helper functions to save pdf

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cam-intel picture cam-intel  路  6Comments

tm2josep picture tm2josep  路  5Comments

akaleeroy picture akaleeroy  路  4Comments

tadarao picture tadarao  路  5Comments

balsamiqMichele picture balsamiqMichele  路  4Comments