简体   繁体   English

在PDFBundle(PHPPdf)中使用其他字体

[英]Use another font in PDFBundle (PHPPdf)

I use the PdfBundle (PHPPdf) in Symfony2 and want to use another font. 我在Symfony2中使用PdfBundle(PHPPdf),并希望使用其他字体。 I want to add the font.xml file to the config.yml in the app folder: 我想将font.xml文件添加到app文件夹中的config.yml中:

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

But it say always File "@FoundationBundle/Resources/config/fonts.xml" doesn't exist or is unreadable I try different variations but I don't find a solution. 但它总是说File "@FoundationBundle/Resources/config/fonts.xml" doesn't exist or is unreadable我尝试使用其他变体但找不到解决方案。 How I can load the fonts.xml File? 如何加载fonts.xml文件?

Edit: My path to the fonts.xml is /src/FoundationBundle/Resources/config/fonts.xml so I want to load this in the /app/config/config.yml . 编辑:我的fonts.xml路径是/src/FoundationBundle/Resources/config/fonts.xml因此我想将其加载到/app/config/config.yml

I hvae noticed the typo in the directory named Recources . 我注意到名为Recources的目录中有错字。 It should be Resources . 应该是Resources

Apart from that, if I remember correctly, this bundle does not support "bundle syntax". 除此之外,如果我没记错的话,这个捆绑软件不支持“捆绑语法”。 Try using this instead: 尝试使用此代替:

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

Put your fonts.xml into /path/to/your/project/app/Resources/config/ 将您的fonts.xml放入/path/to/your/project/app/Resources/config/

I used the following syntax for load the xml File in my Foundation Bundle (Add the lines in the app/config/config.yml ): 我使用以下语法在Foundation Bundle中加载xml文件(在app/config/config.yml添加以下行):

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

Important for me is that I need to clear the cache in symfony so that it works with php app/console cache:clear --env=dev . 对我来说重要的是,我需要清除symfony中的缓存,以便它与php app/console cache:clear --env=dev I also need to copy the fonts.xml content from /vendor/psliwa/php-pdf/lib/PHPPdf/Resourced/config/fonts.xml in the new fonts.xml config. 我还需要从新的fonts.xml配置中的/vendor/psliwa/php-pdf/lib/PHPPdf/Resourced/config/fonts.xml复制fonts.xml内容。

The next problem was to set the variables in the font.xml in my Bundle. 下一个问题是在Bundle中的font.xml中设置变量。 Here I can use the Bundle Syntax again. 在这里,我可以再次使用捆绑语法。 So I set the calibri font like this in the font XML: 因此,我在字体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>

Now the font is in the Foundation Bundle under Resources/public/fonts . 现在,该字体位于Foundation Bundle中的Resources/public/fonts The fonts I saved in the Foundation Bundle in the folder Resources/public/fonts . 我保存在Foundation Bundle中的Resources/public/fonts在文件夹Resources/public/fonts

After changing the font.xml there is also a cache clear required. 更改font.xml之后,还需要清除缓存。 Also in the developer environmental ( php app/console cache:clear --env=dev ) 同样在开发人员环境中( php app/console cache:clear --env=dev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM