0

我在这里检查了很多线程并尝试了它们,但没有任何效果。它正在生成 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');
?>
4

1 回答 1

3

PDF 不能那样工作。

您实际上是在创建一个网页(标准 HTML/CSS),然后告诉浏览器“像 PDF 一样获取它”,这是行不通的,因为当浏览器将其交给 PDF 查看器时,它会不是有效的 PDF 文件。

您想将该HTML/CSS 转换为 PDF。请参阅:使用 PHP 将 HTML + CSS 转换为 PDF?

于 2013-05-14T09:40:37.880 回答