CodeIgniter Forums
Tying to download mpdf files - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Tying to download mpdf files (/showthread.php?tid=81863)



Tying to download mpdf files - sevmusic - 05-11-2022

So I've installed mPDF 8.1 to use with my CodeIgniter 4.

Got it working with opening a file in the browser.
Got it working with creating a file on the server.
Got it working with creating an attachment in an email.

But when I try to force download the created PDF using:

Code:
$mpdf->Output('filename.pdf', \Mpdf\Output\Destination::DOWNLOAD);

or

Code:
$mpdf->Output('filename.pdf', 'D');

I get a broken PDF that cannot be opened.

I used another program to see what was in the PDF and I see this:

Code:
<script type="text/javascript"  id="debugbar_loader" data-time="1652299385" src="https://local.mywebsite.com/?debugbar"></script><script type="text/javascript"  id="debugbar_dynamic_script"></script><style type="text/css"  id="debugbar_dynamic_style"></style><script  class="kint-rich-script">void 0===window.kintShared&&(window.kintShared=function(){"use strict";var e={dedupe:function(e,n){return[].forEach.call(document.querySelectorAll(e),function(e){e!==(n=!n||!n.ownerDocument.contains(n)?e:n)&&e.parentNode.removeChild(e)}),n},runOnce:function(e){"complete"===document.readyState?e():window.addEventListener("load",e)}};return window.addEventListener("click",function(e){var n;e.target.classList.contains("kint-ide-link")&&((n=new XMLHttpRequest).open("GET",e.target.href),n.send(null),e.preventDefault())}),e}())...

The code is much longer than that, but I think you get the idea.

Any clue as to what I'm doing wrong?

Thank you for any help!

-max


RE: Tying to download mpdf files - sevmusic - 05-11-2022

Nevermind, I figured it out.

I had the mpdf being created in the view.

As soon as I moved it to the controller, I was able to download it.

-max


RE: Tying to download mpdf files - InsiteFX - 05-12-2022

Please edit your Topic Title and add [SOLVED] to it.

Thank you.