2012-07-11 59 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中的模板之上。