PDF not store inside the folder using php

2019-09-20 04:55发布

I tried to store my pdf file inside the folder in database.but it works only MAMP server.My code is below:

$dompdf->load_html($html);
$dompdf->set_paper("A4", "landscape");
$dompdf->render();

 $dompdf->stream($projectdetail->project_name." - Cost Report.pdf", array("Attachment" => false));
 $canvas = $dompdf->get_canvas();
 $font = Font_Metrics::get_font("helvetica", "bold");
 $canvas->page_text(750, 570, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));
 $canvas->page_text(25, 570, "II International P Ltd", $font, 6, array(0,0,0));
 $output = $dompdf->output();
 $file_to_save = '../files/'.$projectdetail->project_name.'/'.$projectdetail->project_name.'.pdf';
 file_put_contents($file_to_save, $output);

Can anyone help me?

标签: php html dompdf
1条回答
淡お忘
2楼-- · 2019-09-20 05:20

Early in your code you call $dompdf->stream(). This method streams the PDF and halts execution of the script. I'm not sure why it's working on MAMP but not other servers, but if you re-arrange your script as such you should have more luck.

$dompdf->load_html($html);
$dompdf->set_paper("A4", "landscape");
$dompdf->render();

$canvas = $dompdf->get_canvas();
$font = Font_Metrics::get_font("helvetica", "bold");
$canvas->page_text(750, 570, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));
$canvas->page_text(25, 570, "II International P Ltd", $font, 6, array(0,0,0));
$output = $dompdf->output();

$file_to_save = '../files/'.$projectdetail->project_name.'/'.$projectdetail->project_name.'.pdf';
file_put_contents($file_to_save, $output);

$dompdf->stream($projectdetail->project_name." - Cost Report.pdf", array("Attachment" => false));
查看更多
登录 后发表回答