Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

How can i use a custom class that extends TCPDF #41

Open
julien-its opened this issue Sep 1, 2017 · 6 comments
Open

How can i use a custom class that extends TCPDF #41

julien-its opened this issue Sep 1, 2017 · 6 comments

Comments

@julien-its
Copy link

I would like to change the header and footer functions

@sampart
Copy link
Owner

sampart commented Sep 4, 2017

Hi @julien-its,

Could you take a look at the instructions at https://github.com/whiteoctober/WhiteOctoberTCPDFBundle#using-a-custom-class and see if they provide the information that you need?

If you're still stuck, add further comments to this issue and we'll help you further and also think whether the documentation needs updating.

Thanks
Sam

@sampart
Copy link
Owner

sampart commented Sep 4, 2017

Oh, and if you don't need further help, let us know that too so that we can close this issue! Thanks

@julien-its
Copy link
Author

Hello, Thank you for your answer. I actuly found the solution but not like explained in the Readme

Doing this :

white_october_tcpdf:
    class: 'Acme\MyBundle\MyTCPDFClass'

The class is never called

So i created a new class that extends TCPDF with Header function

class InvoiceTcpdf extends \TCPDF
{
public function Header(){ ... }
}

And instead of using

$this->pdf = $this->tcpdfService->create('vertical', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

I instantialize my custom class

$this->pdf = new \AppBundle\Services\Export\Pdf\InvoiceTcpdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

It works but maybe there is a beter solution

Regards
Julien

@sampart
Copy link
Owner

sampart commented Sep 7, 2017

Hi Julien,

I've done a test of the custom-class functionality here and all seems to be working as expected. Could you update your config to look like this?

white_october_tcpdf:
    class: 'Namespace\InvoiceTcpdf'

Replace Namespace with the appropriate namespace.

And then use

$this->pdf = $this->tcpdfService->create('vertical', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

and let me know if that works?

If it doesn't, can you show me where you're getting $this->tcpdfService from so I can check that? Thanks

@julien-its
Copy link
Author

Sorry it doesn't work

My service.yml :

white_october_tcpdf:
        class: AppBundle\Services\Exports\Pdf\InvoiceTcpdf

    AppBundle\Services\Exports\Pdf\InvoiceService:
        public: true
        class: AppBundle\Services\Exports\Pdf\InvoiceService
        arguments:
            $em: "@doctrine.orm.entity_manager"
            $tcpdf: '@white_october.tcpdf'

In InvoiceService :

$this->pdf = $this->tcpdfService->create('vertical', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

var_dump($this->pdf) return object(TCPDF)

When doing in InvoiceService :

$this->pdf = new \AppBundle\Services\Exports\Pdf\InvoiceTcpdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

var_dump($this->pdf) return object(AppBundle\Services\Exports\Pdf\InvoiceTcpdf)

$this->tcpdfService is a parameter given in the service.yml

` AppBundle\Services\Exports\Pdf\InvoiceService:
public: true
class: AppBundle\Services\Exports\Pdf\InvoiceService
arguments:
$em: "@doctrine.orm.entity_manager"
$tcpdf: '@white_october.tcpdf'``

it's the $tcpdf param

@sampart
Copy link
Owner

sampart commented Oct 19, 2017

@julien-its I think the problem is these lines:

white_october_tcpdf:
        class: AppBundle\Services\Exports\Pdf\InvoiceTcpdf

These should go in config.yml, not services.yml as you don't need to define a new service, you need to configure an existing one.

Could you move those lines to config.yml and try again please?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants