TCPDF Specific border for different sides
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,
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".
Thanks for any help, Metropolis
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.
For example:
border-right: 1px solid black;
This answer is deprecated as 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.
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.
you need to make two changes to tcpdf Class (or override writeHtml function in yout own pdf class inheriting from tcpdf):
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.
I know this is far from being valid HTML :J but it saved me a lot of time and trouble.
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.
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 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)
This kind of weird, but you can draw border by yourself using Line method.
Example
$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0));
$this->Line(x1, y1, x2, y2, $style);
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.
精彩评论