PDF生成但已损坏

时间:2013-05-14 09:26:08

标签: php pdf

我在这里检查了许多线程并尝试了它们,但没有任何作用。它正在生成MS Word文件,但不生成PDF。任何人都可以告诉我快速生成PDF文件的方法。

这是我尝试的代码:

<?php ob_start(); ?>
<style>

#srch-frm {}
.srchfld {
    font-size: 16px;
    height: 31px;
    padding: 4px;
    width: 162px;
}
.out-fld {
   padding: 11px;
}
.box_search {}
#srch-submit {
    font-size: 15px;
    height: 34px;
    width: 128px;
}
.township_report {
    display:none;
}
</style>

<div id="wrapper">


<div id="content">

<p>&nbsp;</p>

<div class="srch_report">

<style>
#report-headings {
    font-size: 20px;
    font-weight: bold;
    position: relative;
    top: -5px;}
#report-title {
    font-size: 20px;
    font-weight: bold;}
#report {
    background-color: lightgray;
    left: 52px;
    padding: 32px;
    position: relative;
    width: 808px;}
.hdr {    
    font-family: verdana;
    font-size: 14px;}
.hdr-ttl {
    padding-left: 39px;}
.hdr-date {padding-left: 195px;}
.hdr-val {padding-left: 5px;}
.fld-ttl {}
.fld-val {
    float: right;
    padding-right: 127px;}
.fld-row {
    height: 23px;}
.fld-col {    
    float: left;
    width: 50%;}
#fld-area {
    font-size: 16px;}
.fld2-val {}
.fld2-ttl {
    padding-left: 103px;}
.fld2 {
    font-weight:bold;}
.fld2-main {
    padding-top: 20px;}
.fld2-val-ini {}    
</style>

<p>&nbsp;</p>
<div id="report">

    <div id='report-headings' align="center">
        Law Offices of Patrick C. Doody
    </div>

    <div id='report-title'>
      <p>Township Deadlines </p>
    </div>

    <div class="hdr">   
      <spam class=''>Year:</spam> <spam class='hdr-val'>2006</spam>
        <spam class='hdr-ttl'>County:</spam> <spam class='hdr-val'>Cook</spam>
        <spam class='hdr-ttl'>Township:</spam> <spam class='hdr-val'>Cook</spam>
        <spam class='hdr-date'>As Of:</spam> <spam class='hdr-val'>2013-05-14</spam>
    </div>

<p>&nbsp;</p>

    <div id="fld-area">

        <div class="fld-row">
            <div class="fld-col">
                <spam class="fld-ttl">Assessor Open:</spam><spam class="fld-val">2006-03-07</spam>
            </div>  
            <div class="fld-col">
                <spam class="fld-ttl">BofR Opens:</spam><spam class="fld-val">2006-09-11</spam>
            </div>
        </div>

        <div class="fld-row">
            <div class="fld-col">
                <spam class="fld-ttl">Assessor Closes:</spam><spam class="fld-val">2006-04-05</spam>
            </div>
            <div class="fld-col">
                <spam class="fld-ttl">BofR Closes:</spam><spam class="fld-val">2006-10-18</spam>
            </div>
        </div>

        <div class="fld-row">
            <div class="fld-col">
                <spam class="fld-ttl">Assr Documents Due:</spam><spam class="fld-val">2006-04-20</spam>
            </div>
            <div class="fld-col">
                <spam class="fld-ttl">BofR Hearing:</spam><spam class="fld-val"></spam>
            </div>
        </div>

        <div class="fld-row">
            <div class="fld-col">
                <spam class="fld-ttl">Assr Certified:</spam><spam class="fld-val">2006-05-31</spam>
            </div>
        </div>

    </div>
<p>&nbsp;</p>
<p>
          <table>
        <tr>
            <td style="width:140px;font-weight:bold;">File #</td>
            <td style="width:140px;font-weight:bold;">Client</td>
            <td style="width:190px;font-weight:bold;">Property Name</td>
            <td style="width:140px;font-weight:bold;">Atty</td>
        </tr>
        <p>
          <tr><td>00-5009</td><td>DORAN</td><td>Popeye's Chicken</td><td>F&G</td></tr></table>        </p>
</div>
<p>&nbsp;</p>
<style>
.prntdiv {
    float: left;
    padding: 16px 16px 16px 386px;}
.savediv {
    float: left;
    padding: 16px;}
#print {
    font-family: times new roman;
    font-size: 15px;
    font-weight: bold;
    padding: 6px 15px;}
#save {
    font-family: times new roman;
    font-size: 15px;
    font-weight: bold;
    padding: 6px 15px;}

</style>

</div>
</p>
</div>
</div>
</div>
<?php
    header('Content-type: application/pdf');
    header('Content-Disposition: attachment; filename="report.pdf"');
    header('Content-Transfer-Encoding: binary');
?>

1 个答案:

答案 0 :(得分:3)

PDF无效。

你实际上是在创建一个网页(标准HTML / CSS),然后告诉浏览器“把它当作PDF格式化”,这是行不通的,因为当浏览器将其移交给它的PDF查看器时,它不是有效的PDF文件。

您希望 HTML / CSS转换为PDF。请参阅:Convert HTML + CSS to PDF with PHP?