How to have the plugins processed when generating PDF documents of content items (for Joomla 1.5.x)?
Written by kksou   
Sunday, 15 June 2008

In a standard Joomla 1.5 installation, you can generate a PDF version of a content item by clicking on the pdf icon appearing in the top right corner of the content item page.

However, if you have installed some plugins such as the Include Content Item or the googleAds plugins, you will find that the plugin do not get processed during the generation of the PDF documents. As as result, you will see the plugin tags such as {googleAds} or {include_content_item}, appearing in the PDF documents! This is, of course, undesirable.

This article shows you how to have the plugins processed during the generation of the PDF documents for content items.

Note: the steps below are for Joomla 1.5.x. If you're using Joomla 1.0.x, please refer to How to have DirectPHP plugin process RSS feed (for Joomla 1.0.x)?.


Explanation

In the original Joomla installation, there is no trigger during the generation of PDF documents. When there is no trigger, none of the plugin gets called. In order for the plugins to be processed, we need to add a trigger.

Solutions (for Joomla 1.5.10 and above)

Very Important: this is for Joomla 1.5.10 and above. Thanks to Markstein who informed me about the change in Joomla code.

All you need is to add 2 lines to have plugins processed during the generation of PDF documents!

  1. Go to the folder <Joomla root folder>/components/com_content/views/article, you will see a file called view.pdf.php.
  2. Open this file view.pdf.php in your favorite editor.
  3. Go to around line 71, and add the 2 lines highlighted in yellow as shown below:
  4. // process the new plugins
    JPluginHelper::importPlugin('content', 'image');
    $dispatcher->trigger('onPrepareContent', array (& $article, & $params, 0));
    
    JPluginHelper::importPlugin('content');
    $results = $dispatcher->trigger('onPrepareContent', array (& $article, & $params, 0));
    
    $document = &JFactory::getDocument();
    
    // set document information
    $document->setTitle($article->title);
    $document->setName($article->alias);
    $document->setDescription($article->metadesc);
    $document->setMetaData('keywords', $article->metakey);
    

  5. Save and close this file.

That's it! Now try generating the PDF documents. You should find all the plugin tags disappear in the PDF documents as they get processed by the respective plugins.

Solutions (for Joomla 1.5.9 and before)

Very Important: this is for Joomla 1.5.9 and before.

All you need is to add 2 lines to have plugins processed during the generation of PDF documents!

  1. Go to the folder <Joomla root folder>/components/com_content/views/article, you will see a file called view.pdf.php.
  2. Open this file view.pdf.php in your favorite editor.
  3. Go to around line 42, and add the 2 lines highlighted in yellow as shown below:
  4. // Initialize some variables
    $article	= & $this->get( 'Article' );
    $params 	= & $article->parameters;
    
    // process the new plugins
    JPluginHelper::importPlugin('content', 'image');
    $dispatcher->trigger('onPrepareContent', array (& $article, & $params, 0));
    
    JPluginHelper::importPlugin('content');
    $results = $dispatcher->trigger('onPrepareContent', array (& $article, & $params, 0));
    
    $document = &JFactory::getDocument();
    
    // set document information
    $document->setTitle($article->title);
    $document->setName($article->alias);
    $document->setDescription($article->metadesc);
    $document->setMetaData('keywords', $article->metakey);
    

  5. Save and close this file.

That's it! Now try generating the PDF documents. You should find all the plugin tags disappear in the PDF documents as they get processed by the respective plugins.


 
< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2012. kksou.com. All Rights Reserved