using AJAX and Jquery to create pdf using FPDF

后端 未结 2 1181
暖寄归人
暖寄归人 2020-12-19 03:18

I am trying to create pdf file using FPDF.

What I right now have is an HTML page with various lines of data and a print button next to it. When someone clicks Print

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-19 04:01

    You should open a new page using tag with your PHP page print.php with your variables.

    click me to download the file

    In the PHP page, add headers

    // Send Headers
    header('Content-type: application/pdf');
    header('Content-Disposition: attachment; filename="myPDF.pdf');
    
    // Send Headers: Prevent Caching of File
    header('Cache-Control: private');
    header('Pragma: private');
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    

    Try to play with header header('Content-type: application/force-download'); to download automatically your file.

    You could also display your PDF data like if the file has been saved readfile('original.pdf');

提交回复
热议问题