我是新來的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% <div style="width:60px;height:20px;border:1px solid #000;background:#F75D59;"></div> </td>
<td>Between 65-90% <div style="width:60px;height:20px;border:1px solid #000;background:#FFFF00;"></div></td>
<td>Greater Than 90% <div style="width:60px;height:20px;border:1px solid #000;background:#00FF00;"></div></td>
</tr>
</table>
這是一份報告,我希望下載它的pdf。
查看[wkhtmltopdf](http://wkhtmltopdf.org)命令行工具。它允許將html呈現爲pdf。 –