pdf download html2pdf

怎甘沉沦 提交于 2019-12-06 05:17:41

To offer download from your browser u need add the header for being attachment...

header("Content-Disposition: attachment; filename=sample.pdf");

Add the above code at the start of the page and then proceed with the html2pdf conversion..

giuseppe

From the documentation, method Output

    /**
     * Send the document to a given destination: string, local file or browser.
     * Dest can be :
     *  I : send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.
     *  D : send to the browser and force a file download with the name given by name.
     *  F : save to a local server file with the name given by name.
     *  S : return the document as a string. name is ignored.
     *  FI: equivalent to F + I option
     *  FD: equivalent to F + D option
     *  true  => I
     *  false => S
     *
kroseva

Change this line $html2pdf->Output('pdf_demo.pdf'); to $html2pdf->Output('pdf_demo.pdf', 'D'); and it will force browser to automatically download the pdf file.

Send PDF to browser with a specific name

$html2pdf->Output('document_name.pdf');

$html2pdf->Output('document_name.pdf', false);

$html2pdf->Output('document_name.pdf', '');

$html2pdf->Output('document_name.pdf', 'I');

Force the browser to download the PDF file with a specific name

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

Write the contents of a PDF file on the server

Attention, this writing on your server must be used with caution. No verification is made on the existence of the file

$html2pdf->Output('directory/filename_xxxx.pdf', 'F');

Retrieve the contents of the PDF and then do whatever you want

$content_PDF = $html2pdf->Output('', true);

$content_PDF = $html2pdf->Output('', 'S');

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!