php dompdf 无法加载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15028250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:25:10  来源:igfitidea点击:

dompdf fails to load

phppdfincludedompdf

提问by Mark T. Johns

I am trying to get dompdf running on an in-house server. With the default config.inc.php settings, I get the following when running the equivalent of the demo 'Hello Wolrd' script:

我试图让 dompdf 在内部服务器上运行。使用默认的 config.inc.php 设置,在运行演示“Hello Wolrd”脚本的等效项时,我得到以下信息:

Warning: require_once(/var/www/dompdf-master/lib/php-font-lib/classes/font.cls.php): failed to open stream: No such file or directory in /var/www/dompdf-master/dompdf_config.inc.php on line 335
Fatal error: require_once(): Failed opening required '/var/www/dompdf-master/lib/php-font-lib/classes/font.cls.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/dompdf-master/dompdf_config.inc.php on line 335 

When I turn off DOMPDF_ENABLE_AUTOLOAD, I no longer get this warning, but the code fails with the following:

当我关闭时DOMPDF_ENABLE_AUTOLOAD,我不再收到此警告,但代码失败并显示以下内容:

Fatal error: Class 'DOMPDF' not found in /var/www/rfq/test.php on line 115

The following is the code:

以下是代码:

require_once("/var/www/dompdf-master/dompdf_config.inc.php");

$dompdf = new DOMPDF(); // this is the line that fails
$dompdf->load_html($quotehtml);
$dompdf->render();
$dompdf->stream("rfq".$_REQUEST['quoteid'].".pdf");

This is Ubuntu 12.04, up-to-date on patches, with default Apache settings.

这是 Ubuntu 12.04,补丁是最新的,具有默认的 Apache 设置。

Thanks so much.

非常感谢。

回答by Mikepote

  • Go to https://github.com/PhenX/php-font-liband download the library.
  • Create the dompdf/lib/php-font-lib/classes/directory.
  • In the zip file, take the contents of the src/FontLib/folder and paste that into your newly created directory.
  • 转到https://github.com/PhenX/php-font-lib并下载库。
  • 创建dompdf/lib/php-font-lib/classes/目录。
  • 在 zip 文件中,获取src/FontLib/文件夹的内容并将其粘贴到新创建的目录中。

That seemed to work for me.

这似乎对我有用。

回答by Jpsy

This is a temporary issue after the DOMPDF project moved to Github. See the answers to this question. The easiest solution to get the complete package is to download DOMPDF 0.6 beta 3 from Google Code.

这是 DOMPDF 项目移至 Github 后的临时问题。请参阅此问题的答案。获取完整包的最简单解决方案是从 Google Code下载DOMPDF 0.6 beta 3

回答by Valko Valkov

We will use dompdf in codeigniter BUT the file that I'v downloaded from GitHub doesn't has all the files that we need. Is missing all the files of php-font-lib. So we had to download it and uploaded to the respective folder. So, to have dompdf working in codeigniter you might have to download it.

我们将在 codeigniter 中使用 dompdf 但我从 GitHub 下载的文件没有我们需要的所有文件。缺少 php-font-lib 的所有文件。所以我们必须下载它并上传到相应的文件夹。因此,要让 dompdf 在 codeigniter 中工作,您可能需要下载它。

See here http://www.digitalwhores.net/codeigniter/codeigniter-dompdf-master-and-php-font-lib/

见这里 http://www.digitalwhores.net/codeigniter/codeigniter-dompdf-master-and-php-font-lib/

回答by Loren

If you are using composer to install dompdf, you need to put define("DOMPDF_ENABLE_AUTOLOAD", false);in dompdf_config.custom.inc.php. This will then allow composer to autoload the php-font-lib as it is already installed. (See this issue: https://github.com/dompdf/dompdf/issues/636)

如果使用composer安装dompdf,需要放入define("DOMPDF_ENABLE_AUTOLOAD", false);dompdf_config.custom.inc.php。这将允许 composer 自动加载已经安装的 php-font-lib。(见这个问题:https: //github.com/dompdf/dompdf/issues/636

If you are not using composer, see Mikepote's answer.

如果您没有使用作曲家,请参阅 Mikepote 的回答。

回答by cMinor

If error is not corrected after doing what other answers suggest:

如果在执行其他答案建议后没有纠正错误:

In dompdf_config.inc.php, change line 332 to point to the actual location of your Font.php  file.
mine was /php-font-lib/src/FontLib

There is no CLASSES folder that was mentioned there.

那里没有提到 CLASSES 文件夹。

回答by foxbeefly

I had almost the exact same problem. My code was working on my local dev machine - a Windows box - but then was failing on our production server - a Linux box

我遇到了几乎完全相同的问题。我的代码在我的本地开发机器上运行 - 一个 Windows 机器 - 但后来在我们的生产服务器上失败 - 一个 Linux 机器

The problem was that the "classes" directory was lower case (\app\Vendor\dompdf\lib\php-font-lib\classes) which windows did not mind - but Linux being case-sensitive did!

问题是“classes”目录是小写的(\app\Vendor\dompdf\lib\php-font-lib\classes),windows并不介意——但Linux是区分大小写的!

Simply editing the following line in dompdf_config.inc.php solved the problem:

只需在 dompdf_config.inc.php 中编辑以下行即可解决问题:

require_once(DOMPDF_LIB_DIR . "/php-font-lib/Classes/Font.php");

For consistency I renamed the directory with an uppercase "C" on the Windows box.

为了保持一致性,我在 Windows 框中用大写的“C”重命名了目录。

回答by omer Farooq

The new version of dompdf doesn't work with 'composer install' or 'composer update'. It needs special versions of font libraries which might not always be the latest versions, so this might change in future. But you can find how to install it via dompdf's documentation. Dont know why the authors haven't hardcoded these font versions inside the composer.json, but anyways here is how to do it.

新版本的 dompdf 不适用于“composer install”或“c​​omposer update”。它需要特殊版本的字体库,这些字体库可能并不总是最新版本,因此将来可能会发生变化。但是您可以通过 dompdf 的文档找到如何安装它。不知道为什么作者没有在 composer.json 中硬编码这些字体版本,但无论如何这里是如何做到的。

Currently the easiest and best way of using the library is via git (taken from the official docs)

目前使用库的最简单和最好的方法是通过 git(取自官方文档)

git clone https://github.com/dompdf/dompdf.git
cd dompdf

git clone https://github.com/PhenX/php-font-lib.git lib/php-font-lib
cd lib/php-font-lib
git checkout 0.4
cd ..

git clone https://github.com/PhenX/php-svg-lib.git php-svg-lib
cd php-svg-lib
git checkout v0.1

Then you can just do

然后你可以做

use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream( "/path-to-save-pdf-file/sample.pdf");