更改 WhiteOctober TCPDF 包配置值 [英] Change WhiteOctober TCPDF bundle configuration values
问题描述
我已经开始在我的 symfony 项目中使用 WhiteOctober TCPDF 包,但我不知道如何更改默认配置值,例如页面格式.我试过把它放在我的 config.yml 中:
I've started using the WhiteOctober TCPDF bundle in my symfony project but I can't figure out how to change the default configuration values, such as page format. I've tried putting that in my config.yml:
white_october_tcpdf:
tcpdf:
k_tcpdf_external_config: true
pdf_page_format: 'LETTER'
pdf_author: 'Company Name'
pdf_header_title: 'Order Confirmation'
pdf_header_string: 'Company Name'
pdf_header_logo: '%kernel.root_dir%/../web/images/logo.png'
pdf_header_logo_width: '35'
pdf_margin_header: 15
pdf_margin_footer: 15
pdf_margin_top: 25
pdf_margin_bottom: 25
pdf_margin_left: 25
pdf_margin_right: 25
但是他们在调用时完全被忽略
but they are totally ignored when calling
$pdf = $this->get('white_october.tcpdf')->create();
在我的控制器中.生成的 PDF 仍然是 A4,没有标题和默认边距.
in my controller. The generated PDF is still in A4 with no header and defaults margins.
我是否遗漏了一些东西让捆绑包采用我的自定义配置?
Am I missing something to make the bundle take my custom configuration?
推荐答案
我有同样的问题.更改供应商代码不是最佳实践.我的解决方法如下:
I have the same problem. Alter vendor code is not best practice. My workaround is below:
我在 src 文件夹中创建了一个新类CustomWhiteOctoberTCPDFBundle".
I created a new class "CustomWhiteOctoberTCPDFBundle" in my src folder.
namespace TCPDFBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class CustomWhiteOctoberTCPDFBundle extends Bundle
{
public function getParent()
{
return 'WhiteOctoberTCPDFBundle';
}
public function boot() {
//Put modified method as mentioned in the previous answer
}
}
On AppKernel.php put:
public function registerBundles()
{
$bundles = array(...
new WhiteOctober\TCPDFBundle\WhiteOctoberTCPDFBundle(),
new TCPDFBundle\CustomWhiteOctoberTCPDFBundle(),
这篇关于更改 WhiteOctober TCPDF 包配置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!