2016-12-05 69 views
0

这是我的下列操作以生成的PDF一段代码DOMPDF生成的PDF结果得到弄乱

$values = $Viewer->getPrintData($_GET['id']); 

if($values->num_rows > 0){ 
    $html_data = ""; 
    while($row = $values->fetch_assoc()){ 
     switch($row['birth_type_id']) 
     { 
      case 1: $hospital_id = $row['hospital_id']; 
        $home_detail = "None"; 
        $other_detail = "None"; 
        $birth_formatted_type = "Birth at : ".$Viewer->getHospitalName($row['hospital_id']); 
        break; 

      case 2: $hospital_id = "None"; 
        $home_detail = $row['home_detail']; 
        $other_detail = "None"; 
        $birth_formatted_type = "|| Birth at Home || <br />Home Details Are : ".$row['home_detail']; 
        break; 

      case 3: $hospital_id = "None"; 
        $home_detail = "None"; 
        $other_detail = $row['other_detail']; 
        $birth_formatted_type = "|| Birth at Other Location || <br />Details Are : ".$row['other_detail']; 
        break; 

      default: 
        $hospital_id = "None"; 
        $home_detail = "None"; 
        $other_detail = "None"; 
        break; 
     } 

     $html_data .= " 
        <html> 
          <head> 
           <style> 
            * 
              { 
               font-family: 'oswald'; 
              } 
            @page 
              { 
               margin: 10px; 
              } 
            body, table 
              { 
               margin: 10px; 
              } 
           </style> 
          </head> 
          <body> 
           <br /> 
           <center> 
            <h2> 
              Birth Certificate Details 
            </h2> 
           </center> 
           <div style='width: 100%;'> 
            <table> 
              <tr> 
               <td style='width: 350px;'> 
                <u> 
                  <h3>Baby Related Details</h3> 
                </u> 
                Registration Number: ".$row['registration_number']."<br /> 
                Birth Date: ".$row['birth_date']."<br /> 
                Birth Time: ".$row['birth_time']."<br /><br /> 
                Gender: ".$Viewer->getGender($row['gender_id'])."<br /> 
                Baby's Full Name: ".$row['baby_name']."<br /> 
                Father's Full Name: ".$row['fathers_name']."<br /> 
                Father's Aadhar ID: ".$row['fathers_uid']."<br /> 
                Mother's Full Name: ".$row['mothers_name']."<br /> 
                Mother's Aadhar ID: ".$row['mothers_uid']."<br /> 
                While Baby's Birth Parents Address: ".$row['while_baby_birth_parents_address']."<br /> 
                Parent's Permanent Address: ".$row['parents_permanent_address']."<br /> 
               </td> 
               <td style='width: 350px;'> 
                <u> 
                  <h3>Parents Details</h3> 
                </u> 
                {$birth_formatted_type}<br /> 
                Religion: ".$row['religion']."<br /><br /> 
                Taluka: ".$Viewer->getTalukaDetail($row['taluka_id'])."<br /> 
                City: ".$Viewer->getCityDetail($row['city_id'])."<br /> 
                Pincode: ".$Viewer->getPincodeDetail($row['pincode_id'])." 
                <br /><br /> 
                Father's Education Level: ".$Viewer->getEducationLevel($row['id_of_fathers_education_level'])."<br /> 
                Mother's Education Level: ".$Viewer->getEducationLevel($row['id_of_mothers_education_level'])."}<br /> 
                Father's Occupation: ".$Viewer->getOccupationDetail($row['id_of_fathers_occupation'])."<br /> 
                Mother's Occupation: ".$Viewer->getOccupationDetail($row['id_of_mothers_occupation'])." 

                <u> 
                  <h3><br />Other Details</h3> 
                </u>  
                Mother's Marriage Age: ".$row['mothers_marriage_age']."<br /> 
                While Baby's Birth Mother's Age: ".$row['while_birth_mothers_age']."<br /> 
                Alive Deliveries Upto Now: ".$row['total_alive_deliveries_uptill_date']."<br /><br /> 
                Birth Place/Person: ".$Viewer->getBirthPlaceOrPerson($row['id_of_birth_place_person'])."<br /> 
                Mother's Delivery Type: ".$Viewer->getDeliveryType($row['id_of_delivery_type'])."<br /> 
                Child's Weight: ".$row['child_weight_while_birth']."<br /> 
                Pregnancy Duration: ".$row['pregnancy_duration']." 
               </td> 
              </tr> 
            </table> 
           </div> 
          </body> 
        </html>"; 
    } 

    require "../dompdf/dompdf_config.inc.php"; 
    $dompdf = new DOMPDF(); 
    $dompdf->load_html($html_data); 
    $dompdf->render(); 
    $dompdf->stream("PD_.pdf"); 
} 

我有具有各自的页上打印29个条目的总数目。问题是被打印在页面上时,第一结果是它是从上病房结果被混乱第二页精细如下

打印第一页

Print of 1st page

的所示的图像中从第2页生成的病房打印正在这样

Print being generated from 2nd page on wards

请人帮忙。

+0

当内容在页面之间分裂时,您的HTML结构可能会崩溃。你应该确保你提供给dompdf的HTML验证。除此之外,很难说没有看到实际的HTML dompdf正在处理的样本(与生成HTML的PHP​​相比)。 – BrianS

+0

但我会说,你将多个HTML文档连接成一个文档。您可以尝试移动“while”循环之外的所有非正文内容。 – BrianS

回答

0

我在dompdf上也遇到了一些麻烦,最后我们决定使用https://github.com/KnpLabs/snappy - 这对于创建新的pdf格式非常有用,在将html转换为pdf格式时效果更好。

$template = $this->twig->loadTemplate($data['template']); 
    $rendered = $template->renderBlock('bodyHtml', ['data' => $data['data']]); 

    return $this->snappy->getOutputFromHtml($message); 

也许这会对你更好。