使用html2pdf在后台保存pdf

Saving pdf in the background using html2pdf

尝试使用html2pdf类自动生成pdf。我得到了以下运行良好的代码,只是有人必须手动保存pdf。但是,无论何时添加新产品,我都希望在没有用户干预的情况下自动将pdf保存到某个文件夹,并将此值存储在数据库中以供将来参考。
如何在不显示任何弹出窗口或不要求用户干预的情况下,"无声地"保存pdf,即在后台保存?
预先感谢。

1
2
3
4
5
6
7
8
9
10
11
12
 include('pdf_content.php');
 $content = ob_get_clean();
// convert to PDF
require_once('html2pdf/html2pdf.class.php');
try
{
    $html2pdf = new HTML2PDF('P', 'A4', 'en');
    $html2pdf->pdf->SetDisplayMode('fullpage');
    $html2pdf->setDefaultFont('Arial');
    $html2pdf->writeHTML($content, isset($_GET['vuehtml']));
    //$html2pdf->Output($file_name.'_'.date("dmY").'.pdf');
    $html2pdf->Output($product_id.'_'.$file_name.'_'.date("dmY").'.pdf');

您可以尝试在每次添加新产品时调用此脚本,尽管那样您实际上不会在"后台"中执行此操作...

有关更多信息,请注意以下问题:"提交表单后如何在后台运行PHP脚本?"

编辑:

如果希望将文件保存在服务器上而不是将其输出到浏览器,则可以使用其他参数。另请参见html2pdf-wiki。请注意,您无法将文件保存在用户计算机上!

1
$html2pdf->Output('directory/file_xxxx.pdf', 'F');