@@ -189,6 +189,9 @@ var getJpegSize = function(imgData) {
189
189
object instanceof Float64Array ) ;
190
190
}
191
191
, binaryStringToUint8Array = function ( binary_string ) {
192
+ /*
193
+ * not sure how efficient this will be will bigger files. Is there a native method?
194
+ */
192
195
var len = binary_string . length ;
193
196
var bytes = new Uint8Array ( len ) ;
194
197
for ( var i = 0 ; i < len ; i ++ ) {
@@ -197,6 +200,20 @@ var getJpegSize = function(imgData) {
197
200
return bytes ;
198
201
}
199
202
, arrayBufferToBinaryString = function ( array_buffer ) {
203
+ /*
204
+ * @see this discussion
205
+ * http://stackoverflow.com/questions/6965107/converting-between-strings-and-arraybuffers
206
+ *
207
+ * As stated, i imagine the method below is highly inefficent for large files. Also of note from Mozilla,
208
+ *
209
+ * "However, this is slow and error-prone, due to the need for multiple conversions (especially if the binary data is not actually byte-format data, but, for example, 32-bit integers or floats)."
210
+ *
211
+ * https://developer.mozilla.org/en-US/Add-ons/Code_snippets/StringView
212
+ *
213
+ * Although i'm strugglig to see how it solves this issue? Doesn't appear to be a direct method for conversion?
214
+ *
215
+ * Async method using Blob and FileReader could be best, but i'm not sure how to fit it into this flow?
216
+ */
200
217
/*var binary_string = '';
201
218
//var bytes = new Uint8Array( array_buffer );
202
219
var bytes = array_buffer;
@@ -209,9 +226,7 @@ var getJpegSize = function(imgData) {
209
226
if ( isArrayBufferView ( ) )
210
227
array_buffer = array_buffer . buffer ;
211
228
212
- var base64 = base64ArrayBuffer ( array_buffer ) ;
213
-
214
- return window . atob ( base64 ) ;
229
+ return window . atob ( base64ArrayBuffer ( array_buffer ) ) ;
215
230
}
216
231
, createImageInfo = function ( data , wd , ht , cs , bpc , f , imageIndex , alias , dp , trns , pal , smask ) {
217
232
var info = {
@@ -243,11 +258,13 @@ var getJpegSize = function(imgData) {
243
258
return info ;
244
259
} ;
245
260
246
- jsPDFAPI . addImage = function ( imageData , format , x , y , w , h , alias ) {
261
+ jsPDFAPI . addImage = function ( imageData , format , x , y , w , h , alias , transparency ) {
247
262
'use strict'
248
263
var images = this . internal . collections [ namespace + 'images' ] ,
249
264
cached_info ,
250
265
binaryStringData ;
266
+
267
+ transparency = transparency || false ;
251
268
252
269
if ( typeof format === 'number' ) {
253
270
var tmp = h ;
@@ -272,7 +289,7 @@ jsPDFAPI.addImage = function(imageData, format, x, y, w, h, alias) {
272
289
throw ( 'addImage requires canvas to be supported by browser.' ) ;
273
290
}
274
291
ctx . drawImage ( imageData , 0 , 0 , canvas . width , canvas . height ) ;
275
- imageData = canvas . toDataURL ( ) ;
292
+ imageData = canvas . toDataURL ( transparency ? 'image/png' : 'image/jpeg' ) ;
276
293
format = "png" ;
277
294
}
278
295
@@ -433,8 +450,9 @@ jsPDFAPI.addImage = function(imageData, format, x, y, w, h, alias) {
433
450
if ( img . palette && img . palette . length > 0 )
434
451
pal = img . palette ;
435
452
436
- if ( img . transparency . indexed )
437
- trns = img . transparency . indexed ;
453
+ //I'm not sure the output from png.js is correct for this?
454
+ /*if(img.transparency.indexed)
455
+ trns = img.transparency.indexed;*/
438
456
439
457
info = createImageInfo ( arrayBufferToBinaryString ( imageData ) ,
440
458
img . width ,
0 commit comments