Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public downloadPdf(mbrTemplate: MbrTemplateForMbrPrint) {
- this.uiBlockService.showUiBlock();
- this.mbrPrintPdfReportService.generatePdfReport(mbrTemplate.id).subscribe(
- (result) => {
- const byteString = atob(result.data.base64String.replace(/\s/g, ''));
- // Convert that text into a byte array.
- const ab = new ArrayBuffer(byteString.length);
- const ia = new Uint8Array(ab);
- for (let i = 0; i < byteString.length; i++) {
- ia[i] = byteString.charCodeAt(i);
- }
- // Blob for saving.
- const blob = new Blob([ia], { type: result.data.contentType });
- // Tell the browser to save as xxx
- let fileName: string = 'MBR - ' + mbrTemplate.trxNumber + ' - ' + this.datePipe.transform(new Date(), EbrSettings.DATE_TIME_FOR_DOWNLOAD_FILE);
- fileName += '.pdf';
- FileSaver.saveAs(blob, fileName);
- const cos: Cos = new Cos();
- cos.id = mbrTemplate.cosId;
- const mbr: MbrTemplate = new MbrTemplate();
- mbr.id = mbrTemplate.id;
- const mbrPrintLog: MbrPrintLog = new MbrPrintLog();
- mbrPrintLog.cos = cos;
- mbrPrintLog.mbr = mbr;
- mbrPrintLog.printFlag = PrintFlag.PRINT;
- this.uiBlockService.showUiBlock();
- this.mbrPrintLogService.add(mbrPrintLog).subscribe(
- (resultPrintLog) => {
- this.uiBlockService.hideUiBlock();
- },
- (error) => {
- this.alertMessageService.error(error);
- this.uiBlockService.hideUiBlock();
- }
- );
- this.uiBlockService.hideUiBlock();
- },
- (error) => {
- this.alertMessageService.error(error);
- this.uiBlockService.hideUiBlock();
- }
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement