1

I am using mPDF to generate pdf files from html. Now I also want to load some external CSS files and found in a couple of questions/answers on here that you are able to do that.

So I tried this:

$mpdf = new \Mpdf\Mpdf();
$stylesheet .= file_get_contents('../css/bootstrap.css');
$stylesheet .= file_get_contents('../css/custom.css');
$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML($html, 2);
$mpdf->Output($rootpad.'/uren.pdf','F');

But this gives me the following error:

[13-Nov-2019 10:56:05 UTC] PHP Notice:  Undefined variable: html in /home/dropfaci/public_html/includes/pdf.php on line 47

When I remove some code and end up with the following code, a pdf is generated just fine but without css:

$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML($html);
$mpdf->Output($rootpad.'/uren.pdf','F');

Why is it not working?

4
  • hmmm, have you defined html variable? Commented Nov 13, 2019 at 11:11
  • @RicardoCosta Yes Because without the stylesheets, the contents of $html are generated correctly into a PDF. Commented Nov 13, 2019 at 11:12
  • Can you take a look @ stackoverflow.com/a/15567033/8233144 more code would be helpful to try understand what's happening Commented Nov 13, 2019 at 11:14
  • @RicardoCosta I have the same code as that answer except I save the file on my server. Commented Nov 13, 2019 at 12:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.