Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. public downloadPdf(mbrTemplate: MbrTemplateForMbrPrint) {
  2. this.uiBlockService.showUiBlock();
  3. this.mbrPrintPdfReportService.generatePdfReport(mbrTemplate.id).subscribe(
  4. (result) => {
  5. const byteString = atob(result.data.base64String.replace(/\s/g, ''));
  6.  
  7. // Convert that text into a byte array.
  8. const ab = new ArrayBuffer(byteString.length);
  9. const ia = new Uint8Array(ab);
  10. for (let i = 0; i < byteString.length; i++) {
  11. ia[i] = byteString.charCodeAt(i);
  12. }
  13.  
  14. // Blob for saving.
  15. const blob = new Blob([ia], { type: result.data.contentType });
  16.  
  17. // Tell the browser to save as xxx
  18. let fileName: string = 'MBR - ' + mbrTemplate.trxNumber + ' - ' + this.datePipe.transform(new Date(), EbrSettings.DATE_TIME_FOR_DOWNLOAD_FILE);
  19. fileName += '.pdf';
  20. FileSaver.saveAs(blob, fileName);
  21.  
  22. const cos: Cos = new Cos();
  23. cos.id = mbrTemplate.cosId;
  24.  
  25. const mbr: MbrTemplate = new MbrTemplate();
  26. mbr.id = mbrTemplate.id;
  27.  
  28. const mbrPrintLog: MbrPrintLog = new MbrPrintLog();
  29. mbrPrintLog.cos = cos;
  30. mbrPrintLog.mbr = mbr;
  31. mbrPrintLog.printFlag = PrintFlag.PRINT;
  32. this.uiBlockService.showUiBlock();
  33. this.mbrPrintLogService.add(mbrPrintLog).subscribe(
  34. (resultPrintLog) => {
  35. this.uiBlockService.hideUiBlock();
  36. },
  37. (error) => {
  38. this.alertMessageService.error(error);
  39. this.uiBlockService.hideUiBlock();
  40. }
  41. );
  42.  
  43. this.uiBlockService.hideUiBlock();
  44. },
  45. (error) => {
  46. this.alertMessageService.error(error);
  47. this.uiBlockService.hideUiBlock();
  48. }
  49. );
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement