jsPDF is generating a single page pdf and removing the other information

218
August 01, 2017, at 7:36 PM

I need to export a specific div into pdf. I am using jsPDF library.

$(function () { 
 
  $('#pdf_this').click(function () { 
    var doc = new jsPDF(); 
 
    doc.addHTML($('#print_div')[0], 15, 15, { 
      'background': '#fff', 
    }, function() { 
      doc.save('patient_profile.pdf'); 
    }); 
  }); 
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.debug.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
<div class="container" id="print_div"><button id="print_this" name="print_this" class="btn btn-danger pull-right"><i class="fa fa-print"></i></button><button id="pdf_this" name="print_this" class="btn btn-danger pull-right" style="margin-right: 5px"><i class="fa fa-download"></i></button> 
  <div class='row justify-content-md-center'> 
    <div class='col-sm-8'> 
      <div class='row'> 
        <table class='table table-bordered table-hover table-responsive'> 
        <tr class='bg-info'> 
          <th colspan='6'>A. General Information</th> 
        </tr> 
          <tr> 
            <th>Clinic ID: </th> 
            <td colspan='2'></td> 
            <th>Patient ID: </th> 
            <td><?php echo $_REQUEST['pid'] ?></td> 
          </tr> 
          <tr> 
            <th>Patient Name: </th> 
            <td colspan='2' style='width: 100%'></td> 
            <th>Current Status: </th> 
            <td><?php echo $getInfoResult['patient_status'] ?></td> 
          </tr> 
          <tr> 
            <th>D.O.B: </th> 
            <td colspan='2'><?php echo $getInfoResult['dob'] ?></td> 
            <th>Date Of Registration: </th> 
            <td><?php echo $getInfoResult['registration_date'] ?></td> 
          </tr> 
          <tr> 
            <th>Gender: </th> 
            <td colspan='2'><?php echo $getInfoResult['gender'] ?></td> 
            <th>Phone Number: </th> 
            <td><?php echo $getInfoResult['pphone'] ?></td> 
          </tr> 
          <tr> 
            <th class='bg-info' colspan='6'>B. Status Changed History: </th> 
          </tr> 
          <tr> 
            <th colspan='2'>Status</th> 
            <th colspan='3'>Date Of Change</th> 
          </tr> 
          <?php foreach($statRes as $res) { ?> 
          <tr> 
            <td colspan="2"><?php echo $res['patient_status'] ?></td> 
            <td colspan="3"><?php echo $res['status_date'] ?></td> 
          </tr> 
          <?php } ?> 
          <tr> 
            <th class="bg-info" colspan="6">C. Smoking History: </th> 
          </tr> 
          <tr> 
            <th colspan="2">Answer</th> 
            <th colspan="2">Nbr of Cigarettes/day</th> 
            <th colspan="2">Date Of Answer</th> 
          </tr> 
          <?php foreach($smokingRes as $res2) { ?> 
            <tr> 
              <td colspan="2"><?php echo $res2['patient_smoker'] ?></td> 
              <td colspan="2"><?php echo $res2['smoker_number_of_packets'] ?></td> 
              <td colspan="2"><?php echo $res2['date_of_edit'] ?></td> 
            </tr> 
          <?php } ?> 
          <tr> 
            <th class="bg-info" colspan="6">D. Alcohol History: </th> 
          </tr> 
          <tr> 
            <th colspan="3">Answer</th> 
            <th colspan="3">Date Of Answer</th> 
          </tr> 
          <?php foreach($alcoholRes as $res3) { ?> 
          <tr> 
            <td colspan="3"><?php echo $res3['alcohol'] ?></td> 
            <td colspan="3"><?php echo $res3['date_of_edit'] ?></td> 
          </tr> 
          <?php } ?> 
          <tr> 
            <th class="bg-info" colspan="6">E. Family Diseases History: </th> 
          </tr> 
          <tr> 
            <td colspan="6"><?php echo $familyRes['diagnosis'] ?></td> 
          </tr> 
          <tr class="bg-info" > 
            <th colspan="6" >F. Visits Information (Total of <?php echo $count ?>)</th> 
          </tr> 
          <?php if($count>0) { ?> 
            <tr> 
              <th>Number</th> 
              <th>Date of the visit</th> 
              <th>Weight (Kg)</th> 
              <th>BMI</th> 
              <th>BMI Result</th> 
            </tr> 
          <?php } foreach($visitRes as $res4) { ?> 
            <tr> 
              <td><a href="visit_profile_page.php?pid=<?php echo $res4['patient_id'] ?>&vid=<?php echo $res4['visit_id'] ?>" ><?php echo $count-- ?></a></td> 
              <td><?php echo $res4['date_of_visit'] ?></td> 
              <td><?php if($res4['patient_weight']==0){ echo "N/A";} else { echo $res4['patient_weight']; } ?></td> 
              <td><?php if($res4['patient_weight']==0){ echo "N/A"; $resBmi =0; } else { $heightM = pow(($res4['patient_height']/100), 2); $bmi = ($res4['patient_weight']/$heightM); echo $resBmi = number_format($bmi, 3, '.', ' '); } ?></td> 
              <td><?php if($res4['patient_weight']==0) { echo "N/A"; } if($resBmi ==0){echo "";} if($resBmi>0 && $resBmi<18.5){echo $resCal="Underweight";}  if($resBmi>=18.5 && $resBmi<25){echo $resCal="Normal Weight";} if($resBmi>=25 && $resBmi<=29.9){echo $resCal = "Overweight";} if($resBmi>=30){echo $resCal = "Obese";}  ?></td> 
            </tr> 
          <?php } ?> 
          <tr class="bg-info"> 
            <th colspan="6">G. Previously Identified Diseases by NCD (Total of <?php echo $countDiag ?>)</th> 
          </tr> 
          <tr> 
          <?php foreach($diagRes as $res5) { ?> 
            <tr> 
              <td colspan="2"><?php echo $countDiag-- ?></td> 
              <td colspan="4"><?php echo $res5['diagnosis_name'] ?></td> 
            </tr> 
          <?php } ?> 
          </tr> 
          <tr class="bg-info"> 
            <th colspan="6">H. Patient Previous Medication (Total of <?php echo $countMed ?>)</th> 
          </tr> 
          <?php if($countMed!=0){ ?> 
          <tr> 
            <th colspan="3">Disease</th> 
            <th>Medication</th> 
            <th colspan="2">Side Effect</th>   
          </tr> 
          <?php } ?> 
          <?php foreach($medRes as $res6) { ?> 
            <td colspan="3"><?php echo $res6['disease'] ?></td> 
            <td><?php echo $res6['patient_medication'] ?></td> 
            <td colspan="2"><?php echo $res6['patient_side_effect'] ?></td> 
          <?php } ?> 
          <tr class="bg-info"> 
            <th colspan="6">I. Allergies On Medications (Total of <?php echo $countAllergy ?>)</th> 
          </tr> 
          <?php if($countAllergy!=0){ ?> 
          <tr> 
            <th colspan="2">Medication</th> 
            <th colspan="2">Side Effect</th> 
            <th colspan="2">Extra Information</th> 
          </tr> 
          <?php } foreach($getAllergyHistoryResult as $res7) { ?> 
          <tr> 
            <td colspan="2"><?php echo $res7['patient_allergy_med'] ?></td> 
            <td colspan="2"><?php echo $res7['med_side_effect'] ?></td> 
            <td colspan="2"><?php echo $res7['comment'] ?></td> 
          </tr> 
          <?php } ?> 
          <tr class="bg-info"> 
            <th colspan="6">J. Surgical History (Total of <?php echo $countSurgery ?>)</th> 
          </tr> 
          <?php if($countSurgery!=0){ ?> 
          <tr> 
            <th colspan="2">Surgery</th> 
            <th colspan="2">Date</th> 
            <th colspan="2">Extra Information</th> 
          </tr> 
          <?php } foreach($getSurgeryHistoryResult as $res8) { ?> 
          <tr> 
            <td colspan="2"><?php echo $res8['patient_surgery'] ?></td> 
            <td colspan="2"><?php echo $res8['surgery_date'] ?></td> 
            <td colspan="2"><?php echo $res8['comment'] ?></td> 
          </tr> 
          <?php } ?> 
        </table> 
      </div> 
    <!-- End of class col-sm-6 --> 
    </div>

The problem is that when the pdf is generated, when the div extend into multiple pdf page, the pdf generated is only one page and the other information are not included.

Rent Charter Buses Company
READ ALSO
Select elements for javascript by selector?

Select elements for javascript by selector?

I want to select this one with jquery:single-product >

343
Conditional formatting in html table

Conditional formatting in html table

I have done conditional formatting using jquery in a HTML tableIt is working fine on the 1st page of datatable, but from the 2nd page, it is not working

330
JQuery - How to check if input is comming from keyboard or not?

JQuery - How to check if input is comming from keyboard or not?

How can I check if input is coming from script or is inputed from keyboard to the textarea?

326
Splitting up my objects into three select boxes with different values

Splitting up my objects into three select boxes with different values

My current calculator needs to be split up into three category groups (Interest Free credit, buy now pay later & classic credit)Currently I am obtaining one list with all the options in the 1st select box using json

215