Force download PDF created by TCPDF, after Ajax post submit

trullallero picture trullallero · Jun 9, 2012 · Viewed 32.7k times · Source

My application allow the users to complete a form, and send it with an Ajax post call. The form si sent to the TCPDF class that create a PDF file. The class has the method "->output(...)" that permit to save the file into web server, send it to the browser, ecc... my goal is, after the form submit, create the PDF file, and force the user to download it (with no refreshing). The method doesn't work with ajax calls. The only solution I've found is create the file, seve it into web server, and than redirect the user to the location of the file to the web server; but it isn't a nice solution, I need to force the download (auto starting). I've read others similar solution on the forum, but thay aren't good form Any suggestions?

Answer

Tal picture Tal · Jan 20, 2013
$pdf->Output("filename.pdf",'D');