2

When I am using following style then everything works properly.

<style>
            table{
                border: 0.5px solid black;
                border-collapse: separate;
                border-spacing: 0;
            }
            </style>

But when Im using class, code is not working.

<style>
            .tableWithOuterBorder{
                border: 0.5px solid black;
                border-collapse: separate;
                border-spacing: 0;
            }
            </style>

Following are my details code.

$htmlData   =   "<html><head>";
                $htmlData   .=  "<style>
                .tableWithOuterBorder{
                    border: 0.5px solid black;
                    border-collapse: separate;
                    border-spacing: 0;
                }
                </style>";

                $htmlData   .=  "</head><body>";
                $htmlData   .=  "<table class='tableWithOuterBorder'><tr><td>Hello</td><td>Sir</td></tr></table>";
                $htmlData   .=  "</body></html>";

        $pdf->writeHTML($htmlData, true, false, false, false, '');

What is wrong in my code?

Mohan Kute
  • 137
  • 1
  • 3
  • 14

1 Answers1

5

Hello Change Below line,

$htmlData   .=  "<table class='tableWithOuterBorder'><tr><td>Hello</td><td>Sir</td></tr></table>";

to

$htmlData   .=  '<table class="tableWithOuterBorder"><tr><td>Hello</td><td>Sir</td></tr></table>';

Just give class name in double quote("), and everything works properly.

My Final code is right now :

$htmlData   =   '<html><head>';
                $htmlData   .=  '<style>
                .tableWithOuterBorder{
                    border: 0.5px solid black;
                    border-collapse: separate;
                    border-spacing: 0;
                }
                </style>';

                $htmlData   .=  '</head><body>';
                $htmlData   .=  '<table class="tableWithOuterBorder"><tr><td>Hello</td><td>Sir</td></tr></table>';
                $htmlData   .=  '</body></html>';
        $pdf->writeHTML($htmlData, true, false, false, false, '');

Thanks