2012-07-11 57 views
1

將TCPDF與FPDI模板一起使用時,某些CSS支持在進程中丟失。問題是諸如邊框或背景顏色之類的東西,最終以PDF模板下方的圖層爲準。 TCPDF使用SetLineStyle()將CSS邊界/背景轉換爲PDF,這似乎是問題所在。使用FPDI模板和CSS的TCPDF

例如:

$this->setSourceFile($filename); // /path/to/my/background.pdf 
$imported_page = $this->ImportPage(1); 
$this->useTemplate($imported_page); 

... 

$html = '<table style="border: 1px solid #000;"><tr><td style="background-color: #ff0000;">...</td></tr></table>'; 

$this->writeHTMLCell(45, 25, 160, 29, $html); 

並未使CSS邊界。只要useTemplate()被刪除,邊界就在那裏。分析使用Illustrator所產生的PDF文件顯示了一些有趣的事情:

useTemplate() PDF層 - 從上至下:

  1. 表/內容層
  2. PDF模板層(組)
  3. 邊框和背景層(路徑)

PDF層沒有useTemplate() - 自頂向下:

  1. 表/內容層
  2. 邊界和背景層(路徑)

當禁用含在Illustrator PDF模板層組中,邊框和背景變得可見。

不幸的是,我們沒有找到一種方法將PDF模板圖層組放在堆棧的底部,以便其他所有東西都在其上面呈現。唯一的解決方法,我們可以拿出,在startTemplate()/endTemplate()被包裹writeHTMLCell()通話,並與printTemplate()整理了:

$this->setSourceFile($filename); // /path/to/my/background.pdf 
$imported_page = $this->ImportPage(1); 
$this->useTemplate($imported_page); 

... 

$html = '<table style="border: 1px solid #000;"><tr><td style="background-color: #ff0000;">...</td></tr></table>'; 

$workaround_template = $this->startTemplate($w, $h); 
$this->writeHTMLCell(45, 25, 160, 29, $html); 
$this->endTemplate(); 
$this->printTemplate($workaround_template, $x, $y, $w, $h, 'T', 'L'); 

所以出於好奇:這是做到這一點的唯一途徑,或者是有辦法將PDF模板放在所有事情的底部?

在此先感謝!

回答

4

解決方法是確實使用setPageMark()。 這裏是什麼工作對我非常好:

public function AddPage($orientation = '', $format = '') { 
    global $pdf_data_path; 
    parent::AddPage($orientation, $format); 
    if ($this->use_headed) { 
     $this->setSourceFile($pdf_data_path."/headed.pdf"); 
     $tplidx = $this->importPage(1, '/MediaBox'); 
     $this->useTemplate($tplidx, 0, 0, 0, 0, true); 
     $this->setPageMark(); 
    }  
} 

的關鍵是把setPageMark()您所使用的模板後。然後邊界將被堆疊在產生的PDF中的模板之上。