Joomla 3.8 - call to undefined method while generating a pdf

Phoca PDF - creating PDF documents in Joomla! CMS
alenah502
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 22 Sep 2017, 12:50

Re: Joomla 3.8 - call to undefined method while generating a pdf

Post by alenah502 » 29 Sep 2017, 09:31

I would also be greatful, if you could share the modified files - thanks

JanMisker
Phoca Newbie
Phoca Newbie
Posts: 3
Joined: 25 Sep 2017, 15:41

Re: Joomla 3.8 - call to undefined method while generating a pdf

Post by JanMisker » 05 Oct 2017, 00:00

Sorry, I am not on this forum often, but here are my changes:

2 files:
  • libraries/src/Document/PdfDocument.php, adapted from libraries/joomla/document/pdf/pdf.php
    administrator/components/com_phocapdf/helpers/phocapdfrender.php, for the fix for custom pdf plugins

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;	
	}
}
and in the phocapdfrender.php starting at line 154:

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;

alenah502
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 22 Sep 2017, 12:50

Re: Joomla 3.8 - call to undefined method while generating a pdf

Post by alenah502 » 05 Oct 2017, 09:43

Wow, that works - thanks a lot! Let me get you a coffee :)

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

Re: Joomla 3.8 - call to undefined method while generating a pdf

Post by Jan » 05 Oct 2017, 13:20

Hi, thank you for the info, I hope I will release the next version today.

In this code some obsolete methods were removed too:

- DS
- JDispatcher
- JError

In render function these methods are missing:
\JFactory::getApplication()->setHeader('Content-type', 'application/pdf', true);// Because of cache
\JFactory::getApplication()->setHeader('Content-disposition', 'inline; filename="'.$this->getName().'.pdf"', true);
Jan
If you find Phoca extensions useful, please support the project

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

Re: Joomla 3.8 - call to undefined method while generating a pdf

Post by Jan » 05 Oct 2017, 15:23

Hi, see:
Phoca PDF version 3.0.4 has been released (ready for Joomla! 3.8.1)
https://www.phoca.cz/news/953-phoca-pdf-3-0-4-released

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

nekoprophet
Phoca Newbie
Phoca Newbie
Posts: 1
Joined: 05 Jun 2019, 01:36

Re: Joomla 3.8 - call to undefined method while generating a pdf

Post by nekoprophet » 05 Jun 2019, 02:24

Do you think you can share your modified files ?

Post Reply