Custom fields not rendered into pdf

Phoca PDF - creating PDF documents in Joomla! CMS
isidrobaq
Phoca Newbie
Phoca Newbie
Posts: 6
Joined: 03 May 2019, 11:07

Custom fields not rendered into pdf

Post by isidrobaq »

I've created an override for my com_content articles, in order to display custom fields along with "regular" article textarea. The issue I'm having is that phocaPDF is only rendering the content of the Joomla core textarea into the pdf. My custom fields are just ignored. Is there anything I need to add to my code in order to phocaPDF "detect" my custom fields?

Thanks in advance!
isidrobaq
Phoca Newbie
Phoca Newbie
Posts: 6
Joined: 03 May 2019, 11:07

Re: Custom fields not rendered into pdf

Post by isidrobaq »

Ok, I think I figured out that phocaPDF is only able to render article text (introtext + fulltext). In which file is that content retrieved and prepared? I mean, where exactly is article's text prepared to be used by the content plugin via $document->getArticleText() ?

Maybe /administrator/components/com_phocapdf/files/com_content/views/articles/view.pdf.php?

I'd like to play a bit with that to try to reproduce my override there, and see if I can make it being printed into the pdf.

Thanks!
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Custom fields not rendered into pdf

Post by Jan »

Hi, yes, PDF only prints the article text (including plugins but depends on which plugins, because it is not possible to transform JS or complicated HTML to PDF)

The PDF function just takes the article content and displays it as PDF:

components\com_content\views\article\view.pdf.php

with help of plugin:
plugins\phocapdf\content\content.php

In fact it is the same Joomla! function like displaying other than HTML formats (raw, json, ...)

Jan
If you find Phoca extensions useful, please support the project
isidrobaq
Phoca Newbie
Phoca Newbie
Posts: 6
Joined: 03 May 2019, 11:07

Re: Custom fields not rendered into pdf

Post by isidrobaq »

Hi Jan

Thanks a lot for the reply. It's all clear now. Would be great if there would be an easy way to override com_content's view.pdf.php file :(. Anyway, I've managed to print default imtrotext and fulltext article images in my pdf.

One more question: to implement custom fields, it's necessary that onContentPrepare event is triggered in the component, as the official docu points

https://docs.joomla.org/J3.x:Adding_cus ... _component

I've checked that when using view.pdf.php, joomla custom fields are not available in $item variable, so most probably that event is not triggered in the component. Where would be the right place to do that in phocaPDF component?

Thanks!
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Custom fields not rendered into pdf

Post by Jan »

Hi, unfortunately, for now I don't have any experiences with custom fields and the documentation is not complete :-( , but I would say, this should be managed in Phoca PDF content plugin so the solution works only for the needs of com_content.
What I didn't find in the documentation is, what must be done to load the information about custom fields together with articles - if some specific SQL or if there is some method in Joomla! to load it directly with articles or load it after specailly for each article, or ... :idea:

The view PDF just loads the $item information form standard article model:

Code: Select all

$item 		= $this->get('Item');
so there is no specific code to somehow influence what will $item include.

Jan
If you find Phoca extensions useful, please support the project
isidrobaq
Phoca Newbie
Phoca Newbie
Posts: 6
Joined: 03 May 2019, 11:07

Re: Custom fields not rendered into pdf

Post by isidrobaq »

Hi Jan

If I understood it correctly, custom fields info is loaded in com_content when onPrepareContent event is triggered. As documentation says, if you want to use them in your component, you need to make sure that event is triggered, and then you can make use of FieldsHelper::getFields() method. So my guess is that you need to trigger onPrepareContent event in PhocaPdf component, and then you'll have custom fields loaded into $item. That's why I was asking where would be the right place to trigger that event in PhocaPdf; I'm going to make direct modification of a PhocaPdf core file (yeah, I know, this is a big "NO", but I need those custom fields in my pdfs), and at least I want to make it in the "right" place. If it works, I'll share my code here, and maybe you can consider adding that feature to future versions of the component.

Thanks a lot for your attention to this issue ;).
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Custom fields not rendered into pdf

Post by Jan »

Hi, will be great to get a copy of your version.
So my guess is that you need to trigger onPrepareContent event in PhocaPdf component
Phoca PDF does not have any text output, it just takes the article output, so there is no place for onPrepareContent as Phoca PDF does not have any content.

You can enable the "internal" com_content events with this parameter in Phoca PDF Content Plugin:

Image

but this of course only works for some specific content plugins with simple output (e.g. Phoca Gallery Content plugin) not for plugins which e.g. change content with help of Javascript, etc. (as there is no option how to do it in static PDF). But maybe you can customize this place to include the custom fields there.

Jan
If you find Phoca extensions useful, please support the project
Post Reply