I upgraded mPDF to version 7 and I noticed that progress bar functionality was removed.
I'm looking for something simple: show some html information to the user (i.e. "Processing file...") while mPDF processes the output file.
This is a simplified version of the code and it is working properly:
$mpdf = new Mpdf();
$html_for_pdf = "<p>Hi, this is the html content to render the PDF file</p>";
$mpdf->WriteHTML( $html_for_pdf );
$mpdf->Output();
In order to get what I want, so far I tried:
a) Echo the "Processing file..." html info to screen, but (due to buffering I guess) nothing shows during the processing until the output PDF file finally comes up. The code I tried is this:
$mpdf = new Mpdf();
$html_for_pdf = "<p>Hi, this is the html content to render the PDF file</p>";
$html_processing = "<p>Processing file...</p>";
echo $html_processing;
$mpdf->WriteHTML( $html_for_pdf );
$mpdf->Output();
b) Handle the output buffering with ob_flush(), which shows the "Processing file..." html on screen but the mPDF file rendering breaks and the output file neves shows. The code I tried is this:
$mpdf = new Mpdf();
$html_for_pdf = "<p>Hi, this is the html content to render the PDF file</p>";
$html_processing = "<p>Processing file...</p>";
echo $html_processing;
ob_end_flush();
ob_flush();
flush();
ob_start();
$mpdf->WriteHTML( $html_for_pdf );
$mpdf->Output();
I googled a lot to get any kind of workaround for this without any luck.
Is there any chance to make this work?
Thanks!
My Answer:
Unfortunately, with the current version of mPDF (version 7), there is no built-in progress bar functionality. However, you can try using JavaScript to show a loading spinner or progress bar while the PDF is being generated.
Here is an example of how you can achieve this:
1. Add a loading spinner or progress bar to your HTML file:
html
2. Use JavaScript to show the loading spinner before generating the PDF:
javascript
document.getElementById('loading').style.display = 'block';
3. After generating the PDF, hide the loading spinner:
javascript
document.getElementById('loading').style.display = 'none';
You can also consider using AJAX to generate the PDF in the background and update the progress bar accordingly. This way, the user will see the progress of the PDF generation.
Keep in mind that this workaround may not be as smooth as a built-in progress bar, but it should give your users some indication that the PDF is being generated.
Rate this post
3 of 5 based on 4344 votesComments