/jspdf.plugin.addimage.js

https://github.com/vincerio/jsPDF · JavaScript · 656 lines · 444 code · 87 blank · 125 comment · 93 complexity · 877a05c9953449d00d80cbe96ebe4823 MD5 · raw file

  1. /** @preserve
  2. * jsPDF addImage plugin
  3. * Copyright (c) 2012 Jason Siefken, https://github.com/siefkenj/
  4. * 2013 Chris Dowling, https://github.com/gingerchris
  5. * 2013 Trinh Ho, https://github.com/ineedfat
  6. * 2013 Edwin Alejandro Perez, https://github.com/eaparango
  7. * 2013 Norah Smith, https://github.com/burnburnrocket
  8. * 2014 Diego Casorran, https://github.com/diegocr
  9. * 2014 James Robb, https://github.com/jamesbrobb
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining
  12. * a copy of this software and associated documentation files (the
  13. * "Software"), to deal in the Software without restriction, including
  14. * without limitation the rights to use, copy, modify, merge, publish,
  15. * distribute, sublicense, and/or sell copies of the Software, and to
  16. * permit persons to whom the Software is furnished to do so, subject to
  17. * the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall be
  20. * included in all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. */
  30. ;(function(jsPDFAPI) {
  31. 'use strict'
  32. var namespace = 'addImage_',
  33. supported_image_types = ['jpeg', 'jpg', 'png'];
  34. // Image functionality ported from pdf.js
  35. var putImage = function(img) {
  36. var objectNumber = this.internal.newObject()
  37. , out = this.internal.write
  38. , putStream = this.internal.putStream
  39. img['n'] = objectNumber
  40. out('<</Type /XObject')
  41. out('/Subtype /Image')
  42. out('/Width ' + img['w'])
  43. out('/Height ' + img['h'])
  44. if (img['cs'] === this.color_spaces.INDEXED) {
  45. out('/ColorSpace [/Indexed /DeviceRGB '
  46. // if an indexed png defines more than one colour with transparency, we've created a smask
  47. + (img['pal'].length / 3 - 1) + ' ' + ('smask' in img ? objectNumber + 2 : objectNumber + 1)
  48. + ' 0 R]');
  49. } else {
  50. out('/ColorSpace /' + img['cs']);
  51. if (img['cs'] === this.color_spaces.DEVICE_CMYK) {
  52. out('/Decode [1 0 1 0 1 0 1 0]');
  53. }
  54. }
  55. out('/BitsPerComponent ' + img['bpc']);
  56. if ('f' in img) {
  57. out('/Filter /' + img['f']);
  58. }
  59. if ('dp' in img) {
  60. out('/DecodeParms <<' + img['dp'] + '>>');
  61. }
  62. if ('trns' in img && img['trns'].constructor == Array) {
  63. var trns = '',
  64. i = 0,
  65. len = img['trns'].length;
  66. for (; i < len; i++)
  67. trns += (img['trns'][i] + ' ' + img['trns'][i] + ' ');
  68. out('/Mask [' + trns + ']');
  69. }
  70. if ('smask' in img) {
  71. out('/SMask ' + (objectNumber + 1) + ' 0 R');
  72. }
  73. out('/Length ' + img['data'].length + '>>');
  74. putStream(img['data']);
  75. out('endobj');
  76. // Soft mask
  77. if ('smask' in img) {
  78. var dp = '/Predictor 15 /Colors 1 /BitsPerComponent ' + img['bpc'] + ' /Columns ' + img['w'];
  79. var smask = {'w': img['w'], 'h': img['h'], 'cs': 'DeviceGray', 'bpc': img['bpc'], 'dp': dp, 'data': img['smask']};
  80. if ('f' in img)
  81. smask.f = img['f'];
  82. putImage.call(this, smask);
  83. }
  84. //Palette
  85. if (img['cs'] === this.color_spaces.INDEXED) {
  86. this.internal.newObject();
  87. //out('<< /Filter / ' + img['f'] +' /Length ' + img['pal'].length + '>>');
  88. //putStream(zlib.compress(img['pal']));
  89. out('<< /Length ' + img['pal'].length + '>>');
  90. putStream(this.arrayBufferToBinaryString(new Uint8Array(img['pal'])));
  91. out('endobj');
  92. }
  93. }
  94. , putResourcesCallback = function() {
  95. var images = this.internal.collections[namespace + 'images']
  96. for ( var i in images ) {
  97. putImage.call(this, images[i])
  98. }
  99. }
  100. , putXObjectsDictCallback = function(){
  101. var images = this.internal.collections[namespace + 'images']
  102. , out = this.internal.write
  103. , image
  104. for (var i in images) {
  105. image = images[i]
  106. out(
  107. '/I' + image['i']
  108. , image['n']
  109. , '0'
  110. , 'R'
  111. )
  112. }
  113. }
  114. , checkCompressValue = function(value) {
  115. if(value && typeof value === 'string')
  116. value = value.toUpperCase();
  117. return value in jsPDFAPI.image_compression ? value : jsPDFAPI.image_compression.NONE;
  118. }
  119. , getImages = function() {
  120. var images = this.internal.collections[namespace + 'images'];
  121. //first run, so initialise stuff
  122. if(!images) {
  123. this.internal.collections[namespace + 'images'] = images = {};
  124. this.internal.events.subscribe('putResources', putResourcesCallback);
  125. this.internal.events.subscribe('putXobjectDict', putXObjectsDictCallback);
  126. }
  127. return images;
  128. }
  129. , getImageIndex = function(images) {
  130. var imageIndex = 0;
  131. if (images){
  132. // this is NOT the first time this method is ran on this instance of jsPDF object.
  133. imageIndex = Object.keys ?
  134. Object.keys(images).length :
  135. (function(o){
  136. var i = 0
  137. for (var e in o){if(o.hasOwnProperty(e)){ i++ }}
  138. return i
  139. })(images)
  140. }
  141. return imageIndex;
  142. }
  143. , notDefined = function(value) {
  144. return typeof value === 'undefined' || value === null;
  145. }
  146. , generateAliasFromData = function(data) {
  147. // TODO: Alias dynamic generation from imageData's checksum/hash
  148. return undefined;
  149. }
  150. , doesNotSupportImageType = function(type) {
  151. return supported_image_types.indexOf(type) === -1;
  152. }
  153. , processMethodNotEnabled = function(type) {
  154. return typeof jsPDFAPI['process' + type.toUpperCase()] !== 'function';
  155. }
  156. , isDOMElement = function(object) {
  157. return typeof object === 'object' && object.nodeType === 1;
  158. }
  159. , createDataURIFromElement = function(element, format) {
  160. //if element is an image which uses data url defintion, just return the dataurl
  161. if (element.nodeName === 'IMG' && element.hasAttribute('src') && (''+element.getAttribute('src')).indexOf('data:image/') === 0) {
  162. return element.getAttribute('src');
  163. }
  164. if(element.nodeName === 'CANVAS') {
  165. var canvas = element;
  166. } else {
  167. var canvas = document.createElement('canvas');
  168. canvas.width = element.clientWidth || element.width;
  169. canvas.height = element.clientHeight || element.height;
  170. var ctx = canvas.getContext('2d');
  171. if (!ctx) {
  172. throw ('addImage requires canvas to be supported by browser.');
  173. }
  174. ctx.drawImage(element, 0, 0, canvas.width, canvas.height);
  175. }
  176. return canvas.toDataURL(format == 'png' ? 'image/png' : 'image/jpeg');
  177. }
  178. ,checkImagesForAlias = function(imageData, images) {
  179. var cached_info;
  180. if(images) {
  181. for(var e in images) {
  182. if(imageData === images[e].alias) {
  183. cached_info = images[e];
  184. break;
  185. }
  186. }
  187. }
  188. return cached_info;
  189. }
  190. ,determineWidthAndHeight = function(w, h, info) {
  191. if (!w && !h) {
  192. w = -96;
  193. h = -96;
  194. }
  195. if (w < 0) {
  196. w = (-1) * info['w'] * 72 / w / this.internal.scaleFactor;
  197. }
  198. if (h < 0) {
  199. h = (-1) * info['h'] * 72 / h / this.internal.scaleFactor;
  200. }
  201. if (w === 0) {
  202. w = h * info['w'] / info['h'];
  203. }
  204. if (h === 0) {
  205. h = w * info['h'] / info['w'];
  206. }
  207. return [w, h];
  208. }
  209. , writeImageToPDF = function(x, y, w, h, info, index, images) {
  210. var dims = determineWidthAndHeight.call(this, w, h, info),
  211. coord = this.internal.getCoordinateString,
  212. vcoord = this.internal.getVerticalCoordinateString;
  213. w = dims[0];
  214. h = dims[1];
  215. images[index] = info;
  216. this.internal.write(
  217. 'q'
  218. , coord(w)
  219. , '0 0'
  220. , coord(h) // TODO: check if this should be shifted by vcoord
  221. , coord(x)
  222. , vcoord(y + h)
  223. , 'cm /I'+info['i']
  224. , 'Do Q'
  225. )
  226. };
  227. /**
  228. * COLOR SPACES
  229. */
  230. jsPDFAPI.color_spaces = {
  231. DEVICE_RGB:'DeviceRGB',
  232. DEVICE_GRAY:'DeviceGray',
  233. DEVICE_CMYK:'DeviceCMYK',
  234. CAL_GREY:'CalGray',
  235. CAL_RGB:'CalRGB',
  236. LAB:'Lab',
  237. ICC_BASED:'ICCBased',
  238. INDEXED:'Indexed',
  239. PATTERN:'Pattern',
  240. SEPERATION:'Seperation',
  241. DEVICE_N:'DeviceN'
  242. };
  243. /**
  244. * DECODE METHODS
  245. */
  246. jsPDFAPI.decode = {
  247. DCT_DECODE:'DCTDecode',
  248. FLATE_DECODE:'FlateDecode',
  249. LZW_DECODE:'LZWDecode',
  250. JPX_DECODE:'JPXDecode',
  251. JBIG2_DECODE:'JBIG2Decode',
  252. ASCII85_DECODE:'ASCII85Decode',
  253. ASCII_HEX_DECODE:'ASCIIHexDecode',
  254. RUN_LENGTH_DECODE:'RunLengthDecode',
  255. CCITT_FAX_DECODE:'CCITTFaxDecode'
  256. };
  257. /**
  258. * IMAGE COMPRESSION TYPES
  259. */
  260. jsPDFAPI.image_compression = {
  261. NONE: 'NONE',
  262. FAST: 'FAST',
  263. MEDIUM: 'MEDIUM',
  264. SLOW: 'SLOW'
  265. };
  266. jsPDFAPI.isString = function(object) {
  267. return typeof object === 'string';
  268. };
  269. /**
  270. * Strips out and returns info from a valid base64 data URI
  271. * @param {String[dataURI]} a valid data URI of format 'data:[<MIME-type>][;base64],<data>'
  272. * @returns an Array containing the following
  273. * [0] the complete data URI
  274. * [1] <MIME-type>
  275. * [2] format - the second part of the mime-type i.e 'png' in 'image/png'
  276. * [4] <data>
  277. */
  278. jsPDFAPI.extractInfoFromBase64DataURI = function(dataURI) {
  279. return /^data:([\w]+?\/([\w]+?));base64,(.+?)$/g.exec(dataURI);
  280. };
  281. /**
  282. * Check to see if ArrayBuffer is supported
  283. */
  284. jsPDFAPI.supportsArrayBuffer = function() {
  285. return typeof ArrayBuffer !== 'undefined' && typeof Uint8Array !== 'undefined';
  286. };
  287. /**
  288. * Tests supplied object to determine if ArrayBuffer
  289. * @param {Object[object]}
  290. */
  291. jsPDFAPI.isArrayBuffer = function(object) {
  292. if(!this.supportsArrayBuffer())
  293. return false;
  294. return object instanceof ArrayBuffer;
  295. };
  296. /**
  297. * Tests supplied object to determine if it implements the ArrayBufferView (TypedArray) interface
  298. * @param {Object[object]}
  299. */
  300. jsPDFAPI.isArrayBufferView = function(object) {
  301. if(!this.supportsArrayBuffer())
  302. return false;
  303. if(typeof Uint32Array === 'undefined')
  304. return false;
  305. return (object instanceof Int8Array ||
  306. object instanceof Uint8Array ||
  307. (typeof Uint8ClampedArray !== 'undefined' && object instanceof Uint8ClampedArray) ||
  308. object instanceof Int16Array ||
  309. object instanceof Uint16Array ||
  310. object instanceof Int32Array ||
  311. object instanceof Uint32Array ||
  312. object instanceof Float32Array ||
  313. object instanceof Float64Array );
  314. };
  315. /**
  316. * Exactly what it says on the tin
  317. */
  318. jsPDFAPI.binaryStringToUint8Array = function(binary_string) {
  319. /*
  320. * not sure how efficient this will be will bigger files. Is there a native method?
  321. */
  322. var len = binary_string.length;
  323. var bytes = new Uint8Array( len );
  324. for (var i = 0; i < len; i++) {
  325. bytes[i] = binary_string.charCodeAt(i);
  326. }
  327. return bytes;
  328. };
  329. /**
  330. * @see this discussion
  331. * http://stackoverflow.com/questions/6965107/converting-between-strings-and-arraybuffers
  332. *
  333. * As stated, i imagine the method below is highly inefficent for large files.
  334. *
  335. * Also of note from Mozilla,
  336. *
  337. * "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)."
  338. *
  339. * https://developer.mozilla.org/en-US/Add-ons/Code_snippets/StringView
  340. *
  341. * Although i'm strugglig to see how StringView solves this issue? Doesn't appear to be a direct method for conversion?
  342. *
  343. * Async method using Blob and FileReader could be best, but i'm not sure how to fit it into the flow?
  344. */
  345. jsPDFAPI.arrayBufferToBinaryString = function(buffer) {
  346. if(this.isArrayBuffer(buffer))
  347. buffer = new Uint8Array(buffer);
  348. var binary_string = '';
  349. var len = buffer.byteLength;
  350. for (var i = 0; i < len; i++) {
  351. binary_string += String.fromCharCode(buffer[i]);
  352. }
  353. return binary_string;
  354. /*
  355. * Another solution is the method below - convert array buffer straight to base64 and then use atob
  356. */
  357. //return atob(this.arrayBufferToBase64(buffer));
  358. };
  359. /**
  360. * Converts an ArrayBuffer directly to base64
  361. *
  362. * Taken from here
  363. *
  364. * http://jsperf.com/encoding-xhr-image-data/31
  365. *
  366. * Need to test if this is a better solution for larger files
  367. *
  368. */
  369. jsPDFAPI.arrayBufferToBase64 = function(arrayBuffer) {
  370. var base64 = ''
  371. var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  372. var bytes = new Uint8Array(arrayBuffer)
  373. var byteLength = bytes.byteLength
  374. var byteRemainder = byteLength % 3
  375. var mainLength = byteLength - byteRemainder
  376. var a, b, c, d
  377. var chunk
  378. // Main loop deals with bytes in chunks of 3
  379. for (var i = 0; i < mainLength; i = i + 3) {
  380. // Combine the three bytes into a single integer
  381. chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]
  382. // Use bitmasks to extract 6-bit segments from the triplet
  383. a = (chunk & 16515072) >> 18 // 16515072 = (2^6 - 1) << 18
  384. b = (chunk & 258048) >> 12 // 258048 = (2^6 - 1) << 12
  385. c = (chunk & 4032) >> 6 // 4032 = (2^6 - 1) << 6
  386. d = chunk & 63 // 63 = 2^6 - 1
  387. // Convert the raw binary segments to the appropriate ASCII encoding
  388. base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]
  389. }
  390. // Deal with the remaining bytes and padding
  391. if (byteRemainder == 1) {
  392. chunk = bytes[mainLength]
  393. a = (chunk & 252) >> 2 // 252 = (2^6 - 1) << 2
  394. // Set the 4 least significant bits to zero
  395. b = (chunk & 3) << 4 // 3 = 2^2 - 1
  396. base64 += encodings[a] + encodings[b] + '=='
  397. } else if (byteRemainder == 2) {
  398. chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]
  399. a = (chunk & 64512) >> 10 // 64512 = (2^6 - 1) << 10
  400. b = (chunk & 1008) >> 4 // 1008 = (2^6 - 1) << 4
  401. // Set the 2 least significant bits to zero
  402. c = (chunk & 15) << 2 // 15 = 2^4 - 1
  403. base64 += encodings[a] + encodings[b] + encodings[c] + '='
  404. }
  405. return base64
  406. };
  407. jsPDFAPI.createImageInfo = function(data, wd, ht, cs, bpc, f, imageIndex, alias, dp, trns, pal, smask) {
  408. var info = {
  409. alias:alias,
  410. w : wd,
  411. h : ht,
  412. cs : cs,
  413. bpc : bpc,
  414. i : imageIndex,
  415. data : data
  416. // n: objectNumber will be added by putImage code
  417. };
  418. if(f) info.f = f;
  419. if(dp) info.dp = dp;
  420. if(trns) info.trns = trns;
  421. if(pal) info.pal = pal;
  422. if(smask) info.smask = smask;
  423. return info;
  424. };
  425. jsPDFAPI.addImage = function(imageData, format, x, y, w, h, alias, compression) {
  426. 'use strict'
  427. if(typeof format === 'number') {
  428. var tmp = h;
  429. h = w;
  430. w = y;
  431. y = x;
  432. x = format;
  433. format = tmp;
  434. }
  435. var images = getImages.call(this),//initalises internals and events on first run
  436. cached_info,
  437. dataAsBinaryString;
  438. compression = checkCompressValue(compression);
  439. format = (format || 'JPEG').toLowerCase();
  440. if(notDefined(alias))
  441. alias = generateAliasFromData(imageData);
  442. if(isDOMElement(imageData))
  443. imageData = createDataURIFromElement(imageData, format);
  444. if(this.isString(imageData)) {
  445. var base64Info = this.extractInfoFromBase64DataURI(imageData);
  446. if(base64Info) {
  447. format = base64Info[2];
  448. imageData = atob(base64Info[3]);//convert to binary string
  449. /*
  450. * need to test if it's more efficent to convert all binary strings
  451. * to TypedArray - or should we just leave and process as string?
  452. */
  453. if(this.supportsArrayBuffer()) {
  454. dataAsBinaryString = imageData;
  455. imageData = this.binaryStringToUint8Array(imageData);
  456. }
  457. }else{
  458. // This is neither raw jpeg-data nor a data uri; alias?
  459. if(imageData.charCodeAt(0) !== 0xff)
  460. cached_info = checkImagesForAlias(imageData, images);
  461. }
  462. }
  463. if(doesNotSupportImageType(format))
  464. throw new Error('addImage currently only supports formats ' + supported_image_types + ', not \''+format+'\'');
  465. if(processMethodNotEnabled(format))
  466. throw new Error('please ensure that the plugin for \''+format+'\' support is added');
  467. var imageIndex = getImageIndex(images),
  468. info = cached_info;
  469. if(!info)
  470. info = this['process' + format.toUpperCase()](imageData, imageIndex, alias, compression, dataAsBinaryString);
  471. if(!info)
  472. throw new Error('An unkwown error occurred whilst processing the image');
  473. writeImageToPDF.call(this, x, y, w, h, info, imageIndex, images);
  474. return this
  475. };
  476. /**
  477. * JPEG SUPPORT
  478. **/
  479. //takes a string imgData containing the raw bytes of
  480. //a jpeg image and returns [width, height]
  481. //Algorithm from: http://www.64lines.com/jpeg-width-height
  482. var getJpegSize = function(imgData) {
  483. 'use strict'
  484. var width, height;
  485. // Verify we have a valid jpeg header 0xff,0xd8,0xff,0xe0,?,?,'J','F','I','F',0x00
  486. if (!imgData.charCodeAt(0) === 0xff ||
  487. !imgData.charCodeAt(1) === 0xd8 ||
  488. !imgData.charCodeAt(2) === 0xff ||
  489. !imgData.charCodeAt(3) === 0xe0 ||
  490. !imgData.charCodeAt(6) === 'J'.charCodeAt(0) ||
  491. !imgData.charCodeAt(7) === 'F'.charCodeAt(0) ||
  492. !imgData.charCodeAt(8) === 'I'.charCodeAt(0) ||
  493. !imgData.charCodeAt(9) === 'F'.charCodeAt(0) ||
  494. !imgData.charCodeAt(10) === 0x00) {
  495. throw new Error('getJpegSize requires a binary string jpeg file')
  496. }
  497. var blockLength = imgData.charCodeAt(4)*256 + imgData.charCodeAt(5);
  498. var i = 4, len = imgData.length;
  499. while ( i < len ) {
  500. i += blockLength;
  501. if (imgData.charCodeAt(i) !== 0xff) {
  502. throw new Error('getJpegSize could not find the size of the image');
  503. }
  504. if (imgData.charCodeAt(i+1) === 0xc0 || //(SOF) Huffman - Baseline DCT
  505. imgData.charCodeAt(i+1) === 0xc1 || //(SOF) Huffman - Extended sequential DCT
  506. imgData.charCodeAt(i+1) === 0xc2 || // Progressive DCT (SOF2)
  507. imgData.charCodeAt(i+1) === 0xc3 || // Spatial (sequential) lossless (SOF3)
  508. imgData.charCodeAt(i+1) === 0xc4 || // Differential sequential DCT (SOF5)
  509. imgData.charCodeAt(i+1) === 0xc5 || // Differential progressive DCT (SOF6)
  510. imgData.charCodeAt(i+1) === 0xc6 || // Differential spatial (SOF7)
  511. imgData.charCodeAt(i+1) === 0xc7) {
  512. height = imgData.charCodeAt(i+5)*256 + imgData.charCodeAt(i+6);
  513. width = imgData.charCodeAt(i+7)*256 + imgData.charCodeAt(i+8);
  514. return [width, height];
  515. } else {
  516. i += 2;
  517. blockLength = imgData.charCodeAt(i)*256 + imgData.charCodeAt(i+1)
  518. }
  519. }
  520. }
  521. , getJpegSizeFromBytes = function(data) {
  522. var hdr = (data[0] << 8) | data[1];
  523. if(hdr !== 0xFFD8)
  524. throw new Error('Supplied data is not a JPEG');
  525. var len = data.length,
  526. block = (data[4] << 8) + data[5],
  527. pos = 4,
  528. bytes, width, height;
  529. while(pos < len) {
  530. pos += block;
  531. bytes = readBytes(data, pos);
  532. block = (bytes[2] << 8) + bytes[3];
  533. if((bytes[1] === 0xC0 || bytes[1] === 0xC2) && bytes[0] === 0xFF && block > 7) {
  534. bytes = readBytes(data, pos + 5);
  535. width = (bytes[2] << 8) + bytes[3];
  536. height = (bytes[0] << 8) + bytes[1];
  537. return {width:width, height:height};
  538. }
  539. pos+=2;
  540. }
  541. throw new Error('getJpegSizeFromBytes could not find the size of the image');
  542. }
  543. , readBytes = function(data, offset) {
  544. return data.subarray(offset, offset+ 4);
  545. };
  546. jsPDFAPI.processJPEG = function(data, index, alias, compression, dataAsBinaryString) {
  547. 'use strict'
  548. var colorSpace = this.color_spaces.DEVICE_RGB,
  549. filter = this.decode.DCT_DECODE,
  550. bpc = 8,
  551. dims;
  552. if(this.isString(data)) {
  553. dims = getJpegSize(data);
  554. return this.createImageInfo(data, dims[0], dims[1], colorSpace, bpc, filter, index, alias);
  555. }
  556. if(this.isArrayBuffer(data))
  557. data = new Uint8Array(data);
  558. if(this.isArrayBufferView(data)) {
  559. dims = getJpegSizeFromBytes(data);
  560. // if we already have a stored binary string rep use that
  561. data = dataAsBinaryString || this.arrayBufferToBinaryString(data);
  562. return this.createImageInfo(data, dims.width, dims.height, colorSpace, bpc, filter, index, alias);
  563. }
  564. return null;
  565. };
  566. jsPDFAPI.processJPG = function(/*data, index, alias, compression, dataAsBinaryString*/) {
  567. return this.processJPEG.apply(this, arguments);
  568. }
  569. })(jsPDF.API);