PHP-font-lib 必须通过 composer 安装或复制到 lib/php-font-lib

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13431905/
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 05:24:08  来源:igfitidea点击:

PHP-font-lib must either be installed via composer or copied to lib/php-font-lib

phpdompdf

提问by HymanTurky

i'm trying to convert some html to pdf. After some google search i find dompdfbut when i try to convert i retrieve

我正在尝试将一些 html 转换为 pdf。经过一些谷歌搜索后,我找到了dompdf,但是当我尝试转换时,我检索到了

PHP-font-lib must either be installed via composer or copied to lib/php-font-lib

This is what i'm trying to do:

这就是我想要做的:

require 'pdf/dompdf.php';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");

How can i solve? Thanks!

我该如何解决?谢谢!

回答by Fabien Ménager

Dompdf moved recently to Github, and we also added Composer support. For this, we removed the reference to the required external library php-font-lib.

Dompdf 最近移至Github,我们还添加了 Composer 支持。为此,我们删除了对所需外部库php-font-lib的引用。

Note: If you are using composer to install dompdf (and php-font-lib), you need to put define("DOMPDF_ENABLE_AUTOLOAD", false);in dompdf_config.custom.inc.php. This will then allow composer to autoload php-font-libwhich is installed through dompdf's composer.json file. Otherwise, you may still get an error. (See this issue)

注意:如果您使用 composer 安装 dompdf(和php-font-lib),则需要放入define("DOMPDF_ENABLE_AUTOLOAD", false);dompdf_config.custom.inc.php。这将允许 composer 自动加载通过 dompdf 的 composer.json 文件安装的php-font-lib。否则,您可能仍会收到错误消息。(见这个问题

If you are not using composer and want to use the latest edition of dompdf with this library: (source)

如果您不使用作曲家并希望在此库中使用最新版本的 dompdf:(来源

  • Get the latest dompdf release from Githuband extract it into a directory.
  • Download the library release also from Github
  • 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.
  • Github获取最新的 dompdf 版本并将其解压缩到一个目录中。
  • 也从Github下载库版本
  • 创建 dompdf/lib/php-font-lib/classes/ 目录。
  • 在 zip 文件中,获取 src/FontLib/ 文件夹的内容并将其粘贴到您新创建的目录中。

回答by Loren

While my edit is being reviewed, I'll post the details here for the latest dompdf 0.6.1

在我的编辑时,我将在此处发布最新 dompdf 0.6.1 的详细信息

If you are using composer to install dompdf (and php-font-lib), you need to put define("DOMPDF_ENABLE_AUTOLOAD", false);in dompdf_config.custom.inc.php. This will then allow composer to autoload php-font-lib which is installed through dompdf's composer.json file. Otherwise, you may still get an error. (See this Issue #636)

如果你使用 composer 安装 dompdf(和 php-font-lib),你需要放入define("DOMPDF_ENABLE_AUTOLOAD", false);dompdf_config.custom.inc.php。这将允许 composer 自动加载通过 dompdf 的 composer.json 文件安装的 php-font-lib。否则,您可能仍会收到错误消息。(请参阅此问题 #636)

If you are not using composer and want to use the latest edition of dompdf, you will need to manually install php-font-lib: (https://stackoverflow.com/a/24505929/3854385)

如果你没有使用 composer 而想使用最新版本的 dompdf,你需要手动安装 php-font-lib: ( https://stackoverflow.com/a/24505929/3854385)

  • Get the latest dompdf release from Githuband extract it into a directory.
  • Download the library release also from Github
  • 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.
  • Github获取最新的 dompdf 版本并将其解压缩到一个目录中。
  • 也从Github下载库版本
  • 创建 dompdf/lib/php-font-lib/classes/ 目录。
  • 在 zip 文件中,获取 src/FontLib/ 文件夹的内容并将其粘贴到您新创建的目录中。

回答by Fred Wuerges

Another trick, to avoid the change of automated downloaded files from Composer, is define the DOMPDF_ENABLE_AUTOLOADand after reload the config file:

另一个技巧,为了避免从 Composer 自动下载文件的更改,是DOMPDF_ENABLE_AUTOLOAD在重新加载配置文件后定义和:

// Disable DOMPDF's internal autoloader if you are using Composer
define('DOMPDF_ENABLE_AUTOLOAD', false);
require_once CONFIG_DIR . 'vendor/dompdf/dompdf/dompdf_config.inc.php';

$dompdf = new \DOMPDF;