Guest User

Untitled

a guest
Dec 14th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. .success(function (response) {
  2. var fileName = response[0].FileName;
  3. var fileImage = response[0].binFileImage;
  4. var blob = new Blob(fileImage, { type: 'application/pdf' });
  5. var fileURL = URL.createObjectURL(blob);
  6.  
  7. function base64ArrayBuffer(arrayBuffer) {
  8. var base64 = ''
  9. var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  10.  
  11. var bytes = new Uint8Array(arrayBuffer)
  12. var byteLength = bytes.byteLength
  13. var byteRemainder = byteLength % 3
  14. var mainLength = byteLength - byteRemainder
  15.  
  16. var a, b, c, d
  17. var chunk
  18.  
  19. // Main loop deals with bytes in chunks of 3
  20. for (var i = 0; i < mainLength; i = i + 3) {
  21. // Combine the three bytes into a single integer
  22. chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]
  23.  
  24. // Use bitmasks to extract 6-bit segments from the triplet
  25. a = (chunk & 16515072) >> 18 // 16515072 = (2^6 - 1) << 18
  26. b = (chunk & 258048) >> 12 // 258048 = (2^6 - 1) << 12
  27. c = (chunk & 4032) >> 6 // 4032 = (2^6 - 1) << 6
  28. d = chunk & 63 // 63 = 2^6 - 1
  29.  
  30. // Convert the raw binary segments to the appropriate ASCII encoding
  31. base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]
  32. }
  33.  
  34. // Deal with the remaining bytes and padding
  35. if (byteRemainder == 1) {
  36. chunk = bytes[mainLength]
  37.  
  38. a = (chunk & 252) >> 2 // 252 = (2^6 - 1) << 2
  39.  
  40. // Set the 4 least significant bits to zero
  41. b = (chunk & 3) << 4 // 3 = 2^2 - 1
  42.  
  43. base64 += encodings[a] + encodings[b] + '=='
  44. } else if (byteRemainder == 2) {
  45. chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]
  46.  
  47. a = (chunk & 64512) >> 10 // 64512 = (2^6 - 1) << 10
  48. b = (chunk & 1008) >> 4 // 1008 = (2^6 - 1) << 4
  49.  
  50. // Set the 2 least significant bits to zero
  51. c = (chunk & 15) << 2 // 15 = 2^4 - 1
  52.  
  53. base64 += encodings[a] + encodings[b] + encodings[c] + '='
  54. }
  55.  
  56. return base64
  57. }
  58.  
  59. JVBERi0xLjQNCiX5+prnDQo3IDAgb2JqDQo8PA0KL0UgMzU0ODENCi9IIFsgMTM3OCAxNjMgXQ0KL0wgMzc3NzkNCi9MaW5lYXJpemVkIDENCi9OIDINCi9PIDEwDQovVCAzNzU4OQ0KPj4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICANCmVuZG9iag0KDQp4cmVmDQo3IDExDQowMDAwMDAwMDE3IDAwMDAwIG4NCjAwMDAwMDEyN... (shortened).
  60.  
  61. lwsService.getdocument(id)
  62. .success(function (response) {
  63. var byteArray = new Uint8Array(response[0].binFileImage);
  64. var blob = new Blob([byteArray], { type: 'application/pdf' });
  65. if (window.navigator && window.navigator.msSaveOrOpenBlob) {
  66. window.navigator.msSaveOrOpenBlob(blob);
  67. } else {
  68. var objectUrl = URL.createObjectURL(blob);
  69. window.open(objectUrl);
  70. }
  71.  
  72. var blob = new Blob([content], {type: 'application/octet-stream'});
  73. saveAs(blob, "yourFile.pdf");
Add Comment
Please, Sign In to add comment