spipu / html2pdf

OFFICIAL PROJECT | HTML to PDF converter written in PHP
http://html2pdf.fr/en/default
Open Software License 3.0
1.67k stars 746 forks source link

Html2Pdf: Save on server and Download the same PDF file #449

Open yeshansachithak opened 5 years ago

yeshansachithak commented 5 years ago

Hi,

I'm using below code to generate PDF. Which works fine and saved to my location.

//convert to PDF
    try {
        if ($html_string !== "") {
            //Html2Pdf
            try {
                $html2pdf = new Html2Pdf('P', 'A4', 'en');
                $html2pdf->pdf->SetDisplayMode('fullpage');
                $html2pdf->writeHTML($html_string);
                //$html2pdf->output($file_dir, 'F');
                $html2pdf->output($file_dir, 'D');
            } catch (Html2PdfException $e) {
                $html2pdf->clean();
                $formatter = new ExceptionFormatter($e);
                echo $formatter->getHtmlMessage();
            }
        }
    } catch (Exception $ex) {
        echo 'Error Message :: ' . $ex->getMessage();
        die();
    }

$html2pdf->output($file_dir, 'F'); works fine. When I use $html2pdf->output($file_dir, 'D'); It's show below error on my console.

image

How can I save and download the same generated PDF?

Please advice....

LittleBigFox commented 5 years ago

Hi!

Have you try to change the header?

header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename='downloaded.pdf'");

Something like this?

Regards, LBF