pdfmake icon indicating copy to clipboard operation
pdfmake copied to clipboard

Open saved blob from db

Open zirt0 opened this issue 10 years ago • 1 comments

I want to save a pdf to the database en reopen it when i need it, but i dont know how to do it exactly.

i am making first a buffer blob and then save in to db. THis is working good i think

`pdfMake.createPdf(docDefinition).getBuffer(function(dataURL) {

    data = JSON.stringify(dataURL)
    //here is some code to save in database

});`

But i dont know what to do to when i retrieve the data from the database to create a new pdf file.

var getfromDb = JSON.parse(dataURL) pdfMake.createPdf(getfromDb).open(); I have tried this but it is not working. Can someone give me a example code how to open a pdf with the blob

zirt0 avatar Oct 02 '16 12:10 zirt0

I save PDF as Blob in database, so when I want to get it I do:

getAttachment('report', report.id, filename)
          .then(function(blob) {
            // --------------- Open in explorer ---------------
            var url = URL.createObjectURL(blob);
            var win = window.open('', '_blank');
            try {
              win.location.href = url;
            } catch (e) {
              win.close();
              throw e;
            }
            // --------------- Download  ---------------
            FileSaver.saveAs(blob, filename);

ramonsan avatar Oct 06 '16 08:10 ramonsan