Welcome Guest, Not a member yet? Register   Sign In
tcpdf configuration
#1

Hi,
I'm using tcpdf 6.4.1 with Codeigniter 4. It works without any problems.
There are a few changes in the configuration that I need:
For example, I have changed the definition for PDF_MARGIN_TOP in vendor/tecnickom/tcpdf/config.
I would prefer to leave the vendor directory untouched and keep those changes inside my /app directory. Any ideas how this can be done?
Reply
#2

(07-07-2022, 07:17 AM)Erwin Wrote: Hi,
I'm using tcpdf 6.4.1 with Codeigniter 4. It works without any problems.
There are a few changes in the configuration that I need:
For example, I have changed the definition for PDF_MARGIN_TOP in vendor/tecnickom/tcpdf/config.
I would prefer to leave the vendor directory untouched and keep those changes inside my /app directory. Any ideas how this can be done?

I do not use the library directly, but will try to help you.

When you start using the tcpdf library, you initiate a new tcpdf object:

PHP Code:
$pdf = new TCPDF(PDF_PAGE_ORIENTATIONPDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false); 

and then you can manipulate it's properties through the TCPDF class methods.

The property you refer to is defined in the config file as a constant:

PHP Code:
define ('PDF_MARGIN_TOP'27); 

But as described in the documentation, you can change it through the TCPDF method SetMargins:

PHP Code:
$pdf->SetMargins(PDF_MARGIN_LEFTPDF_MARGIN_TOPPDF_MARGIN_RIGHT); 

Instead of using the defaults (as in the example line above) you can use your own numbers - all or part of them:

PHP Code:
$pdf->SetMargins(PDF_MARGIN_LEFT33PDF_MARGIN_RIGHT); 
==

Donatas G.
Reply
#3

(07-11-2022, 08:42 AM)dgvirtual Wrote:
(07-07-2022, 07:17 AM)Erwin Wrote: Hi,
I'm using tcpdf 6.4.1 with Codeigniter 4. It works without any problems.
There are a few changes in the configuration that I need:
For example, I have changed the definition for PDF_MARGIN_TOP in vendor/tecnickom/tcpdf/config.
I would prefer to leave the vendor directory untouched and keep those changes inside my /app directory. Any ideas how this can be done?

I do not use the library directly, but will try to help you.

When you start using the tcpdf library, you initiate a new tcpdf object:

PHP Code:
$pdf = new TCPDF(PDF_PAGE_ORIENTATIONPDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false); 

and then you can manipulate it's properties through the TCPDF class methods.

The property you refer to is defined in the config file as a constant:

PHP Code:
define ('PDF_MARGIN_TOP'27); 

But as described in the documentation, you can change it through the TCPDF method SetMargins:

PHP Code:
$pdf->SetMargins(PDF_MARGIN_LEFTPDF_MARGIN_TOPPDF_MARGIN_RIGHT); 

Instead of using the defaults (as in the example line above) you can use your own numbers - all or part of them:

PHP Code:
$pdf->SetMargins(PDF_MARGIN_LEFT33PDF_MARGIN_RIGHT); 
Hi,
thanks for your answer. This works with definitions that aren't used in the TCPDF class. In my case, I want to set K_TCPDF_CALLS_IN_HTML to true to be able to use the tcpdf  tag in HTML.
Reply
#4

(07-11-2022, 12:07 PM)Erwin Wrote: Hi,
thanks for your answer. This works with definitions that aren't used in the TCPDF class. In my case, I want to set K_TCPDF_CALLS_IN_HTML to true to be able to use the tcpdf  tag in HTML.
Mhm, if you look at the code of tcpdf, https://github.com/tecnickcom/TCPDF/blob...php#L19484 , you see that the variable you want to set is a global that is not automatically expected to be set, so you might try to set it yourself using


Code:
define("K_TCPDF_CALLS_IN_HTML", true)

Have you tried it? It should be done before the library is initiated (before the $pdf = new...) so that when the lib config is read, it finds the global variable set and does not create it anew (see the config file on how it is set: https://github.com/tecnickcom/TCPDF/blob...g.php#L227 )
==

Donatas G.
Reply
#5

(07-28-2022, 12:59 PM)dgvirtual Wrote:
(07-11-2022, 12:07 PM)Erwin Wrote: Hi,
thanks for your answer. This works with definitions that aren't used in the TCPDF class. In my case, I want to set K_TCPDF_CALLS_IN_HTML to true to be able to use the tcpdf  tag in HTML.
Mhm, if you look at the code of tcpdf, https://github.com/tecnickcom/TCPDF/blob...php#L19484 , you see that the variable you want to set is a global that is not automatically expected to be set, so you might try to set it yourself using


Code:
define("K_TCPDF_CALLS_IN_HTML", true)

Have you tried it? It should be done before the library is initiated (before the $pdf = new...) so that when the lib config is read, it finds the global variable set and does not create it anew (see the config file on how it is set: https://github.com/tecnickcom/TCPDF/blob...g.php#L227 )

Hi,
I think I have found a nice solution now:

I have copied tcpdf_config.php to app/Config/, and added define('K_TCPDF_EXTERNAL_CONFIG', true); at the beginning.
Then, I added this new config file in composer.json:
Code:
"autoload": {
    ...
    "files": [
        "app/Config/tcpdf_config.php"
    ]
},

Finally, I did a "composer dump-autoload" to update the autoloader.
All configuration changes can be done in app/Config/tcpdf_config.php now.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB