在 PDFBundle (PHPPDF) 中使用另一种字体

Use another font in PDFBundle (PHPPdf)

我在 Symfony2 中使用 PdfBundle (PHPPdf) 并想使用另一种字体。 我想将 font.xml 文件添加到应用程序文件夹中的 config.yml:

ps_pdf:
    fonts_file: "@FoundationBundle/Resources/config/fonts.xml"

但它总是说 File "@FoundationBundle/Resources/config/fonts.xml" doesn't exist or is unreadable 我尝试了不同的变体,但没有找到解决方案。如何加载 fonts.xml 文件?

编辑:我到 fonts.xml 的路径是 /src/FoundationBundle/Resources/config/fonts.xml 所以我想在 /app/config/config.yml.

中加载它

我注意到名为 Recources 的目录中有错字。应该是 Resources.

除此之外,如果我没记错的话,这个包不支持"bundle syntax"。试试改用这个:

ps_pdf:
    fonts_file: "%kernel_root%/Resources/config/fonts.xml"

将你的 fonts.xml 放入 /path/to/your/project/app/Resources/config/

我使用以下语法在我的 Foundation Bundle 中加载 xml 文件(在 app/config/config.yml 中添加行):

ps_pdf:
    fonts_file: "%kernel.root_dir%/../src/FoundationBundle/Resources/config/fonts.xml"

对我来说重要的是我需要清除 symfony 中的缓存,以便它与 php app/console cache:clear --env=dev 一起工作。我还需要在新的 fonts.xml 配置中从 /vendor/psliwa/php-pdf/lib/PHPPdf/Resourced/config/fonts.xml 复制 fonts.xml 内容。

下一个问题是在我的 Bundle 中设置 font.xml 中的变量。在这里我可以再次使用 Bundle Syntax。所以我在字体XML中设置了这样的calibri字体:

<font name="calibri">
    <normal src="%FoundationBundle:public/fonts/calibri.ttf%" />
    <bold src="%FoundationBundle:public/fonts/calibrib.ttf%" />
    <italic src="%FoundationBundle:public/fonts/calibrii.ttf%" />
    <bold-italic src="%FoundationBundle:public/fonts/calibribi.ttf%" />
</font>

现在该字体位于 Resources/public/fonts 下的 Foundation Bundle 中。我保存在 Foundation Bundle 文件夹中的字体 Resources/public/fonts.

更改 font.xml 后还需要清除缓存。同样在开发者环境中(php app/console cache:clear --env=dev)