Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto download mpdf generated pdf document

Tags:

html

php

mpdf

I am newbie for mpdf so don't mind if you feel this question is stupid one:),

I generated the pdf document usinf mPDF class , the issue is that after pdf generated the browser opens it in tab . But i want it not to open but auto download , My code is like follwing..

include("../mpdf.php"); $html="my HTML code here !";  $mpdf=new mPDF('c','A4','','',32,25,27,25,16,13);  $mpdf->SetDisplayMode('fullpage'); $mpdf->list_indent_first_level = 0;  $stylesheet = file_get_contents('mpdfstyletables.css'); $mpdf->WriteHTML($stylesheet,1); $mpdf->WriteHTML($html); $mpdf->Output('mpdf.pdf'); 

I am expecting that there will be a function to download in the mpdf class like $mpdf->download instead $mpdf->Output('mpdf.pdf').I searched alot for this type solution but in vain i could't find any .

like image 628
Mansoor Jafar Avatar asked Aug 27 '12 09:08

Mansoor Jafar


People also ask

How to download PDF using mPDF in PHP?

First, we need mPDF library to generate a PDF file. You can either download this from Github or install it using Composer. Let's know how to install the mPDF library using composer. Now, go to your project directory on the command prompt and run the following command to install mPDF library.

Where can I download mPDF?

Online manual is available at https://mpdf.github.io/.

How do I open mPDF files?

Find the PDF you want to open in your Files and double click to open. Select Adobe Acrobat (or whichever reader you downloaded) from the list of available options. If no list appears or the page opens in another application, you can right-click the file and select Open With to choose your PDF reader. Click Open.

How can I use mPDF without Composer?

2) Ensure all needed classes are loaded You can do this manually (reload, find the file with missing class, add require call, repeat) or you can use an autoloading library of your choice. Further usage is then the same as when using Composer, just require your autoloading script instead of Composer autoload.


1 Answers

Add 'D' parameter for download

$mpdf->Output('MyPDF.pdf', 'D'); 
like image 141
Mihai Iorga Avatar answered Sep 30 '22 23:09

Mihai Iorga