tags:

views:

622

answers:

5

Hey Everyone,

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

A: 

i am having the same problem what is the solution

josi
A: 

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.

Mohsin
A: 

After looking at all of the PDF generators, my suggestion is, use DOMPDF instead

Metropolis
A: 

Hi 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).

cioddi
A: 

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;