Skip to content

Commit f88bef0

Browse files
committed
Merge pull request parallax#542 from yetithefoot/master
Fast ArrayBuffers to String encoding
2 parents f58e830 + ee27719 commit f88bef0

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

plugins/addimage.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,11 @@
413413
* Async method using Blob and FileReader could be best, but i'm not sure how to fit it into the flow?
414414
*/
415415
jsPDFAPI.arrayBufferToBinaryString = function(buffer) {
416+
if('TextDecoder' in window){
417+
var decoder = new TextDecoder('ascii');
418+
return decoder.decode(buffer);
419+
}
420+
416421
if(this.isArrayBuffer(buffer))
417422
buffer = new Uint8Array(buffer);
418423

@@ -586,8 +591,11 @@
586591
* to TypedArray - or should we just leave and process as string?
587592
*/
588593
if(this.supportsArrayBuffer()) {
589-
dataAsBinaryString = imageData;
590-
imageData = this.binaryStringToUint8Array(imageData);
594+
// no need to convert if imageData is already uint8array
595+
if(!(imageData instanceof Uint8Array)){
596+
dataAsBinaryString = imageData;
597+
imageData = this.binaryStringToUint8Array(imageData);
598+
}
591599
}
592600

593601
info = this['process' + format.toUpperCase()](

0 commit comments

Comments
 (0)