import JsBarcode from 'jsbarcode'; import { SharedPDFService } from '../../shared/shared-pdf.service'; declare var pdfMake: any; export class ItemDetaisPdf { static PrintFile: any; static ItemDetailsPrint(Item: any, win: any, custom: boolean, txt: string) { let dd = { background: function (currentPage:any, pageSize:any) { if (custom) { return [ { canvas: [ { type: 'line', x1: 5, y1: 5, x2: 385, y2: 5, lineWidth: 1 }, //Up line { type: 'line', x1: 5, y1: 5, x2: 5, y2: 560, lineWidth: 1 }, //Left line { type: 'line', x1: 5, y1: 560, x2: 385, y2: 560, lineWidth: 1 }, //Bottom line { type: 'line', x1: 385, y1: 5, x2: 385, y2: 560, lineWidth: 1 }, //Rigth line ] } ] } else { return [ { canvas: [ { type: 'line', x1: 5, y1: 5, x2: 272, y2: 5, lineWidth: 1 }, //Up line { type: 'line', x1: 5, y1: 5, x2: 5, y2: 420, lineWidth: 1 }, //Left line { type: 'line', x1: 5, y1: 420, x2: 272, y2: 420, lineWidth: 1 }, //Bottom line { type: 'line', x1: 272, y1: 5, x2: 272, y2: 420, lineWidth: 1 }, //Rigth line ] } ] } }, info: { title: 'ItemDetails', }, header: function (currentPage: any, pageCount: any) { return { text: currentPage.toString() + ' of ' + pageCount, alignment: 'right', marginRight: 7, fontSize: 8, marginTop: 2 }; }, footer: { columns: [ { text: Item.Entity.CName, bold: 'true' }, { text: Item.Entity.CName, alignment: 'right' } ] }, // pageMargins: [10, 15, 10, 15], pageMargins: [10, 10, 10, 10], pageSize: custom ? 'B7' : { width: 277, height: 435 }, content: [ // SharedPDFService.MainHeading(CheckListData.Entity.CName, CheckListData.Entity.Header, CheckListData.Image, CheckListData.HColor, null), SharedPDFService.MainHeading(Item.Entity.CName, Item.Entity, Image, Item.AColor, null), SharedPDFService.GetHeader(Item.Entity, Item.HColor), // SharedPDFService.GetPrintType('INSPECTION'), // SharedPDFService.HeaderAfterLine(), this.ChangeTableFormat(Item.Item, custom, txt), // this.TableCreation(Item.Item), // this.CheckListTable(CheckListData.Sections) ], styles: SharedPDFService.GetStyles() }; // return dd; pdfMake.createPdf(dd).open(); // this.PrintFile = TrUtils.Stringify(dd); // pdfMake.createPdf(dd).getDataUrl((DataURL: any) => { // document.getElementById('pdf').setAttribute('src', DataURL); // }); } static ChangeTableFormat(Item: any, custom: boolean, txt: string) { if (txt === 'New') { return [{ image: this.textToBase64Barcode(Item.MPN, custom), alignment: 'center' }, { alignment: 'center', marginTop: 10, columns: [{ text: 'GSM : ' + Item.GSM, bold: true, marginTop: 25 }, { stack: [{ text: 'QC : Ok', bold: true, lineHeight: 1.7 }, { text: 'Mil : ' + Item.Mil, bold: true }] }] }, { alignment: 'center', marginTop: 10, stack: [{ text: 'SIZE(mm) : ' + Item.Size, bold: true, lineHeight: 1.7 }, { text: 'GROSS Wt(kg) : ' + Item.GWt, bold: true, lineHeight: 1.7 }, { text: 'Net Wt(kg) : ' + Item.NWt, bold: true, lineHeight: 1.7 }, { text: 'No.of Joins : 2', bold: true, lineHeight: 1.7 } ] }] } else { return { stack: [{ image: this.textToBase64Barcode(Item.MPN, custom), alignment: 'center' }, { style: 'tableExample', marginLeft: custom ? 110 : 137, marginTop: 20, table: { marginTop: 10, widths: [50, 50], body: [[{ text: 'QC', lineHeight: 2 }, { text: '' }]] } }, this.TableCreation(Item) ] } } } static TableCreation(Item: any) { return { style: 'tableExample', // marginRight: 5, table: { widths: ['auto', '*', '*', '*'], body: [ [{ text: 'GSM', lineHeight: 2 }, { text: Item.GSM }, { text: 'Mil' }, { text: Item.Mil }], [{ text: 'Item Desc', lineHeight: 2 }, { text: Item.Desc, colSpan: 3 }, {}, {}], // [{ text: 'Bar Code' }, { image: this.textToBase64Barcode(Item.MPN), colSpan: 3 }, {}, {}], [{ text: 'SIZE(mm)', lineHeight: 2 }, { text: Item.Size, colSpan: 3 }, {}, {}], [{ text: 'Gross Wt(Kg)', lineHeight: 2 }, { text: Item.GWt, colSpan: 3 }, {}, {}], [{ text: 'Net Wt (Kg)', lineHeight: 2 }, { text: Item.NWt, colSpan: 3 }, {}, {}], [{ text: 'No.of Joints', lineHeight: 2 }, { text: '', colSpan: 3 }, {}, {}], ] } } } static textToBase64Barcode(text: any, custom: boolean) { var canvas = document.createElement("canvas"); JsBarcode(canvas, text, { displayValue: true, height: 40, width: 1 }); return canvas.toDataURL("image/png"); } }