服务器上的 DOMpdf

问题描述 投票:0回答:1

我在本地主机上安装了 DOMpdf(WAMP 和 dompdf 从 git 下载)并且工作正常。安装是使用 Composer 完成的。当我安装在本地主机上时,有一个名为 DOMpdf 的子目录。

我通过运行命令“apt install php-dompdf”将其安装在网络服务器上,它安装良好并重新启动了服务器。但不起作用,我的意思是在控制台中它有错误

"Failed to load resource: the server responded with a status of 500 (Internal Server Error)"

我找到了配置文件在网络服务器上的存储位置,并相应地将我的 php 文件中的位置更改为

require_once("/etc/php-dompdf/dompdf_config.inc.php");

结果我收到了不同的错误消息。

[Mon Oct 30 16:50:40.500977 2023] [php7:error] [pid 3532633] [client 10.64.4.168:64880] PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function DOMPDF::stream(), 0 passed in /var/www/html/nztimesheets/testDOMpdf.php on line 29 and at least 1 expected in /usr/share/php/dompdf/include/dompdf.cls.php:1057\nStack trace:\n#0 /var/www/html/nztimesheets/testDOMpdf.php(29): DOMPDF->stream()\n#1 {main}\n  thrown in /usr/share/php/dompdf/include/dompdf.cls.php on line 1057

搜索其他线程后,我注意到有人使用 autoload.inc.php,但这不是我的 php-dompdf 文件夹中的选项。

php代码是:

<?php
    echo('Here!');
    
    require_once("/etc/php-dompdf/dompdf_config.inc.php");
    
    echo('Here now.');

    use DOMpdf;
    use DOMpdf\options;

    $dompdf=new DOMpdf();

    $html = '<h1 style="color: blue;"> Hello this is from DOM pdf to convert html to pdf<h1>';

    $dompdf->load_html($html);

    $dompdf->set_Paper('A4','landscape');

    $dompdf->render();

    $dompdf->stream();
?>

有什么明显的原因可以解释为什么它不能在服务器上运行吗? (注意:我从服务器本地主机上的工作 php 文件中更改了 require_once)

webserver dompdf
1个回答
0
投票

我需要在stream()函数中添加文件名。

$dompdf->stream('myfilename.pdf');

在我的本地主机中,它只是在浏览器窗口中打开/创建了 pdf。

© www.soinside.com 2019 - 2024. All rights reserved.