Generating PDF with moodle stylesheets

Generating PDF with moodle stylesheets

by Lavanya Manne -
Number of replies: 1
Picture of Plugin developers

I was trying to generate PDF document from a moodle custom page. I could pullout the content, it was absolutely working fine, but CSS is not working for the page:

require_once('../../config.php');

require_once($CFG->libdir.'/pdflib.php');

$PAGE->requires->css('/styles.css');

$pdf = new pdf();
$pdf->AddPage();
$pdf->writeHTML('<p>This is an example</p>');
$pdf->Output('mypdf.pdf', 'D');

Could anyone guide me where I was going wrong. Many Thanks.



Average of ratings: -
In reply to Lavanya Manne

Re: Generating PDF with moodle stylesheets

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Moodle's pdf() class is a wrapper round TCPDF. Suggest you have a read through the docs for that - https://tcpdf.org/docs/

There's some examples, but my understanding is that TCPDF's CSS support is very limited. You're not going to reproduce what Moodle looks like in a browser.