【问题标题】:tcpdf position footer at the bottom of the page页面底部的 tcpdf 位置页脚
【发布时间】:2012-04-24 16:14:48
【问题描述】:

我正在使用 tcpdf 将 pdf 添加到系统发送的电子邮件中。当电子邮件到达时,办公室将其打开并打印出 pdf 并将其发布给未在系统上设置电子邮件的客户。问题是当 tcpdf 生成 pdf 时,它会将页脚直接放在信函的内容之下。这样做的问题是pdf使用公司的信头模板并将页眉放在正确的位置,但页脚应该在页面底部,但它会根据内容的位置移动,其中为了让它看起来像他们的信头一样需要在底部。

我目前正在使用以下内容(我知道 POSTS 是不安全的,当我完成所有内容时,我很快就会对那个帖子进行排序):

    <?php

    $message = $_POST[emailformmessage];
    $cf_id = $_POST[cf_id];
    $leadname = $_POST[leadname];
    $postcode = $_GET[postcode];
    $address = $_GET[address];
    $date = $_GET[date];
    $town = $_GET[town];
    $business = $_POST[businessname];




    $html = "<html>
    <head>
    <style>

    .container {width:680px; font-family:Arial, Helvetica, sans-serif; font-size:44px;}

    .header {margin-left:50px; margin-right:50px; margin-top:15px;}

    .customeraddress {color:#000;margin-left:65px; margin-right:65px; margin-top:25px; text-align:left;}

    .delivered {color:#fff; background:#344EA2; margin-left:80px; margin-top:5px; text-align:center;padding:15px; margin-right:80px;}

    .titles_L {color:#fff; background:#13155C; margin-left:80px; margin-top:5px; text-align:center; padding:5px; width:250px; float:left; font-weight:bold;}

    .titles_R {color:#fff; background:#13155C; margin-top:5px; text-align:center; padding:5px; margin-right:80px; width:250px; float:left; font-weight:bold;}

    .body-text { background:#fff;color:#333; margin-left:65px; margin-top:5px; text-align:left; padding:15px 0px 15px 0px; margin-right:65px; overflow:auto;}

    .terms {color:#fff;margin-left:80px; margin-top:5px; text-align:center;  padding:15px; margin-right:80px;}

    .footer {margin-left:50px; margin-top:5px; text-align:left; font-size:40px; padding:15px; margin-right:50px; color:#000; overflow:auto;}

    .footer a {}

    .footer_left {float:left; width:100px;}

    .footer_right {float:left;}

    .clear {clear:both; float:none;}

    .footerclear {clear:both; float:none; width:100%; padding:8px;}

    .pricerow {}

    .emailpricesgasoil {width:240px; float:left;  padding-bottom:15px; padding-top:15px; margin:2px 0px 2px 0px;background:#f4f4f4;color:#EE3B33;}

    .emailpricesderv {width:240px; float:left;  padding-bottom:15px; padding-top:15px; margin:2px 0px 2px 0px;background:#f4f4f4;color:#EE3B33;}

    .emailpriceskero {width:240px; float:left;  padding-bottom:15px; padding-top:15px; margin:2px 0px 2px 0px;background:#f4f4f4;color:#EE3B33;}

    .emailfueldescgasoil {width:250px; float:left;  padding-bottom:15px; padding-top:15px;margin:2px 0px 2px 0px;background:#f1f1f1;}

    .emailfueldescderv {width:250px; float:left;  padding-bottom:15px; padding-top:15px; margin:2px 0px 2px 0px;background:#f1f1f1;}

    .emailfueldesckero {width:250px; float:left;  padding-bottom:15px; padding-top:15px;  margin-top:2px; margin:2px 0px 2px 0px; background:#f1f1f1;}
    </style>
    </head>
    <body>


    <div class=\"container\">

    <img class=\"header\" src=\"http://key4design.co.uk/chandlers/images/chandlers_header.jpg\" width=\"996\" height=\"326\">

    <div class=\"customeraddress\">
    $leadname<br/>
    $business<br/>
    $address<br/>
    $town<br/>
    $postcode<br/>
    $date<br/>
    </div>
    <div class=\"clear\"></div>

    <div class=\"body-text\">
     $message</div>
    <div class=\"clear\"></div>
    <div class=\"footer\">
    <img class=\"footerimg\" src=\"http://key4design.co.uk/chandlers/images/chandlers_footer.jpg\" width=\"996\" height=\"261\">
    <div class=\"footerclear\"></div>
    </div>

    </body>
    </html>";
    $old_limit = ini_set("memory_limit", "16M");
    require_once("./pdf/config/lang/eng.php");
    require_once("./pdf/tcpdf.php");
    $pdf = new TCPDF("portrait", PDF_UNIT, "a3", true, "UTF-8", false);
    // set font
    $pdf->SetFont("helvetica", "", 10);
    // add a page
    $pdf->AddPage();
    $pdf->writeHTML($html, true, false, true, false, "");
    // reset pointer to the last page
    $pdf->lastPage();
    //Close and output PDF document
    if(!file_exists("./pdf/doc/file.pdf") || is_writable("./pdf/doc/file.pdf"))
    $pdf->Output("./pdf/doc/file.pdf", "F");
    else
    exit("./pdf/doc/file.pdf");
    ?>

【问题讨论】:

  • 我相信 TCPDF 不支持所有的 css 功能。喜欢:float, padding

标签: php email footer tcpdf


【解决方案1】:

好像你只在页脚中添加了一张图片,为什么不直接使用Image Function

$pdf->AddPage();
$pdf->writeHTML($html, true, false, true, false, "");
$pdf->Image('http://key4design.co.uk/chandlers/images/chandlers_footer.jpg', 100, 350);
// reset pointer to the last page
$pdf->lastPage();  

您可能必须禁用默认页脚

$pdf->setPrintFooter(false);

【讨论】:

  • 如果我使用图像,我会得到:致命错误:调用未定义的函数 Image()
  • 已编辑。试试$pdf->Image(),也可以自己添加xy坐标。 a3 纵向尺寸是 297 宽 x 420 长,所以我猜 x=100, y=350 并自行调整。
  • 谢谢,现在可以了,但是由于某种原因它把页脚放在了第二页:-(
  • 试试这个$pdf-&gt;SetAutoPageBreak(false);
  • 好的,现在可以了,但是正在切断页脚的底部,我是否要更改坐标以将其放置在我认为的正确位置?
【解决方案2】:
$pdf->SetAutoPageBreak(false);

这将阻止 tcpdf 自动生成下一页,您可以在同一页面上调整页脚。

【讨论】:

  • 终于,我的图像被推送到新页面的关键!
猜你喜欢
  • 2017-10-03
  • 1970-01-01
  • 2016-06-13
  • 1970-01-01
  • 1970-01-01
  • 2012-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多