php TCPDF 不同边的特定边界

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2646792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:12:25  来源:igfitidea点击:

TCPDF Specific border for different sides

phptcpdf

提问by Metropolis

I just started using TCPDF (output with HTML), and I do not understand why I can not have an inline CSS style for border like the following,

我刚开始使用 TCPDF(用 HTML 输出),我不明白为什么我不能有一个像下面这样的内联 CSS 样式的边框,

style="border-right: 1px"

After looking at some of the examples, the only place I see borders being used is on a table using the border="1" property. This is very frustrating, and I hope there is a way for me to use all inline CSS instead of old HTML attributes like "border".

在查看了一些示例之后,我看到使用边框的唯一地方是在使用 border="1" 属性的表格上。这非常令人沮丧,我希望有一种方法可以让我使用所有内联 CSS,而不是像“边框”这样的旧 HTML 属性。

Thanks for any help, Metropolis

感谢您的帮助,大都会

回答by user412934

Since version 5.7 TCPDF ( http://www.tcpdf.org) includes full support for CSS borders, so you have just to update. Anyway, do not forget to correctly set the borders.

由于版本 5.7 TCPDF ( http://www.tcpdf.org) 包含对 CSS 边框的完全支持,因此您只需更新即可。无论如何,不​​要忘记正确设置边框。

For example:

例如:

border-right: 1px solid black;

回答by cioddi

This answer is deprecatedas current versions of tcpdf seem to have support for css border definitions build in. Only use this if you are still using an old tcpdf and cant switch.

此答案已弃用,因为当前版本的 tcpdf 似乎支持内置的 css 边框定义。仅当您仍在使用旧的 tcpdf 且无法切换时才使用此答案。

I am also using the writeHtml function in a recent project and found drawing lines at calculated positions was not a real option to me. so I have created a little hack to enable 1px black borders to tr td div tags.

我也在最近的一个项目中使用 writeHtml 函数,发现在计算位置绘制线条对我来说不是一个真正的选择。所以我创建了一个小技巧来为 tr td div 标签启用 1px 黑色边框。

you need to make two changes to tcpdf Class (or override writeHtml function in yout own pdf class inheriting from tcpdf):

您需要对 tcpdf 类进行两次更改(或在您自己的从 tcpdf 继承的 pdf 类中覆盖 writeHtml 函数):

So just look for the following:

所以只需寻找以下内容:

if (isset($dom[$key]['content'])) {
    $cell_content = $dom[$key]['content'];
} else {
    $cell_content = ' ';
}

after that include:

之后包括:

if (isset($dom[$key]['attribute']['border'])) {
    $cell_borderHack = $dom[$key]['attribute']['border'];
} elseif (isset($dom[$trid]['attribute']['border'])) {
    $cell_borderHack = $dom[$trid]['attribute']['border'];
} else {
    $cell_borderHack = false;
}

and then find:

然后找到:

$this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true);

and replace it with:

并将其替换为:

$this->MultiCell($cellw, $cellh, $cell_content, $cell_borderHack, $lalign, false, 2, '', '', true, 0, true);

After you have done these changes it becomes possible to define top Left rigt bottom Borders just by putting a combination of "TRBL" into the border attribute of your html-tag. e.g.: -> will render the top and left Border 1px solid Black to this table cell.

完成这些更改后,只需将“TRBL”的组合放入 html 标签的边框属性中,就可以定义左上边框。例如: -> 将顶部和左侧边框 1px 纯黑色渲染到此表格单元格。

I know this is far from being valid HTML :J but it saved me a lot of time and trouble.

我知道这远不是有效的 HTML :J 但它为我节省了很多时间和麻烦。

It should also be mentioned that there is a very good reason not going for dompdf due to lack of utf-8 support it will get you into even bigger trouble especially if you are generating Pdf from a multilingual database which I assume.

还应该提到的是,由于缺乏 utf-8 支持,有一个很好的理由不使用 dompdf,它会给您带来更大的麻烦,尤其是如果您从我假设的多语言数据库生成 Pdf。

Tcpdf is the only php library I know that handles utf-8 without any problems (please correct me if I'm wrong in this case).

Tcpdf 是我所知道的唯一一个处理 utf-8 没有任何问题的 php 库(如果我在这种情况下错了,请纠正我)。

回答by KotaKomputer

TCPDF 5.9.010 (2010-10-27) - Support for CSS properties 'border-spacing' and 'padding' for tables were added. Latest version when I write this post: TCPDF 5.9.034 (2010-12-19)

TCPDF 5.9.010 (2010-10-27) - 添加了对表格的 CSS 属性“边框间距”和“填充”的支持。我写这篇文章时的最新版本:TCPDF 5.9.034 (2010-12-19)

回答by Alex Zheka

This kind of weird, but you can draw border by yourself using Line method.

这种很奇怪,但是您可以使用 Line 方法自己绘制边框。

Example

例子

$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0));
$this->Line(x1, y1, x2, y2, $style);

回答by Mohsin

Unfortunately, TCPDF doesn't suppport the FULL CSS hopes some one got the quick magic to fix this or may the Developer itself make it compatible on next version.

不幸的是,TCPDF 不支持 FULL CSS,希望有人能快速解决这个问题,或者开发人员自己让它在下一个版本中兼容。