How to download PDF File Generated from TCPDF (PHP) using AJAX (jQuery)? How to download PDF File Generated from TCPDF (PHP) using AJAX (jQuery)? ajax ajax

How to download PDF File Generated from TCPDF (PHP) using AJAX (jQuery)?


If the problem is that you are not getting the browser's download dialog for the PDF, then the solution is to do it this way:

First, redirect the browser (using window.location as the other answers say) to navigate to a special controller action in your application, e.g. with this url: http://your.application.com/download/pdf/filename.pdf.

Implement the action referenced in the URL like this:

public function actionPdf() {    header('Content-Type: application/pdf');    header('Content-Disposition: attachment; filename="filename.pdf";');    header('Content-Length: '.filesize('path/to/pdf'));    readfile('path/to/pdf');    Yii::app()->end();}

This will cause the browser to download the file.


You need to save the PDF to somewhere on your server and then issue window.location = '/url/to/pdf-you-just-saved.pdf'; from your javascript. The users browser will then prompt them to download the PDF file.


in tcpdf , just pass this argument the Output method:

$pdf->Output('yourfilename.pdf', 'D'); 

that's all