mpdf / mpdf.github.io

mPDF documentation
https://mpdf.github.io
Other
504 stars 160 forks source link

css file not working on remote server #165

Closed Ademgenc53 closed 3 years ago

Ademgenc53 commented 3 years ago

Hello, While working fine on the local computer, css does not work on the remote server

    table.customTable {
        width: 793px;
        border-collapse: collapse;
        font-family: Arial, Roboto, sans-serif;
    }

    table.customTable tr td {
        padding: 5px;
        border-bottom: 1px solid #ddd;
        font-family:'Roboto-thin',sans-serif;
    }

    table.customTable tr th {
        background-color: #3715cd;
        color: #ffffff;
        padding: 5px;
        font-family:'Roboto-thin',sans-serif;
    }

    .align-left {
        text-align:left;
    }

    .align-right {
        text-align:right;
    }

    .align-center {
        text-align:center;
    }

    .bold {
        font-weight:bold;
    }

    .red {
        color:rgb(255, 0, 0);
    }

It doesn't need tmp, and font on local computer, but it does on remote computer it needs below code for remote server

$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];

$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];

$mpdf = new \Mpdf\Mpdf([
    'fontDir' => array_merge($fontDirs, [
        __DIR__ . '/ttfonts',
    ]),
    'fontdata' => $fontData + [
        'frutiger' => [
            'R' => 'Roboto-Regular.ttf',
            'I' => 'Roboto-Regular.ttf',
        ]
    ],
    'default_font' => 'frutiger',
    'default_font_size' => 7,
    'tempDir' => __DIR__ . '/tmp'
]);

I am loading the css file as below

$mpdf->SetDisplayMode('default');

$mpdf->autoScriptToLang = true;
$mpdf->baseScript = 1;  // Use values in classes/ucdn.php  1 = LATIN
$mpdf->autoLangToFont = true;

$stylesheet = file_get_contents(__DIR__ . '/style.css');

$mpdf->WriteHTML($stylesheet,\Mpdf\HTMLParserMode::HEADER_CSS);
$mpdf->WriteHTML($html,\Mpdf\HTMLParserMode::HTML_BODY);

I'm using the latest version of mPDF 8.0.12 I tried 7.2, 7.3, 7.4 as PHP version, css doesn't work in any of them Some code of CSS works th background color and text color red color works, bold does not text-align not working padding not working

I tried a lot of things but couldn't reach a result. Can you help me

Thank you

Klap-in commented 3 years ago

Sorry, did you read this: https://github.com/mpdf/mpdf.github.io/issues/new ? Please use stackoverflow for your troubleshooting. If it turns out to be a bug, you can report it in the issue tracker of mpdf.

Ademgenc53 commented 3 years ago

I looked everywhere, I tried to do a lot of things, I couldn't solve the problem. I've used it before and there was no problem. I upgraded to the latest version with Composer, all the problems started I'm deleting the vendor folder, is coming back Server firm renamed .composer in root directory but I couldn't solve the problem vender coming back. We can't get rid of the vendor folder I will try domPDF, if successful I will use this