PDF Plugin for custom component

Phoca PDF - creating PDF documents in Joomla! CMS
netamity
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 30 Apr 2020, 13:17

PDF Plugin for custom component

Post by netamity » 30 Apr 2020, 13:33

How can I create a PhocaPDF plugin for a custom component?
I've taken a look at the code for the content plugin, and can see onBeforeCreatePDFContent and onBeforeDisplayPDFContent and think I can adapt these to pull data from my component.
The issue is, if I create a new plugin how do I get PhocaPDF to know to use it if i add ?tmpl=component&format=pdf to the URL. If I have index.php?option=com_sea&view=messages&layout=report&tmpl=component&format=pdf (com_sea is my custom component)

If i try that link now I get 'Error. Failed to load PDF document.' Not sure if it means it cant find a plugin for that component or whether its trying to use the content plugin and can't get a valid content item.

Thanks for your help. What would be really great is if I could get a 'hello world' type plugin that a could associate with my component that would just spit out a pdf document with static content, and then I could recode it to pull in the dynamic data.

Many thanks

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

Re: PDF Plugin for custom component

Post by Jan » 30 Apr 2020, 18:02

Hi, first, your component needs to have the pdf view, see examples e.g. in Phoca Cart:

Image which should just echo the output

The PDF view just calls the PDF document in Joomla! (which was added by Phoca Cart) and this document then use the plugin to render the page.

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

netamity
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 30 Apr 2020, 13:17

Re: PDF Plugin for custom component

Post by netamity » 05 May 2020, 11:48

I have added a view.pdf.php file to the correct folder. I used the one in com_content as an example and now have:
defined('_JEXEC') or die;
jimport('joomla.application.component.view');

class SeaCkViewMessages extends JViewLegacy
{


function display($tpl = null)
{
$app = JFactory::getApplication();
$user = JFactory::getUser();

//die('works');
$document = JFactory::getDocument();
$document->setHeader('header');

echo 'lots of text here';
$document->setArticleText('lots of text here');
$document->setArticleTitle('test');

}
}
I'm still getting the same 'Error- Failed to load PDF document.' as I did before. Do I need to create a plugin for my component as well? If so, how is this done?
Thanks for your help.

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

Re: PDF Plugin for custom component

Post by Jan » 05 May 2020, 13:17

Hi, yes, each component needs own plugin. Just see e.g. as example the Phoca PDF Phoca Cart Plugin:
https://www.phoca.cz/download/category/ ... art-plugin

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

Post Reply