Movatterモバイル変換


[0]ホーム

URL:


mPDF Manual – What Else Can I Do

Capture HTML output

One way of outputting a webpage to mPDF without re-writing your scripts too much, is to buffer the output:

<?php// Require composer autoloadrequire_once__DIR__.'/vendor/autoload.php';$mpdf=new\Mpdf\Mpdf();// Buffer the following html with PHP so we can store it to a variable laterob_start();// This is where your script would normally output the HTML using echo or printecho'<div>Generate your content</div>';// Now collect the output buffer into a variable$html=ob_get_contents();ob_end_clean();// send the captured HTML from the output buffer to the mPDF class for processing$mpdf->WriteHTML($html);$mpdf->Output();
  • \Mpdf\Mpdf() - Initialise an instance of mPDF class, and specify configuration
  • WriteHTML() - Write HTML to the document
  • Output() - Finalise and output the document

[8]ページ先頭

©2009-2026 Movatter.jp