donglu9743 2012-07-11 21:29
浏览 175
已采纳

TCPDF与FPDI模板和CSS

When using TCPDF together with FPDI templates, some CSS support is lost in the process. The problem are things like borders or background-colors, that end up in layers below the PDF template. TCPDF uses SetLineStyle() to convert CSS borders/backgrounds to PDF and this seems to be the problem.

For example:

$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); 

doesn't render the CSS borders. As soon as useTemplate() is removed the borders are there. Analyzing the resulting PDFs with Illustrator shows some interesting things:

PDF layers with useTemplate() - top to bottom:

  1. Table/Content layers
  2. PDF Template layers (group)
  3. Border and background layers (paths)

PDF layers without useTemplate() - top to bottom:

  1. Table/Content layers
  2. Border and background layers (paths)

When disabling the layer group containing the PDF template in Illustrator, the borders and backgrounds become visible.

Unfortunately we didn't find a way to put the PDF template layer group at the bottom of the stack so everything else renders above it. The only workaround we could come up with, was wrapping the writeHTMLCell() call in startTemplate() / endTemplate() and finishing up with 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');

So out of curiosity: is this the only way to do it, or is there a way to put the PDF template at the bottom of all things to come?

Thanks in advance!

  • 写回答

2条回答 默认 最新

  • drqefnd544707688 2012-07-12 18:55
    关注

    Did you try using the setPageMark()-method?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度