I have a jspdf code that is already working but i want to change it and use a loop to print array data and i'm not sure how to implement in a correct way.Below ill share my jspdf code
downloadPDF(isSubmit:any) {
debugger
let doc = new jsPDF();
let rows: Array<any> = [];
let medicineInfo: any;
let physicianInfo: any;
doc.page = 1;
var col = ["Test Name", "Result", "Unit" , "Reference"];
this.hubxDataItemSpList.forEach((a) => {
medicineInfo = this.hubxDataItemSpList.find(x => x.id == a.id);
rows.push(['' + a.itemTitle + '', '' + a.itemValue + '', '' + a.itemUnit ]);
});
if (this.prescriptionModel.id > 0) {
if (this.reportCommonData != null) {
doc.setProperties({title: "Prescription Report"});
doc.setFont("bold");
doc.setFontSize(16);
doc.text(15, 20, "Prescription Report");
doc.setFontSize(10);
doc.setFont("bold");
doc.text(140, 20, "Provider Details:");
doc.setFont("normal");
doc.text(140, 25, "Name: " + this.reportCommonData.organizationName);
doc.text(140, 30, "Address: " + this.reportCommonData.address);
doc.text(140, 35, "Phone: " + this.reportCommonData.phone);
doc.text(140, 40, "Email: " + this.reportCommonData.email);
doc.setFont("bold");
doc.text(15, 35, "Patient Details:");
doc.setFont("normal");
doc.text(15, 40, "Name: " + this.reportCommonData.firstName + " " + this.reportCommonData.lastName);
doc.text(15, 45, "MRN: " + this.reportCommonData.patientMRN);
doc.text(15, 50, "Email: " + this.reportCommonData.patientEmail);
doc.text(15, 55, "Phone: " + this.reportCommonData.patientPhone);
doc.setFont("bold");
doc.text(140, 50, "Physician Details:");
doc.setFont("normal");
doc.text(140, 55, "Name: " + physicianInfo.firstName + " " + physicianInfo.lastName);
doc.text(140, 60, "NPI Number: " + physicianInfo.npiNumber);
doc.text(140, 65, "Phone: " + physicianInfo.phoneNumber);
doc.setFont("bold");
doc.text(15, 65, 'Pharmacy Details:');
doc.setFont("normal");
doc.text(15, 70, "Name: " + this.PharmacyInfo.pharmacyName);
doc.text(15, 75, "Address: " + this.PharmacyInfo.address1);
doc.text(15, 80, "City: " + this.PharmacyInfo.city);
doc.text(15, 85, "Email: " + this.PharmacyInfo.email);
doc.text(15, 90, "Phone:" + this.PharmacyInfo.phone);
doc.text(15, 95, "Prescription Date: " + this.datePipe.transform(this.prescriptionModel.createdDate, 'M/d/yyyy, h:mm a'));
doc.autoTable({
columnStyles: {
0: { cellWidth: 120 },
1: { cellWidth: 40 },
2: { cellWidth: 20 }
},
head: [col],
body: rows,
startY: 100,
theme: 'plain',
tableLineColor: [242, 238, 238],
tableLineWidth: 0.5,
styles: {
font: 'courier',
lineColor: [242, 238, 238],
lineWidth: 0.5
},
});
doc.setFont("bold");
doc.setFontSize(7);
doc.text(15,260, "xyz");
doc.setFont("normal");
doc.text(15,265, "xyz");
doc.text(15,270, "xyz ");
doc.text(15,275, "xyz.");
doc.setFont("bold");
doc.text(65,280,"xyz");
doc.setFontSize(5);
doc.setFont("normal");
doc.text(180, 285,'Powered by xyz');
if(!isSubmit){
window.open(doc.output('bloburl'))
}else{
this.fileList.push({
data: doc.output('datauristring'),
ext: 'pdf'
});
}
}
}
}
and below this code ill share a code that i want to pull this logic to the above code. i want to loop the autptable as the same ways im looping at the below code.
<div *ngFor="let hubxReport of hubxReportList; let i=index">
<div>{{hubxReport.categoryName}}</div>
<div *ngFor="let item of hubxReport.hubxDataItems">
<div>{{item.itemTitle}} {{item.itemValue}} {{item.itemUnit}}
</div>
</div>
i want to loop the above jspdf code the same way im looping in this html code.is it possible to implement. I'm new to angular.thanks
and the loop that i tried
let col1 = [];
let rows = [];
for(let i = 0; i < this.hubxDataItemSpList[0].categoryName.length; i++)
{
col1.push(this.hubxDataItemSpList[0].categoryName)
i++;
for(let j = 0; j < this.hubxDataItemSpList.length; j++)
{
rows.push(this.hubxDataItemSpList[0].itemTitle,this.hubxDataItemSpList[0].itemValue,this.hubxDataItemSpList[0].itemUnit)
}
}