Extend TCPDF in AJAX class. would i need to use custom IDE code for this?

53 views
Skip to first unread message

TLWebdesignNL

unread,
Jun 24, 2020, 4:54:16 AM6/24/20
to Joomla Component Builder
Hi,

I create a PDF on the fly through JCB ajax. Now i want to create custom footer in TCPDF. But this needs me to extend the tcpdf class. But since i'm already in the ajax class i'm unable to do so.

Is there another way besides custom code hash automation to extend this class and use it in my ajax.php model?

Kind regards,

Tom

Balearian Google

unread,
Jun 24, 2020, 7:24:57 AM6/24/20
to TLWebdesignNL, Joomla Component Builder
Hello Tom,
As TCPDF is a php class, did you think to pass all info to a php function (ajax model) which will do all the “dirty” job?
It’s easy with JCB using “Javascript & CSS" tab (use the first field: Add JavaScript (file)) and php tab (use the first field as well (Add PHP (AJAX) ).

Hope it helps.

--
You received this message because you are subscribed to the Google Groups "Joomla Component Builder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jcb+uns...@vdm.io.
To view this discussion on the web visit https://groups.google.com/a/vdm.io/d/msgid/jcb/3c3f131e-46e0-44ba-aa9d-1c426a466b37n%40vdm.io.

TLWebdesignNL

unread,
Jun 24, 2020, 11:16:13 AM6/24/20
to Joomla Component Builder, jcodewalker, Joomla Component Builder, TLWebdesignNL .
HI,

Thanks for replying but i have the PDF working fine. Even have it return as a download popup without saving anything to disk. If anyone is interested i would'nt mind sharing the code.

But now i want to take it a step further. To customize the TCPDF footer i need to override the TCPDF class. but since everything you put in the PHP AJAX custom field is already inside a class of "AJAX" i'm not able to initiate a class override on tcpdf. I now fixed this by adding a custom code hash automation on the ajax.php and have it insert the override before the ajax class starts. Works well but since llewellyn warns us about using this (and i've been able to avoid this up till today) i was wondering if maybe i overlooked something here that would be able to put stuff outside the class without needing to resort to custom code hash automation.

Op woensdag 24 juni 2020 om 13:24:57 UTC+2 schreef jcodewalker:

Balearian Google

unread,
Jun 24, 2020, 11:39:51 AM6/24/20
to TLWebdesignNL, Joomla Component Builder
I think I’m not able to understand your problem, so forgive me if I’m wrong.

Somewere in your code you have to include the tcpdf class, otherwise it is not available. In the same point you can include your own file which extends TCPDF class. Then you call yourOwnExtendingTcpdfClass instead of TCPDF.

TLWebdesignNL

unread,
Jun 24, 2020, 12:03:36 PM6/24/20
to Joomla Component Builder, jcodewalker, Joomla Component Builder, TLWebdesignNL .
Well i'm not calling any own files. But i think you're not far off on understanding my question. Maybe moving it to a seperate file would would work? But putting it "plain text" inside the class it doesn't work because php doesn't support classes in classes. So i now used custom code to place the class override outside the "class [[[Component]]]ModelAjax extends JModelList"

See screenshot below. I'm not sure adding it through a file would fix the classes inside classes limitation tho.

Schermafbeelding 2020-06-24 om 17.56.21.png

If i don't do the footer override i could just load everything inside my generatePdf function like this:

Schermafbeelding 2020-06-24 om 18.00.59.png
I've got it working now doing it like this. was just wondering if there would possibly be a cleaner method.
Op woensdag 24 juni 2020 om 17:39:51 UTC+2 schreef jcodewalker:

Balearian Google

unread,
Jun 24, 2020, 12:15:03 PM6/24/20
to TLWebdesignNL, Joomla Component Builder
Yes, you should move it.

Il giorno 24/giu/2020, alle ore 18:03, 'TLWebdesignNL' via Joomla Component Builder <j...@vdm.io> ha scritto:

Well i'm not calling any own files. But i think you're not far off on understanding my question. Maybe moving it to a seperate file would would work? But putting it "plain text" inside the class it doesn't work because php doesn't support classes in classes. So i now used custom code to place the class override outside the "class [[[Component]]]ModelAjax extends JModelList"

See screenshot below. I'm not sure adding it through a file would fix the classes inside classes limitation tho.

<Schermafbeelding 2020-06-24 om 17.56.21.png>

If i don't do the footer override i could just load everything inside my generatePdf function like this:

To view this discussion on the web visit https://groups.google.com/a/vdm.io/d/msgid/jcb/449aed90-019b-496d-859a-7cbe0be43476n%40vdm.io.
<Schermafbeelding 2020-06-24 om 18.00.59.png><Schermafbeelding 2020-06-24 om 17.56.21.png>

Balearian Google

unread,
Jun 24, 2020, 12:24:02 PM6/24/20
to TLWebdesignNL, Joomla Component Builder
Obviously your new file must be a php file…
<?php
defined('_JEXEC') or die('Restricted access);
class PROFIELPDF extends TCPF {
bla bla bla
}
Il giorno 24/giu/2020, alle ore 18:03, 'TLWebdesignNL' via Joomla Component Builder <j...@vdm.io> ha scritto:

Well i'm not calling any own files. But i think you're not far off on understanding my question. Maybe moving it to a seperate file would would work? But putting it "plain text" inside the class it doesn't work because php doesn't support classes in classes. So i now used custom code to place the class override outside the "class [[[Component]]]ModelAjax extends JModelList"

See screenshot below. I'm not sure adding it through a file would fix the classes inside classes limitation tho.

<Schermafbeelding 2020-06-24 om 17.56.21.png>

If i don't do the footer override i could just load everything inside my generatePdf function like this:

TLWebdesignNL

unread,
Jun 25, 2020, 3:19:52 AM6/25/20
to Joomla Component Builder, jcodewalker, Joomla Component Builder, TLWebdesignNL .
Ah ok thanks for the help! That sounds like a more "proper" way indeed.

Op woensdag 24 juni 2020 om 18:24:02 UTC+2 schreef jcodewalker:

TLWebdesignNL

unread,
Jun 26, 2020, 7:46:01 AM6/26/20
to Joomla Component Builder, TLWebdesignNL ., jcodewalker, Joomla Component Builder
It worked like a charm. Did took me some time to figure out how to do it so i'll write it down here for future reference for other users.

I created a Library in JCB with these settings:
- Target: "media"
- File Behaviour: "Custom script" (i tried "do not add" but then i can't specify a file to include in the package. I couldn't find any info in the video tuts on what "do not add" could be used for)
- PHP setDocument(): // ( I just added two slashes so i didn't get an error on save because it expects a script)
- Then i linked the file per video tutorial on Joomla Mount JCB (https://www.youtube.com/watch?v=rDjvgLYOt1o)
- Then i pointed the target path to the assets folder in my component. like this "/components/com_componentname/assets/"

Then i used this code to import the document: "jimport('components.com_componentname.models.filename', JPATH_ROOT);" inside my function inside the php scripting area of your needs.
      - where componentname is your components name of course and filename is the name of the file without extensions. Make sure not to use periods in your filename!

If i did something wrong or if it could be improved on feel free to reply.
Kind regards,

Tom

Op donderdag 25 juni 2020 om 09:19:52 UTC+2 schreef TLWebdesignNL .:

TLWebdesignNL

unread,
Jun 26, 2020, 8:02:54 AM6/26/20
to Joomla Component Builder, TLWebdesignNL ., jcodewalker, Joomla Component Builder
OK i got an ammendment myself already. Browsing other recent topics here i found this one and of course this would've been a much easier way to get that file in the right place:


The Folder & Files area is located in the Settings tab of your component.

Op vrijdag 26 juni 2020 om 13:46:01 UTC+2 schreef TLWebdesignNL .:

Franz

unread,
Dec 7, 2020, 9:31:30 AM12/7/20
to Joomla Component Builder, tomt...@gmail.com, jcodewalker, Joomla Component Builder
Hi Tom

Regarding using TCPDF in JCB, you mention " Even have it return as a download popup without saving anything to disk. If anyone is interested i would'nt mind sharing the code".

I have been struggling the past week or two and would really appreciate if you could share the mechanism. I seem to be getting stuck on how to achieve the popup without saving.....

Regards

Franz

((ewe))yn

unread,
Dec 19, 2020, 4:31:13 PM12/19/20
to Joomla Component Builder, Franz, tomt...@gmail.com, jcodewalker, Joomla Component Builder
We are moving to GitHub Discussions. We will keep this open to give access to old issues, resolved. But please continue conversations on the new github discussions area ;)
Reply all
Reply to author
Forward
0 new messages