Convert Blob data to Raw buffer in javascript or node

后端 未结 3 1365
猫巷女王i
猫巷女王i 2021-02-09 04:55

I am using a plugin jsPDF which generates PDF and saves it to local file system. Now in jsPDF.js, there is some piece of code which generates pdf data in blob format as:-

<
3条回答
  •  独厮守ぢ
    2021-02-09 05:01

               var blob = new Blob([array], {type: "application/pdf"});
    
                var arrayBuffer, uint8Array;
                var fileReader = new FileReader();
                fileReader.onload = function() {
                    arrayBuffer = this.result;
                    uint8Array  = new Uint8Array(arrayBuffer);
    
                    var printer = require("./js/controller/lib");
                    printer.printDirect({
                        data: uint8Array,
                        printer:'Deskjet_3540',
                        type: 'PDF',
                        success: function(id) {
                            console.log('printed with id ' + id);
                        },
                        error: function(err) {
                            console.error('error on printing: ' + err);
                        }
                    })
                };
                fileReader.readAsArrayBuffer(blob);
    

    This is the final code which worked for me. The printer accepts uint8Array encoding format.

提交回复
热议问题