Changing WhiteOctober TCPDF Package Configuration Values

I started using the WhiteOctober TCPDF package in my symfony project, but cannot figure out how to change the default configuration values, such as page format. I tried putting this 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 completely ignored when called

 $pdf = $this->get('white_october.tcpdf')->create(); 

in my controller. The generated PDF file is still in A4 format with no headers and default fields.

Did I miss something to associate the pool with my user configuration?

+4
source share
4 answers

I have the same problem. Change vendor code is not recommended. My workaround is below:

I created a new class called "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(), 
+1
source

You need to edit the tcpdf_config.php file in the vendor / tecnick.com / tcpdf / config folder.

0
source

Add this code ...

  if (preg_match("/^pdf_/i", $k)) { if (!defined($constKey)) { define($constKey, $v); } } 

to package file

  /vendor/whiteoctober/tcpdf-bundle/WhiteOctober/TCPDFBundle/WhiteOctoberTCPDFBundle.php 

The source file https://github.com/wrep/TCPDFBundle/blob/master/WrepTCPDFBundle.php currently only matches configuration parameters starting with ^k configuration parameters for this package are shown here

https://github.com/wrep/TCPDFBundle/blob/master/WrepTCPDFBundle.php

I had to add some more configuration parameters from tcpdf_config.php that were not specified in the above documentation configuration example. Here is my full white_october_tcpdf: section in app/config/config.yml

 ...ober_tcpdf: file: %kernel.root_dir%/../vendor/tecnick.com/tcpdf/tcpdf.php class: TCPDF tcpdf: k_path_url: %kernel.root_dir%/../vendor/tecnick.com/tcpdf/ k_path_main: %kernel.root_dir%/../vendor/tecnick.com/tcpdf/ k_path_fonts: %kernel.root_dir%/../vendor/tecnick.com/tcpdf/fonts/ k_path_cache: %kernel.cache_dir%/tcpdf k_path_url_cache: %kernel.cache_dir%/tcpdf k_path_images: %kernel.root_dir%/../vendor/tecnick.com/tcpdf/examples/images/ k_blank_image: %kernel.root_dir%/../vendor/tecnick.com/tcpdf/examples/images/_blank.png k_cell_height_ratio: 1.25 k_title_magnification: 1.3 k_small_ratio: 0.66666666666667 k_thai_topchars: true k_tcpdf_calls_in_html: true k_tcpdf_external_config: true head_magnification: 10 pdf_page_format: LETTER pdf_page_orientation: P pdf_creator: TCPDF pdf_author: TCPDF pdf_header_title: Example Title pdf_header_string: "this is motto - My Company\nwww.mycompany.org" pdf_header_logo: ../../../../../web/bundles/home/images/peas.jpg pdf_header_logo_width: 30 pdf_unit: mm pdf_margin_header: 5 pdf_margin_footer: 10 pdf_margin_top: 27 pdf_margin_bottom: 25 pdf_margin_left: 15 pdf_margin_right: 15 pdf_font_name_main: helvetica pdf_font_size_main: 10 pdf_font_name_data: helvetica pdf_font_size_data: 8 pdf_font_monospaced: courier pdf_image_scale_ratio: 1.25 
0
source

Well, now I am solving the same problem:

You need to define your necessary constants, as mirk said,

 white_october_tcpdf: tcpdf: . . . 

then you need to change the class: /vendor/whiteoctober/tcpdf-bundle/WhiteOctober/TCPDFBundle/WhiteOctoberTCPDFBundle.php with this code

  // All K_ and _pdf constants are required if (preg_match("/^k_/i", $k) OR preg_match("/^pdf_/i", $k)) { if (!defined($constKey)) { $value = $this->container->getParameterBag()->resolveValue($v); if (($k === 'k_path_cache' || $k === 'k_path_url_cache') && !is_dir($value)) { $this->createDir($value); } define($constKey, $value); } } 

to compare both types of constants.

0
source

Source: https://habr.com/ru/post/1444151/


All Articles