Download PDF is not rendering the complete list of data from ngFor using html2canvas

血红的双手。 提交于 2019-12-04 06:32:34

问题


I have the below code to download the elements in ngFor as a PDF . My html is a array list of data information rendered using ngFor . I have a downloadPDF function written which accepts the id as a parameter and loops through the array list and has to save entire loop of array data as PDF when I click on the downloadPDF button. I am not sure why its saving only the first element from the array finalArList . I have attached the JSON response of finalArList and also the pdf file for reference. Any help on this would be really helpful . I am posting this after lot many tries.enter image description here

downloadPDF() {
       html2canvas(document.getElementById('testDiv')).then(function(canvas) {
      const img = canvas.toDataURL('image/png');
      const doc = new jsPDF();
      doc.addImage(img, 'JPEG', 5, 5);
      doc.save('testCanvas.pdf');
      });
    }


HTML:

     <div id="testDiv" *ngFor="let finalArList of finalArList">
                            <div>
                            <h3>
                              {{finalArList.dischargeDate}} </h3>
                            <div>
                              <div>
                                <div>
                                  <label>Case number:</label>
                                </div>
                                <div>
                                  <span>{{finalArList.caseNo}}</span>
                                </div>
                              </div>
                              <div>
                                <div>
                                  <label>Patient:</label>
                                </div>
                                <div>
                                  <span>{{finalArList.patientName}}</span>
                                </div>
                              </div>
                              <div>
                                <div>
                                  <label>Hospital:</label>
                                </div>
                                <div>
                                  <span>{{finalArList.instName}}</span>
                                </div>
                              </div>
                              <div>
                                <div>
                                  <label>Payee:</label>
                                </div>
                                <div>
                                  <span></span>
                                </div>
                              </div>
                              <div>
                                <div>
                                  <label>Total Doctor Fee:</label>
                                </div>
                                <div>
                                  <span>{{finalArList.formattedTotalDrFee}}</span>
                                </div>
                              </div>
                              <div>
                                <div>
                                  <label>To be Collected:</label>
                                </div>
                                <div>
                                  <span>{{finalArList.formattedDrFeeToCollect}}</span>
                                </div>
                              </div>
                              <div>
                                <div>
                                  <label>Payor:</label>
                                </div>
                                <div>
                                  <span>{{finalArList.payor}}</span>
                                </div>
                              </div>
                              <div>
                                <div>
                                  <label>Remarks:</label>
                                </div>
                                <div>
                                  <span>{{finalArList.remark}}</span>
                                </div>  
                              </div>
                              <div>
                                <div>
                                  Paid
                                  <span></span>
                                </div>
                                <div>
                                  Unpaid
                                  <span>{{finalArList.formattedUnpaidAmounr}}</span>
                                </div>
                              </div>                          
                              <div>
                                <button>View Payment Details</button>
                              </div>
                            </div>
                          </div>
    </div>

     <button type="button"(click)="downloadPDF()">Download in PDF</button>

When i do like this html2canvas(document.getElementById('myTable')).then(function (canvas) { console.log('canvas', +canvas); I am getting NaN.

However, if I hover on top of canvas I get a list of objects attached in screennshot for reference.

来源:https://stackoverflow.com/questions/50018124/download-pdf-is-not-rendering-the-complete-list-of-data-from-ngfor-using-html2ca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!