Question

I am trying to convert html into pdf using mpdf. Problem is that i am unable to apply css to pdf file..

Here is my code of php:

<?php

    $html = $divPrint;
    $mpdf=new mPDF();
    $stylesheet = file_get_contents('pdf.css');
    $mpdf->WriteHTML($stylesheet,1);
    $mpdf->WriteHTML($html,2);
    $mpdf->Output();
    exit;

?>

What it is doing is taking html through ajax on my this php page. But the output it gives doesn't come with css which i've written for it..

Please tell me that to do now?

Was it helpful?

Solution

 <?php

$html = $divPrint;

include('mpdf.php'); // including mpdf.php
$mpdf=new mPDF();
$stylesheet = file_get_contents('pdf.css'); // external css
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html,2);
$mpdf->Output();
exit;

?>

1st assign your html in $html then include mpdf.php file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top