Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yeshansachithak opened this Issue Feb 13, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@yeshansachithak
Copy link

yeshansachithak commented Feb 13, 2019

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

This comment has been minimized.

Copy link
Contributor

LittleBigFox commented Feb 18, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.