0

enter image description hereenter image description hereI 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 senter image description hereure 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.

enter image description here

Nancy
  • 911
  • 7
  • 26
  • 54
  • Any comments for my question? – Nancy Apr 25 '18 at 12:01
  • Guys !! any solutions pls . I tried to change the id to classname , but i am facing typecast error. – Nancy Apr 25 '18 at 13:50
  • Hi Again :) ! the question, as is, is far from providing enough information. Try to imagine, like us, that you know nothing about your project. now, do you understand your own question or know where the problem might be coming from? I don't, for instance, know what a full list of data would look like nor what an incomplete data set looks like. And we are talking about the data in the pdf, right? what about a console.log of the returned data from the API, is the data complete at least at this step or did the loss happen before? – tatsu Apr 26 '18 at 08:08
  • @tatsu I have edited my question with response and more details. – Nancy May 18 '18 at 15:19
  • in that `then(function(canvas) {` console.log `canvas` see what you get. and add it to your question. – tatsu May 19 '18 at 10:29
  • @tatsu i have updated the question with canvas log – Nancy May 20 '18 at 06:30
  • @tatsu any update? – Nancy May 20 '18 at 20:02
  • well Not a number is because you put `+` don't put `+` you already have `,` plus you don't wanna add – tatsu May 21 '18 at 12:35
  • Anyways I have attached the screen shot of canvas object. Could you pls check that one – Nancy May 22 '18 at 16:07
  • does it have a `data` child? – tatsu May 24 '18 at 16:31

0 Answers0