Re: Joomla 3.8 - call to undefined method while generating a pdf
Posted: 29 Sep 2017, 09:31
I would also be greatful, if you could share the modified files - thanks
Support for Phoca Extensions
https://phoca.cz./forum/
Code: Select all
<?php
namespace Joomla\CMS\Document;
defined('JPATH_PLATFORM') or die;
use Joomla\Filesystem\File;
use Joomla\CMS\Factory;
class PdfDocument extends Document
{
// Document
public $_generator = 'Phoca PDF';
public $_charset = 'utf-8';
public $_mime = 'application/pdf';
public $_type = 'pdf';
// PDF (Html)
public $_links = array();
public $_custom = array();
protected $_caching = null;
// PDF
public $_header = null;
public $_name = 'Phoca';
public $_article_title = '';
public $_article_text = '';
public function __construct($options = array()) {
parent::__construct($options);
$this->_type = 'pdf';
$this->_mime = 'application/pdf';
$this->_caching = null;
$app = \JFactory::getApplication();
}
function setHeader($text) {
$this->_header = $text;
}
function getHeader() {
return $this->_header;
}
function setName($name = 'Phoca') {
$this->_name = $name;
}
function getName() {
return $this->_name;
}
function setArticleText($text) {
$this->_article_text = $text;
}
function getArticleText() {
return $this->_article_text;
}
function setArticleTitle($text) {
$this->_article_title = $text;
}
function getArticleTitle() {
return $this->_article_title;
}
function render( $caching = false, $params = array()) {
$app = \JFactory::getApplication();
//$this->_caching = $caching;
//Call static function because of using on different places by different extensions
if (\JFile::exists(JPATH_ADMINISTRATOR.'/components/com_phocapdf/helpers/phocapdfrender.php')) {
require_once(JPATH_ADMINISTRATOR.'/components/com_phocapdf/helpers/phocapdfrender.php');
} else {
return JError::raiseError('PDF ERROR', 'Document cannot be created - Loading of Phoca PDF library (Render) failed');
}
parent::render();
$data = \PhocaPdfRender::renderPDF($this);
return $data;
}
function addCustomTag() {
return true;
}
public function getHeadData() {
$data = array();
$data['title'] = $this->title;
$data['description']= $this->description;
$data['link'] = $this->link;
$data['metaTags'] = $this->_metaTags;
$data['links'] = $this->_links;
$data['styleSheets']= $this->_styleSheets;
$data['style'] = $this->_style;
$data['scripts'] = $this->_scripts;
$data['script'] = $this->_script;
$data['custom'] = $this->_custom;
return $data;
}
public function setHeadData($data)
{
if (empty($data) || !is_array($data)) {
return;
}
$this->title = (isset($data['title']) && !empty($data['title'])) ? $data['title'] : $this->title;
$this->description = (isset($data['description']) && !empty($data['description'])) ? $data['description'] : $this->description;
$this->link = (isset($data['link']) && !empty($data['link'])) ? $data['link'] : $this->link;
$this->_metaTags = (isset($data['metaTags']) && !empty($data['metaTags'])) ? $data['metaTags'] : $this->_metaTags;
$this->_links = array();//(isset($data['links']) && !empty($data['links'])) ? $data['links'] : $this->_links;
$this->_styleSheets = array();//(isset($data['styleSheets']) && !empty($data['styleSheets'])) ? $data['styleSheets'] : $this->_styleSheets;
$this->_style = array();//(isset($data['style']) && !empty($data['style'])) ? $data['style'] : $this->_style;
$this->_scripts = array();//(isset($data['scripts']) && !empty($data['scripts'])) ? $data['scripts'] : $this->_scripts;
$this->_script = array();//(isset($data['script']) && !empty($data['script'])) ? $data['script'] : $this->_script;
$this->_custom = array();//(isset($data['custom']) && !empty($data['custom'])) ? $data['custom'] : $this->_custom;
}
}
Code: Select all
default:
$dispatcher = JDispatcher::getInstance();
if (JPluginhelper::isEnabled('phocapdf',strtolower($t))){
JPluginHelper::importPlugin( 'phocapdf' );
$results = $dispatcher->trigger('onBeforeCreatePDF'.$t, array(&$content));
require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_phocapdf'.DS.'helpers'.DS.'phocapdfcontenttcpdf.php');
$pdf = new PhocaPDFContentTCPDF($content->page_orientation, 'mm', $content->page_format, true, 'UTF-8', $content->use_cache);
$results = $dispatcher->trigger('onBeforeDisplayPDF'.$t, array (&$pdf, &$content, &$document));
} else {
return JError::raiseError('PDF ERROR', 'Phoca PDF - '.$t.' plugin is disabled or not installed');
}
break;
Jan\JFactory::getApplication()->setHeader('Content-type', 'application/pdf', true);// Because of cache
\JFactory::getApplication()->setHeader('Content-disposition', 'inline; filename="'.$this->getName().'.pdf"', true);