//(function () { angular.module('MobileWebLogistics') .service('localCustom', function () { var self = this; //======custom create report var pdf, parcelImg, isParcelImg, parcelMap, isParcelMap, imgwidth1, imgwidth2, imgwidth3; var imgheight1, imgheight2, imgheight3; var availSpace = 270; var defaultTop = 28; var page = 1; this.createPDF = function ($scope, parcelImgUrl) { //alert("bb"); parcelImg = new Image(); parcelImg.setAttribute('crossOrigin', 'anonymous'); var parcelImgUrl1 = parcelImgUrl.toString(); parcelImg.onload = function () { isParcelImg = true; }; parcelImg.onerror = function () { isParcelImg = false; }; parcelImg.src = parcelImgUrl; parcelImg.src = parcelImgUrl1 + "?"; setTimeout(function () { var img1; pdf = new jsPDF('portrait', 'mm', 'letter', true); var margins = { top: 15, bottom: 60, left: 20, width: 520 }; //adding report self.addTable1($scope); }, 500); } this.addHeader = function ($scope) { try { pdf.addImage('headerImg', 'PNG', 15, 8, 71.7 * 0.861, 22.49 * 0.861); } catch (err) { pdf.addImage($scope.headerData, 'PNG', 15, 8, 71.7 * 0.861, 22.49 * 0.861, 'headerImg'); } pdf.setFont("arial"); pdf.setTextColor(0, 0, 0); pdf.setFontSize(10); pdf.textEx($scope.pdfHeaderTxt1, 194, 13, 'right', 'middle'); pdf.textEx('Email: gis@highlandcova.org', 193, 18, 'right', 'middle'); pdf.textEx($scope.pdfHeaderTxt2, 192, 23, 'right', 'middle'); pdf.setLineWidth(0.4); pdf.setDrawColor(0, 0, 0); pdf.line(37, 25, 198, 25); } this.addFooter = function (pidtxt, pid, page) { pdf.setLineWidth(0.4); pdf.setDrawColor(220, 220, 220); pdf.line(15, 260, 198, 260); pdf.setFont("arial"); pdf.setTextColor(100, 100, 100); pdf.setFontSize(10); if (pidtxt.trim().length > 0) { pdf.text(16, 265, pidtxt + pid); } pdf.text(183, 265, page + ' | Page'); } this.imageExists = function ($scope, url, callback) { var img = new Image(); img.setAttribute('crossOrigin', 'anonymous'); var parcelImgUrl1 = url.toString(); img.onload = function () { callback(true); }; img.onerror = function () { callback(false); }; img.src = url; img.src = parcelImgUrl1 + "?"; //for chrome just in case return; } this.getReportImages = function ($scope, pid) { //alert(pid); if ($scope.propertyImg != 'false') { if (pid == 1 && isParcelImg == true) { $scope.reportImages.push(parcelImg); } var checkMore = true; var moreImg; var nextPid = parseInt(pid) + 1; var moreImgUrl = parcelImg.src.replace('_1.jpg', '_' + nextPid + '.jpg'); var k = 2; self.imageExists($scope, moreImgUrl, function (exists) { if (exists) { self.getReportImages($scope, pid + 1) } else { self.addImages($scope); } }); } else { self.addImages($scope); } } this.addImages = function ($scope) { if ($scope.propertyImg == 'false') { isParcelImg = false; } var imgLoc; var j; if ($scope.reportImages.length > 0) { self.addFooter($scope.parcelpdfID[0], $scope.selectedParcel[$scope.parcelpdfID[1]], page); page += 1; imgLoc = 30; pdf.addPage(); self.addHeader($scope); } for (j = 0; j < $scope.reportImages.length; j++) { var imgW = $scope.reportImages[j].width / ($scope.reportImages[j].width / 140); var imgH = $scope.reportImages[j].height / ($scope.reportImages[j].width / 140); if (imgLoc + imgH > availSpace) { self.addFooter($scope.parcelpdfID[0], $scope.selectedParcel[$scope.parcelpdfID[1]], page); page += 1; imgLoc = 30; pdf.addPage(); self.addHeader($scope); } pdf.addImage($scope.reportImages[j], 'JPEG', 35, imgLoc, imgW, imgH, 'house' + j); imgLoc = imgLoc + imgH + 10; if ($scope.multipleReportImages != 'true') { j = 1000; } } self.addFooter($scope.parcelpdfID[0], $scope.selectedParcel[$scope.parcelpdfID[1]], page); pdf.save('Parcel_report.pdf'); $("#pdfPreloaderContainer").removeClass("active"); page = 1; } var tblNum = 1; this.addTable1 = function ($scope) { self.addHeader($scope); pdf.setFont("arial"); pdf.setTextColor(80, 80, 80); pdf.setFontSize(16); pdf.text(17, 42, $("#propertyAddr").html()); html2canvas($("#reportBody > #reportTbl_1"), { onrendered: function (canvas1) { var imgData1 = canvas1.toDataURL('image/png'); imgwidth1 = canvas1.width * 0.227; // This will print out the width. imgheight1 = canvas1.height * 0.23; pdf.addImage(imgData1, 'PNG', 16, 45, imgwidth1, imgheight1); nextTblLoc = imgheight1 + 45; tblNum = 2; if (tblNum > $scope.numOfTable) { $scope.reportImages = []; self.getReportImages($scope, 1); } else { self.addAdditionalTable($scope); } } }); } this.addAdditionalTable = function ($scope) { html2canvas($("#reportBody > #reportTbl_" + tblNum), { onrendered: function (canvas2) { var imgData2 = canvas2.toDataURL('image/png'); imgwidth2 = canvas2.width * 0.227; // This will print out the width. imgheight2 = canvas2.height * 0.23; if (nextTblLoc + imgheight2 > availSpace) { //add page and nextTblLoc=35 self.addFooter($scope.parcelpdfID[0], $scope.selectedParcel[$scope.parcelpdfID[1]], page); page += 1; pdf.addPage(); self.addHeader($scope); nextTblLoc = defaultTop; pdf.addImage(imgData2, 'PNG', 16, nextTblLoc, imgwidth2, imgheight2); nextTblLoc += imgheight2; } else { pdf.addImage(imgData2, 'PNG', 16, nextTblLoc, imgwidth2, imgheight2); nextTblLoc = nextTblLoc + imgheight2; } tblNum += 1; if (tblNum > $scope.numOfTable) { $scope.reportImages = []; self.getReportImages($scope, 1); } else { self.addAdditionalTable($scope); } } }); } //======end of custom create report }); //})();