MRJethva
MRJethva

Reputation: 367

Include stylesheet file into MPDF conversion in PHP

I have made HTML to convert it into PDF using MPDF, but issue is that I can't include a stylesheet file.

Example:

include("../mpdf.php");
$mpdf=new mPDF('c'); 
$mpdf->SetDisplayMode('fullpage');
// LOAD a stylesheet
$stylesheet = file_get_contents('mpdfstyleA4.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html);
$mpdf->Output();

I used the code above but I can't see the effect of the styles. Does anyone know a better way to include styles?

Upvotes: 0

Views: 6863

Answers (3)

user2706194
user2706194

Reputation: 199

mPdf works best with inline style sheets which cause no bugs while pdf opens in different browsers.

Upvotes: 1

urchino
urchino

Reputation: 340

You need to load the stylesheet in the html - it's not clear in your snippet where the content for $html comes from but that's the place to load styles. Using your code you'll be writing the CSS you've loaded as if it were document content for the PDF, which I assume isn't your intent.

Upvotes: 1

Steven Holmquist
Steven Holmquist

Reputation: 66

It looks to me you are setting the new PDF function into "Code" mode. $mpdf=new mPDF('c');

Have you tried it without the "C"?

$mpdf=new mPDF();

Also, is your stylesheet, "mpdfstyleA4.css", located in the same path as mpdf.php?

Upvotes: 0

Related Questions