2012-04-12 212 views
2

我正在使用tcpdf將pdf添加到系統發出的電子郵件。當電子郵件到達時,辦公室打開它並打印PDF並將其發佈給未在系統上設置的用於電子郵件的客戶。問題是,當tcpdf生成PDF文件時,它將頁腳直接放在信件的內容之下。問題在於pdf使用公司的信頭模板並將標題放在正確的位置,但頁腳應該放在頁面的底部,但它會根據內容的位置移動,其中as因爲它看起來像他們的信頭需要在底部一樣。位於頁面底部的tcpdf位置頁腳

<?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"); 
    ?> 
+0

我相信TCPDF不支持所有的CSS功能。像:'float,padding' – safarov 2012-04-12 10:17:05

回答

4

似乎只在頁腳,爲什麼不只是增加了一個形象:我目前使用下面的(我知道了帖子的是不安全的,即時的排序是一個不久,當我經歷的一切)

使用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); 
+0

如果我使用圖像,我會得到:致命錯誤:調用未定義函數Image() – 2012-04-12 11:01:30

+0

已編輯。試試$ pdf-> Image(),也可以自己添加** x **,** y ** coords。 a3肖像大小是297寬420長,所以我會猜測x = 100,y = 350,並調整自己。 – Savid 2012-04-12 11:39:25

+0

謝謝,現在起作用了,但是由於某種原因它會將頁腳放在第二頁上:-( – 2012-04-12 12:42:36

0
$pdf->SetAutoPageBreak(false); 

這會阻止tcpdf自動生成下一頁,您可以在同一頁面上調整頁腳。