PDF不存储在文件夹内使用PHP [英] PDF not store inside the folder using php

查看:112
本文介绍了PDF不存储在文件夹内使用PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将我的pdf文件存储在数据库中的文件夹中,但它仅适用于MAMP服务器。我的代码如下所示:

  $ 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);

任何人都可以帮我吗?

解决方案

在你的代码早期,你可以调用 $ dompdf-> stream()。此方法将PDF流式传输并暂停脚本的执行。我不确定它为什么在MAMP上工作,但不是其他服务器,但如果你重新安排你的脚本,你应该有更多的运气。 code> $ 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));


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?

解决方案

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));

这篇关于PDF不存储在文件夹内使用PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆