将php报告页面转换为PDF格式

时间:2016-04-05 17:18:17

标签: php pdf

我是php新手,不知道如何将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

1 个答案:

答案 0 :(得分:1)

还有一个名为DoPdf的免费Windows软件。它就像您安装在PC上的虚拟打印机,非常轻便,简单,快速且无痛。安装这个&#34;打印机&#34;在您的PC上,然后在您的浏览器上,&#34; print&#34;该打印机上的页面。您将获得的只是将您的漂亮而干净的HTML转换为保存在您选择的文件夹上的PDF文件。您甚至可以配置生成的PDF的分辨率,如果它将是纵向或横向,黑色或白色,那么,它是一个非常受欢迎和不错的选项。此外,PC上的每个软件都可以随时使用此pdf创建者,例如,您的OpenOffice等。最佳。