import JsBarcode from 'jsbarcode'; import { SharedPDFService } from '../../shared/shared-pdf.service'; import { TrUtils } from '../../utils/tr-utils'; declare var pdfMake: any; export class ItemBarCodeLabelPdf { 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: 15, x2: 372.95275591, y2: 15, lineWidth: 1 }, //Up line { type: 'line', x1: 5, y1: 15, x2: 5, y2: 550.92913386, lineWidth: 1 }, //Left line { type: 'line', x1: 5, y1: 550.92913386, x2: 372.95275591, y2: 550.92913386, lineWidth: 1 }, //Bottom line { type: 'line', x1: 372.95275591, y1: 15, x2: 372.95275591, y2: 550.92913386, 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, 20, 10, 20], pageSize: { width: 377.95275591, height: 566.92913386 }, content: [ // SharedPDFService.MainHeading(CheckListData.Entity.CName, CheckListData.Entity.Header, CheckListData.Image, CheckListData.HColor, null), // SharedPDFService.GetPrintType('INSPECTION'), // SharedPDFService.HeaderAfterLine(), this.ChangeTableFormat(Item.Item, custom, txt), {stack: [SharedPDFService.MainHeading(Item.Entity.CName, Item.Entity, Image, Item.AColor, null)], marginTop:15}, {stack: [this.GetHeader(Item.Entity, Item.HColor)], marginTop:15} // 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 GetHeader(Entity: any, HColor: string) { let headerstyle: string; if (Entity.Header === 1) { headerstyle = 'ws_adrs_center'; } else { headerstyle = 'ws_adrs_left'; } let SubHeader: any = [ { text: '' + Entity.Adrs1 + '', style: [headerstyle], fontSize:10 }, { text: '' + Entity.City + SharedPDFService.getPinCode(Entity.PIN) + ', ' + 'Ph: ' + Entity.Phone, style: headerstyle, fontSize:10 }, { text: '' + SharedPDFService.GetEmail(Entity.Email) + '', style: headerstyle, fontSize:10 }, // { text: 'GSTIN:' + Entity.GSTIN + ', ' + 'PAN: ' + Entity.PAN, style: headerstyle }, ]; if (!TrUtils.IsEmpty(Entity.Adrs2)) { SubHeader.splice(1, 0, { text: '' + Entity.Adrs2 + '', style: [headerstyle], fontSize:10 }); } // if (!TrUtils.IsEmpty(Entity.TLine)) { // SubHeader.unshift({ text: this.GetTagLine(Entity.TLine), fontSize: 10, bold: true, color: HColor, margin: [0, 0, 0, 2] }); // } // if (!TrUtils.IsEmpty(Entity.GSTIN) || !TrUtils.IsEmpty(Entity.PAN)) { // let Data: any = ''; // if (!TrUtils.IsEmpty(Entity.GSTIN)) { // Data = 'GSTIN:' + Entity.GSTIN; // } // if (!TrUtils.IsEmpty(Entity.GSTIN) && !TrUtils.IsEmpty(Entity.PAN)) { // Data = Data + ', '; // } // if (!TrUtils.IsEmpty(Entity.PAN)) { // Data = Data + 'PAN:' + Entity.PAN; // } // SubHeader.push({ text: Data, style: headerstyle, fontSize: this.TermsandCond }); // } // if (Entity.GSTType === 2) { // SubHeader.push({ text: '* under composition scheme', fontSize: this.TermsandCond }); // } return SubHeader; } static ChangeTableFormat(Item: any, custom: boolean, txt: string) { if (txt === 'New') { return [{ svg: this.textToSvgBarcode(Item.MPN).svg, 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: [{ svg: this.textToSvgBarcode(Item.MPN).svg, alignment: 'center', marginTop: 20}, { style: 'tableExample', marginLeft: custom ? 180 : 238, marginTop: 20, fontSize:10, table: { marginTop: 15, widths: [50, 50], body: [[{ text: 'QC', marginTop:7, marginBottom:7 }, { text: '' , marginTop:7, marginBottom:7}]] } }, this.TableCreation(Item) ] } } } static TableCreation(Item: any) { return { style: 'tableExample', // marginRight: 5, fontSize:10, table: { widths: ['auto', '*', '*', '*'], body: [ [{ text: 'GSM', marginTop:7, marginBottom:7}, { text: Item.GSM, marginTop:7, marginBottom:7 }, { text: 'Mil',marginTop:7, marginBottom:7 }, { text: Item.Mil,marginTop:7, marginBottom:7 }], [{ text: 'Item Desc', marginTop:7, marginBottom:7 }, { text: Item.Desc, colSpan: 3,marginTop:7, marginBottom:7 }, {}, {}], // [{ text: 'Bar Code' }, { image: this.textToBase64Barcode(Item.MPN), colSpan: 3 }, {}, {}], [{ text: 'SIZE(mm)', marginTop:7, marginBottom:7 }, { text: Item.Size, colSpan: 3,marginTop:7, marginBottom:7 }, {}, {}], [{ text: 'Gross Wt(Kg)', marginTop:7, marginBottom:7 }, { text: Item.GWt, colSpan: 3 ,marginTop:7, marginBottom:7}, {}, {}], [{ text: 'Net Wt (Kg)', marginTop:7, marginBottom:7}, { text: Item.NWt, colSpan: 3,marginTop:7, marginBottom:7 }, {}, {}], [{ text: 'No.of Joints', marginTop:7, marginBottom:7 }, { text: Item.Join, colSpan: 3,marginTop:7, marginBottom:7 }, {}, {}], ] } } } static textToSvgBarcode(text: string): any { const svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg"); JsBarcode(svgElement, text, { format: "CODE128", width:1.25, height:80 }); return { svg: svgElement.outerHTML }; } static textToBase64Barcode(text: any, custom: boolean) { var canvas = document.createElement("canvas"); JsBarcode(canvas, text, { displayValue: true, height: 80, width: 1 }); return canvas.toDataURL("image/svg"); } }