简体   繁体   English

使用Dompdf保存PDF文件

[英]Save PDF file with Dompdf

using Dompdf to store data in pdf file: 使用Dompdf在pdf文件中存储数据:

This function work fine : 这个功能很好用:

$pdf = \App::make('dompdf.wrapper');
$pdf->loadHTML('<h1>Test</h1> ');
return $pdf->stream();

Now,when try 现在,当试试

$pdf = \App::make('dompdf.wrapper');
$pdf->loadHTML('<h1>Test</h1> ');
file_put_contents("test.pdf", $pdf->output());

Get error: 得到错误:

file_put_contents(test.pdf): failed to open stream: Permission denied

Do I need to create some extra folder for saving file or something ? 我是否需要创建一些额外的文件夹来保存文件或其他内容?

Tnx, P Tnx,P

To save the generated pdf to a file, use output() , ie: 要将生成的pdf 保存到文件,请使用output() ,即:

$dompdf = new Dompdf();
$dompdf->loadHtml('<h1>hello world</h1>');
$output = $dompdf->output();
file_put_contents('filename.pdf', $output);

Try this 试试这个

$pdf->load_html('<h1>Test</h1>');
$pdf->render();
$pdf->stream("data.pdf");

This resolve problem : 这解决问题:

  return PDF::loadHTML('<h1>Test</h1> ')->save('path-/my_stored_file.pdf');

This question help: 这个问题有帮助:

dompdf: loading html files to render, doesn't work dompdf:加载要渲染的html文件,不起作用

Tnx, P Tnx,P

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM