2016-04-05 94 views
-2

我是新來的PHP和不知道如何將PHP文件轉換爲PDF格式。將php報告頁面轉換爲PDF格式

我想將下面的代碼轉換爲pdf,但我沒有成功。

請幫助我轉換它,它是一種迫切的。我也附上了我想要轉換的圖像。

<? 
$Section = isset($_GET['Section'])?$_GET['Section']:""; 
?> 


<table border="0" cellpadding="0" cellspacing="0" width="100%"> 
    <div id="loginpanel" > 
    <h3>Performa regarding Contempt Petition ('A'Category) Cases Report</h3> 
    </div> 
<br /> 
<p id="demo" align="right" style="font-size:12px"></p> 

<a href="<?=DIR_WS_SITE_CONTROL?>index.php?Page=pdf"   target="_blank">Download PDF</a> 

<script> 
var d = new Date(); 
document.getElementById("demo").innerHTML = d; 
</script> 

<tr><td><br/></td></tr> 
</table> 

<? 
    //// Section start 
switch($Section) 
{ 
    case "district_report": 
    default: 


$ZoneObj = new DataTable(TABLE_ZONE); 
$ZoneObj->Where = "1"; 
$ZoneObj->TableSelectAll(); 

?> 

<table cellpadding="5" cellspacing="1" border="1" class="TableBorder" style="color:black"> 

    <tr class="InsideLeftTd"> 
     <td width="2%" height="25"><b>S.No</b></td> 
     <td width="10%" align="left"><b>Circle</b></td> 
     <td width="10%" align="left"><b>District</b></td> 
     <td width="8%" align="left"><b>Total no of cases</b></td> 
     <td width="8%" align="left"><b>Total no. of cases where reply filed</b></td> 
     <td width="8%" align="left"><b>No. of cases due for hearing in next 21 days</b></td> 
     <td width="8%" align="left"><b>No. of cases due for hearing in next 21 days(Reply Filed)</b></td> 
     <td width="8%" align="left"><b>No. of cases due for hearing in next 21 days(Reply Not Filed)</b></td> 
    </tr> 
<? 

$SNo=1; 
$Count=1; 
while($CurrentZon=$ZoneObj->GetObjectFromRecord()) 
{ 
    $circleObj = new DataTable(TABLE_CIRCLE); 
    $circleObj->Where = "zone_id='".$CurrentZon->id."'"; 
    $circleObj->TableSelectAll(); 

?> 
<tr> 
    <td colspan="11" align="center"><b><?=MyStripSlashes($CurrentZon->zone);?> Zone</b></td> 
</tr> 


<? while($CurrentCir=$circleObj->GetObjectFromRecord()) 
{ 

    $DistrictObj = new DataTable(TABLE_DISTRICT); 
    $DistrictObj->Where = "circle_id='".$CurrentCir->id."'"; 
    $DistrictObj->TableSelectAll(); 

?> 

<tr class="InsideRightTd"> 

    <td height="25" align="center" style="color:black" rowspan="<?=$DistrictObj->GetNumRows()?>"><?=$SNo?>.</td> 

    <td align="left" style="color:black" rowspan="<?=$DistrictObj->GetNumRows()?>"> 
     <?=MyStripSlashes($CurrentCir->circle);?> 
    </td> 

    <? while($CurrentDis=$DistrictObj->GetObjectFromRecord()) 
    { 

    $ConObj = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj->Where = "district_id='".$CurrentDis->id."'"; 
    $Case_count=$ConObj->TableCountDistinct("id","id_count"); 

    $ConObj2 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj2->Where = "district_id='".$CurrentDis->id."' AND reply_filed='Yes'"; 
    $Reply_count=$ConObj2->TableCountDistinct("id","reply_count"); 

    $ContObj = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ContObj->Where = "district_id='".$CurrentDis->id."' AND date_next_hearing>='".date('Y-m-d')."' AND date_next_hearing <='".date('Y-m-d', strtotime("+21 days"))."'"; 
    $ContObj->TableSelectAll(); 

    $ConObj3 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj3->Where = "district_id='".$CurrentDis->id."' AND date_next_hearing>='".date('Y-m-d')."' AND date_next_hearing <='".date('Y-m-d', strtotime("+21 days"))."' AND reply_filed='Yes'"; 
    $ConObj3->TableSelectAll(); 

    $ConObj4 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj4->Where = "district_id='".$CurrentDis->id."' AND date_next_hearing>='".date('Y-m-d')."' AND date_next_hearing <='".date('Y-m-d', strtotime("+21 days"))."' AND reply_filed='No'"; 
    $Filed_count=$ConObj4->TableCountDistinct("id","next_count"); 

    ?> 
    <td align="center" style="color:black"><?=MyStripSlashes($CurrentDis->district);?></td> 
    <td align="center" style="color:black"><?=MyStripSlashes($Case_count->id_count);?></td> 

    <? if($Reply_count->reply_count!='0'){ 
     $color= (($Reply_count->reply_count)*100)/$Case_count->id_count; 
    }else{ 
     $color = '0'; 
    } 

    if($color=='0'){?> 
     <td align="center" style="color:black"> 
     <?=MyStripSlashes($Reply_count->reply_count)?> 
     </td> 

    <?}elseif($color<=65 & $color>0){?> 

    <td align="center" style="color:black" bgcolor="#F75D59"> 
     <?=MyStripSlashes($Reply_count->reply_count)?> 
    </td> 

    <? }elseif($color>65 && $color<=90){?> 
    <td align="center" style="color:black" bgcolor="#FFFF00"> 
     <?=MyStripSlashes($Reply_count->reply_count)?> 
    </td> 

    <? }elseif($color>90){?> 
    <td align="center" style="color:black" bgcolor="#00FF00"> 
     <?=MyStripSlashes($Reply_count->reply_count)?> 
    </td>   
    <?}?> 

    <td align="center" style="color:black"> 
     <?=MyStripSlashes($ContObj->GetNumRows())?> 
    </td> 

    <td align="center" style="color:black"> 
     <?=MyStripSlashes($ConObj3->GetNumRows())?> 
    </td> 


    <? if($Filed_count->next_count==0){?> 

     <td align="center" style="color:black" bgcolor="#00FF00"> 
     <?=MyStripSlashes($Filed_count->next_count)?> 
     </td> 
     <?}else{?> 
     <td align="center" style="color:black" bgcolor="#F75D59"> 
     <?=MyStripSlashes($Filed_count->next_count)?> 
     </td> 
     <?}?> 

    </tr> 


    <? 
    } 
    $SNo++; 
    $Count++; 

    ////////Circle Total Starts here//////////////////////////// 

    $ConObj5 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj5->Where = "circle_id='".$CurrentCir->id."'"; 
    $Case_count=$ConObj5->TableCountDistinct("id","id_count"); 

    $ConObj6 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj6->Where = "circle_id='".$CurrentCir->id."' AND reply_filed='Yes'"; 
    $Reply_count=$ConObj6->TableCountDistinct("id","reply_count"); 

    $ContObj7 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ContObj7->Where = "circle_id='".$CurrentCir->id."' AND date_next_hearing>='".date('Y-m-d')."' AND date_next_hearing <='".date('Y-m-d', strtotime("+21 days"))."'"; 
    $Hear_count=$ContObj7->TableCountDistinct("id","file_count"); 

    $ConObj7 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj7->Where = "circle_id='".$CurrentCir->id."' AND date_next_hearing>='".date('Y-m-d')."' AND date_next_hearing <='".date('Y-m-d', strtotime("+21 days"))."' AND reply_filed='Yes'"; 
    $Hearing_count=$ConObj7->TableCountDistinct("id","case_count"); 

    $ConObj8 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj8->Where = "circle_id='".$CurrentCir->id."' AND date_next_hearing>='".date('Y-m-d')."' AND date_next_hearing <='".date('Y-m-d', strtotime("+21 days"))."' AND reply_filed='No'"; 
    $Filed_count=$ConObj8->TableCountDistinct("id","next_count");  

    ?> 
    <tr> 
     <td colspan="3" align="center"><b><?=$CurrentCir->circle?> Circle Total</b></td> 
    <td align="center" style="color:black"><b><?=MyStripSlashes($Case_count->id_count);?></b></td> 

    <? if($Reply_count->reply_count!='0'){ 
     $color= (($Reply_count->reply_count)*100)/$Case_count->id_count; 
     }else{ 
     $color = '0'; 
     } 

     if($color=='0'){?> 
     <td align="center" style="color:black"> 
     <?=MyStripSlashes($Reply_count->reply_count)?> 
     </td> 

    <?}elseif($color<=65 & $color>0){?> 

     <td align="center" style="color:black" bgcolor="#F75D59"> 
     <b><?=MyStripSlashes($Reply_count->reply_count)?></b> 
     </td> 

    <? }elseif($color>65 && $color<=90){?> 
    <td align="center" style="color:black" bgcolor="#FFFF00"> 
     <b><?=MyStripSlashes($Reply_count->reply_count)?></b> 
    </td> 

    <? }elseif($color>90){?> 
    <td align="center" style="color:black" bgcolor="#00FF00"> 
     <b><?=MyStripSlashes($Reply_count->reply_count)?></b> 
    </td>   
    <?}?> 

    <td align="center" style="color:black"> 
     <b><?=MyStripSlashes($Hear_count->file_count)?></b> 
    </td> 

    <td align="center" style="color:black"> 
     <b><?=MyStripSlashes($Hearing_count->case_count)?></b> 
    </td> 

    <? if($Filed_count->next_count==0){?> 

    <td align="center" style="color:black" bgcolor="#00FF00"> 
     <b><?=MyStripSlashes($Filed_count->next_count)?></b> 
    </td> 
    <?}else{?> 
    <td align="center" style="color:black" bgcolor="#F75D59"> 
     <b><?=MyStripSlashes($Filed_count->next_count)?></b> 
    </td> 
    <?}?> 

    </tr> 

    <? 
    /////////Zone total starts here///////////////////////// 

    $ConObj5 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj5->Where = "zone_id='".$CurrentCir->zone_id."'"; 
    $Case_count=$ConObj5->TableCountDistinct("id","id_count"); 

    $ConObj6 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj6->Where = "zone_id='".$CurrentCir->zone_id."' AND reply_filed='Yes'"; 
    $Reply_count=$ConObj6->TableCountDistinct("id","reply_count"); 

    $ContObj7 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ContObj7->Where = "zone_id='".$CurrentCir->zone_id."' AND date_next_hearing>='".date('Y-m-d')."' AND date_next_hearing <='".date('Y-m-d', strtotime("+21 days"))."'"; 
    $Hear_count=$ContObj7->TableCountDistinct("id","fil_count"); 

    $ConObj7 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj7->Where = "zone_id='".$CurrentCir->zone_id."' AND date_next_hearing>='".date('Y-m-d')."' AND date_next_hearing <='".date('Y-m-d', strtotime("+21 days"))."' AND reply_filed='Yes'"; 
    $Hearing_count=$ConObj7->TableCountDistinct("id","case_count"); 

    $ConObj8 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj8->Where = "zone_id='".$CurrentCir->zone_id."' AND date_next_hearing>='".date('Y-m-d')."' AND date_next_hearing <='".date('Y-m-d', strtotime("+21 days"))."' AND reply_filed='No'"; 
    $Filed_count=$ConObj8->TableCountDistinct("id","next_count");  



    } ?> 

    <tr> 
    <td colspan="3" align="center"><b><?=$CurrentZon->zone?> Zone Total</b>  </td> 

    <td align="center" style="color:black"><b><?=MyStripSlashes($Case_count->id_count);?></b></td> 

    <? if($Reply_count->reply_count!='0'){ 
     $color= (($Reply_count->reply_count)*100)/$Case_count->id_count; 
     }else{ 
     $color = '0'; 
     } 

    if($color=='0'){?> 
     <td align="center" style="color:black"> 
     <?=MyStripSlashes($Reply_count->reply_count)?> 
     </td> 

     <?}elseif($color<=65 & $color>0){?> 

     <td align="center" style="color:black" bgcolor="#F75D59"> 
     <b><?=MyStripSlashes($Reply_count->reply_count)?></b> 
     </td> 

     <? }elseif($color>65 && $color<=90){?> 
     <td align="center" style="color:black" bgcolor="#FFFF00"> 
     <b><?=MyStripSlashes($Reply_count->reply_count)?></b> 
     </td> 

     <? }elseif($color>90){?> 
     <td align="center" style="color:black" bgcolor="#00FF00"> 
     <b><?=MyStripSlashes($Reply_count->reply_count)?></b> 
     </td>    
     <?}?> 

     <td align="center" style="color:black"> 
     <b><?=MyStripSlashes($Hear_count->fil_count)?></b> 
     </td> 

     <td align="center" style="color:black"> 
     <b><?=MyStripSlashes($Hearing_count->case_count)?></b> 
    </td> 

    <? if($Filed_count->next_count==0){?> 

    <td align="center" style="color:black" bgcolor="#00FF00"> 
     <b><?=MyStripSlashes($Filed_count->next_count)?></b> 
    </td> 
    <?}else{?> 
    <td align="center" style="color:black" bgcolor="#F75D59"> 
     <b><?=MyStripSlashes($Filed_count->next_count)?></b> 
    </td> 
    <?}?> 

    </tr> 


    <?} 

    /////////District total starts here////////////////////////// 

    $ConObj5 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj5->Where = "1"; 
    $Case_count=$ConObj5->TableCountDistinct("id","id_count"); 

    $ConObj6 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj6->Where = "reply_filed='Yes'"; 
    $Reply_count=$ConObj6->TableCountDistinct("id","reply_count"); 

    $ContObj7 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ContObj7->Where = "date_next_hearing>='".date('Y-m-d')."' AND date_next_hearing <='".date('Y-m-d', strtotime("+21 days"))."'"; 
    $Hear_count=$ContObj7->TableCountDistinct("id","file_count"); 

    $ConObj7 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj7->Where = "date_next_hearing>='".date('Y-m-d')."' AND date_next_hearing <='".date('Y-m-d', strtotime("+21 days"))."' AND reply_filed='Yes'"; 
    $Hearing_count=$ConObj7->TableCountDistinct("id","case_count"); 

    $ConObj8 = new DataTable(TABLE_CONTEMPT_PETITION_A); 
    $ConObj8->Where = "date_next_hearing>='".date('Y-m-d')."' AND date_next_hearing <='".date('Y-m-d', strtotime("+21 days"))."' AND reply_filed='No'"; 
    $Filed_count=$ConObj8->TableCountDistinct("id","next_count");  

    ?>  
    <tr class="InsideRightTd"> 
    <td align="center" style="color:black" bgcolor="#F5F5DC" colspan="3"><b> Grand Total</b></td> 
    <td align="center" style="color:black" bgcolor="#F5F5DC"><b><?=MyStripSlashes($Case_count->id_count);?></b></td> 

    <? if($Reply_count->reply_count!='0'){ 
     $color= (($Reply_count->reply_count)*100)/$Case_count->id_count; 
    }else{ 
     $color = '0'; 
    } 

    if($color=='0'){?> 
     <td align="center" style="color:black"> 
     <?=MyStripSlashes($Reply_count->reply_count)?> 
     </td> 

    <?}elseif($color<=65 & $color>0){?> 

     <td align="center" style="color:black" bgcolor="#F75D59"> 
     <b><?=MyStripSlashes($Reply_count->reply_count)?></b> 
     </td> 

    <? }elseif($color>65 && $color<=90){?> 
    <td align="center" style="color:black" bgcolor="#FFFF00"> 
     <b><?=MyStripSlashes($Reply_count->reply_count)?></b> 
    </td> 

    <? }elseif($color>90){?> 
    <td align="center" style="color:black" bgcolor="#00FF00"> 
     <b><?=MyStripSlashes($Reply_count->reply_count)?></b> 
    </td>   
    <?}?> 

    <td align="center" style="color:black"> 
     <b><?=MyStripSlashes($Hear_count->file_count)?></b> 
    </td> 

    <td align="center" style="color:black"> 
     <b><?=MyStripSlashes($Hearing_count->case_count)?></b> 
    </td> 

    <? if($Filed_count->next_count==0){?> 

    <td align="center" style="color:black" bgcolor="#00FF00"> 
     <b><?=MyStripSlashes($Filed_count->next_count)?></b> 
    </td> 
    <?}else{?> 
    <td align="center" style="color:black" bgcolor="#F75D59"> 
     <b><?=MyStripSlashes($Filed_count->next_count)?></b> 
    </td> 
    <?}?> 
    </tr> 

    </table> 

    <? break; 
    } 
    ?> 

    <table cellpadding="0" cellspacing="0" border="0" style="color:black" align="center"> 
    <tr></tr><br/> 

    <tr> 
     <td>Less than 65% &nbsp;&nbsp;<div style="width:60px;height:20px;border:1px solid #000;background:#F75D59;"></div>  </td> 
     <td>Between 65-90%&nbsp;&nbsp;<div style="width:60px;height:20px;border:1px solid #000;background:#FFFF00;"></div></td> 
     <td>Greater Than 90% &nbsp;&nbsp;<div style="width:60px;height:20px;border:1px solid #000;background:#00FF00;"></div></td> 
     </tr> 

    </table> 

這是一份報告,我希望下載它的pdf。

我附上自己的形象也report image for which i want pdf file

+0

查看[wkhtmltopdf](http://wkhtmltopdf.org)命令行工具。它允許將html呈現爲pdf。 –

回答

0

還有一個免費的Windows軟稱爲DoPdf。它就像您在PC上安裝的虛擬打印機,非常輕便,快速且無痛。在PC上安裝這個「打印機」,然後在瀏覽器上「打印」該打印機上的頁面。您將得到的所有內容都將轉換爲保存在您選擇的文件夾中的PDF文件。你甚至可以配置生成的PDF的分辨率,如果它將是縱向或橫向,黑色或白色,所以,這是一個非常受歡迎和不錯的選擇。此外,您PC上的每個軟件都可以隨時使用此PDF創建器,例如,OpenOffice等。

+0

感謝您的回答,但事情是「這份報告需要從不同的地點下載,不同的計算機不是從我的只有」 – Sonia

+0

然後,你將需要依靠服務器端資源,像一個(我認爲)亞歷山大波波夫在我面前對你說。不要害怕,實施並不困難。 1)聯繫您的ISP(您的網站託管在哪裏); 2)詢問他們是否有滿足這種需求的服務器端組件 - 創建PDF文件「onfly」 - 如果您的賬戶支持使用該技術; 3)Ask'em關於代碼示例在您的頁面上實現; 4)是時候編碼了:用你的所有知識在你的頁面上放置一個「下載爲PDF」,供用戶點擊並管理後面的場景。我相信你會得到它的。最好。 – statosdotcom

+0

@Sonia請檢查你認爲有助於解決問題的答案。謝謝。 – statosdotcom