Php 如何将DOMPDF生成的内容保存到文件?
我正在使用Dompdf创建PDF文件,但我不知道为什么它不将创建的PDF保存到服务器 有什么想法吗Php 如何将DOMPDF生成的内容保存到文件?,php,file,pdf-generation,save,dompdf,Php,File,Pdf Generation,Save,Dompdf,我正在使用Dompdf创建PDF文件,但我不知道为什么它不将创建的PDF保存到服务器 有什么想法吗 require_once("./pdf/dompdf_config.inc.php"); $html = '<html><body>'. '<p>Put your html here, or generate it with your favourite '. 'templating system.</p>
require_once("./pdf/dompdf_config.inc.php");
$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
file_put_contents('Brochure.pdf', $dompdf->output());
require_once(“./pdf/dompdf_config.inc.php”);
$html=
''.
“将你的html放在这里,或者用你最喜欢的内容生成它”。
“模板系统。”。
'';
$dompdf=新的dompdf();
$dompdf->load_html($html);
$dompdf->render();
文件内容('宣传册.pdf',$dompdf->output());
我刚刚使用了dompdf,虽然代码有点不同,但仍然有效
这是:
require_once("./pdf/dompdf_config.inc.php");
$files = glob("./pdf/include/*.php");
foreach($files as $file) include_once($file);
$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$output = $dompdf->output();
file_put_contents('Brochure.pdf', $output);
require_once(“./pdf/dompdf_config.inc.php”);
$files=glob(“./pdf/include/*.php”);
foreach($files as$file)包含一次($file);
$html=
''.
“将你的html放在这里,或者用你最喜欢的内容生成它”。
“模板系统。”。
'';
$dompdf=新的dompdf();
$dompdf->load_html($html);
$dompdf->render();
$output=$dompd->output();
文件内容('宣传册.pdf',$output);
这里唯一的区别是包含目录中的所有文件
除此之外,我唯一的建议是为写入文件指定一个完整的目录路径,而不仅仅是文件名。我确实测试了您的代码,我看到的唯一问题是您试图将文件写入的目录缺乏权限 对需要放置文件的目录授予“写入”权限。在您的情况下,它是当前目录 在linux中使用“chmod”
如果您在Windows中,请将启用“写入”的“所有人”添加到目录的安全选项卡。
版本的dompdf?有PHP错误吗?dompdf 0.5.2,PHP5.2.13我没有看到任何会阻止您保存的内容,所以我猜是服务器配置错误。也许PHP无法写入该目录?如果是这种情况,PHP将报告一个错误。检查PHP错误日志或启用错误显示。
<?php
$content='<table width="100%" border="1">';
$content.='<tr><th>name</th><th>email</th><th>contact</th><th>address</th><th>city</th><th>country</th><th>postcode</th></tr>';
for ($index = 0; $index < 10; $index++) {
$content.='<tr><td>nadim</td><td>nadim.sheikh.07@gmail.com</td><td>7737033665</td><td>247 dehligate</td><td>udaipur</td><td>india</td><td>313001</td></tr>';
}
$content.='</table>';
//$html = file_get_contents('pdf.php');
if(isset($_POST['pdf'])){
require_once('./dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF;
$dompdf->load_html($content);
$dompdf->render();
$dompdf->stream("hello.pdf");
}
?>
<html>
<body>
<form action="#" method="post">
<button name="pdf" type="submit">export</button>
<table width="100%" border="1">
<tr><th>name</th><th>email</th><th>contact</th><th>address</th><th>city</th><th>country</th><th>postcode</th></tr>
<?php for ($index = 0; $index < 10; $index++) { ?>
<tr><td>nadim</td><td>nadim.sheikh.07@gmail.com</td><td>7737033665</td><td>247 dehligate</td><td>udaipur</td><td>india</td><td>313001</td></tr>
<?php } ?>
</table>
</form>
</body>
</html>