7

I am trying to convert my html page into pdf format using mpdf. problem is that i am unable to apply more than one css to pdf file.. here is my code of php

<?php
           $html =file_get_contents('mpdf/test.html');
            include("../mpdf.php");
            $mpdf=new mPDF(); 
           $mpdf->SetDisplayMode('fullpage','two');
            // LOAD a stylesheet 1
            $stylesheet = file_get_contents('assets/css/main.css');
            $mpdf->WriteHTML($stylesheet,1);    // The parameter 1 tells that this is css/style only and no body/html/text
          // LOAD a stylesheet 2
            $stylesheetextra = file_get_contents('assets/css/test.css');
            $mpdf->WriteHTML($stylesheetextra ,1);  // The parameter 1 tells that this is css/style only and no body/html/text
            $mpdf->WriteHTML($html,2);
          $mpdf->Output();

            exit;
            ?>

Output it gives doesn't come with test.css . main.css is applying properly to pdf file but test.css doesn't applying.please help me? thanking you in advance

  • 1
    does appending the second stylesheet to the first work i.e. $stylesheet = file_get_contents('assets/css/main.css') . file_get_contents('assets/css/test.css'); $mpdf->WriteHTML($stylesheet,1); –  Sep 29 '15 at 08:35

3 Answers3

8

You can do it just storing the CSS content in one variable, like this:

$stylesheet  = '';
$stylesheet .= file_get_contents('css/bootstrap.min.css');
$stylesheet .= file_get_contents('css/style.css');
$stylesheet .= file_get_contents('css/impressao_ctr.css');
1

It may be an ugly solution but i ran into a similar problem before. What i did was, since it wasn't a huge problem, i took all the css from the 2nd one i couldn't add, and added it to the "main.css".

somdow
  • 6,268
  • 10
  • 40
  • 58
0

(mPDF ≥ 1.0)

use \Mpdf\HTMLParserMode::HEADER_CSS as 2th parameter.

$stylesheet = file_get_contents('assets/css/main.css');
$mpdf->WriteHTML($stylesheet, \Mpdf\HTMLParserMode::HEADER_CSS);

$stylesheetextra = file_get_contents('assets/css/test.css');
$mpdf->WriteHTML($stylesheetextra, \Mpdf\HTMLParserMode::HEADER_CSS);

Link origin

Trần Hữu Hiền
  • 872
  • 1
  • 9
  • 22