A beginning of solution to display fields in pdf

More
14 years 3 months ago #3870 by vlester
Hello,

I found a way to display fields and extra fields in the pdf but it's far to be perfect : there are three problems I can't solve.

You'll find below the "view.pdf.php" file I modified (inspired a lot by the file view.html.php).
In this example, I used the default template and I have only the field "category" displayed. As you could see in the pdf file enclosed, it indeed displays the category but also the subcategory and that is cool.

I have also tried with another template with all the fields displayed (created by, revised by, hits...) and all these fields are in the pdf. And so is the Select-FlexiContent-Item plugin (I haven't yet tried with other plugins).

So here are the problems:
1/ The CSS.
The pdf file doesn't get the css of the tempate so you might have to change the positions of the fields in your template and may be the css of the file item.php (for example add some "padding-top", some "<br>", etc. )
The <ul> and <li> become dashes in the pdf. I removed them from the file item.php but there are still 3 dashes at the top of the pdf and I don't know how to remove them.
You also can change these variables in librairies/joomla/document/pdf.php
Code:
var $_margin_header = 10; var $_margin_top = 25;

To avoid the duplicate title, I also change this in the same file :
Code:
// Set PDF Header data $pdf->setHeaderData('',0,'Mon site - http://www.monsite.fr');

2/ The second and bigger problem is the path of the images. I have errors with almost all the images of the page. For example (I use JComments):
TCPDF ERROR: [Image] No such file or directory in www.monsite.fr/components/com_jc ... avatar.png
or
TCPDF ERROR: [Image] No such file or directory in www.monsite.fr/index.php?option= ... t&ac=97789

(This file "no_avatar.png" exists and the pathway is ok).
To limit errors, I duplicated in the repertory "tcpdf" the repertories "components/com_flexicontent/Images" and templates/the_name_of_my_template/images, I also duplicated the repertory "M_images". These dupplications solved the errors with all the images of these repertories (icons mostly). But the problem is for the new images such like users avatars and Kaptcha images. I can't find how to remove the errors with these files.
(What is weird is that the images in the description field don't cause error.)

3/ The last problem is again with JComments
All the comments are displayed in the pdf file and I'd rather not. And finally, there is in the footer this ugly code I can't remove :
Code:
var jcomments=new JComments(12671, 'com_flexicontent','http://localhost:8888/monsite/index.php?option=com_jcomments&tmpl=component'); jcomments.setList('comments-list'); jcomments.setAntiCache(1,0,0);




I hope I was clear (sorry for my english). But the best way is to try by yourself this view.pdf.file
Please let me know if you could solve some of these issues.
Thanks a lot



Find below the code to put in the file view.pdf.php (components/com_flexicontent/views/item)
Code:
<?php /** * @version 1.5 beta 5 $Id: view.html.php 183 2009-11-18 10:30:48Z vistamedia $ * @package Joomla * @subpackage FLEXIcontent * @copyright (C) 2009 Emmanuel Danan - www.vistamedia.fr * @license GNU/GPL v2 * * FLEXIcontent is a derivative work of the excellent QuickFAQ component * @copyright (C) 2008 Christoph Lukes * see www.schlu.net for more information * * FLEXIcontent is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ defined( '_JEXEC' ) or die( 'Restricted access' ); jimport( 'joomla.application.component.view'); /** * HTML View class for the Items View * * @package Joomla * @subpackage FLEXIcontent * @since 1.0 */ class FlexicontentViewItems extends JView { /** * Creates the item page * * @since 1.0 */ function display( $tpl = null ) { global $mainframe; //initialize variables $document = & JFactory::getDocument(); $user = & JFactory::getUser(); $menus = & JSite::getMenu(); $menu = $menus->getActive(); $dispatcher = & JDispatcher::getInstance(); $params = & $mainframe->getParams('com_flexicontent'); $aid = (int) $user->get('aid'); $limitstart = JRequest::getVar('limitstart', 0, '', 'int'); $cid = JRequest::getInt('cid', 0); if($this->getLayout() == 'form') { $this->_displayForm($tpl); return; } //Set layout $this->setLayout('item'); //get item data $item = & $this->get('Item'); $iparams =& $item->parameters; $params->merge($iparams); // Bind Fields $item = FlexicontentFields::getFields($item, 'items', $params); $item = $item[0]; // Note : This parameter doesn't exist yet but it will be used by the future gallery template if ($params->get('use_panes', 1)) { jimport('joomla.html.pane'); $pane = & JPane::getInstance('Tabs'); $this->assignRef('pane', $pane); } JHTML::_('behavior.tooltip'); if (($item->id == 0)) { if (!$aid) { // Redirect to login $uri = JFactory::getURI(); $return = $uri->toString(); $url = 'index.php?option=com_user&view=login'; $url .= '&return='.base64_encode($return);; $mainframe->redirect($url, JText::_('You must login first') ); } else { $id = JRequest::getInt('id', 0); return JError::raiseError( 404, JText::sprintf( 'ITEM #%d NOT FOUND', $id ) ); } } // Pathway need to be improved $cats = new flexicontent_cats($cid); $parents = $cats->getParentlist(); $depth = $params->get('item_depth', 0); /* * Handle the metadata * * Because the application sets a default page title, * we need to get it right from the menu item itself */ // Get the menu item object if (is_object($menu)) { $menu_params = new JParameter( $menu->params ); if (!$menu_params->get( 'page_title')) { $params->set('page_title', $item->title); } } else { $params->set('page_title', $item->title); } ?><div style="text-align:justify;font-family:times,arial;text-indent:0;"> <?php $document->setTitle($item->title); $document->setName($item->alias); $document->setDescription($item->metadesc); $document->setMetaData('keywords', $item->metakey); /* * Handle display events * No need for it currently */ $item->event = new stdClass(); $results = $dispatcher->trigger('onAfterDisplayTitle', array ($item, &$params, $limitstart)); $item->event->afterDisplayTitle = trim(implode("\n", $results)); $results = $dispatcher->trigger('onBeforeDisplayContent', array (& $item, & $params, $limitstart)); $item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onAfterDisplayContent', array (& $item, & $params, $limitstart)); $item->event->afterDisplayContent = trim(implode("\n", $results)); $print_link = JRoute::_('index.php?view=items&cid='.$item->categoryslug.'&id='.$item->slug.'&pop=1&tmpl=component'); $this->assignRef('item' , $item); $this->assignRef('user' , $user); $this->assignRef('params' , $params); $this->assignRef('iparams' , $iparams); $this->assignRef('menu_params' , $menu_params); $this->assignRef('print_link' , $print_link); $this->assignRef('parentcat', $parentcat); $this->assignRef('fields', $item->fields); $this->assignRef('tmpl' , $tmpl); ?><div style="text-align:justify;font-family:times,arial;text-indent:0;"> <?php /* * Set template paths : this procedure is issued from K2 component * * "K2" Component by JoomlaWorks for Joomla! 1.5.x - Version 2.1 * Copyright (c) 2006 - 2009 JoomlaWorks Ltd. All rights reserved. * Released under the GNU/GPL license: http://www.gnu.org/copyleft/gpl.html * More info at http://www.joomlaworks.gr and http://k2.joomlaworks.gr * Designed and developed by the JoomlaWorks team */ $this->addTemplatePath(JPATH_COMPONENT.DS.'templates'); $this->addTemplatePath(JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_flexicontent'.DS.'templates'); $this->addTemplatePath(JPATH_COMPONENT.DS.'templates'.DS.'default'); $this->addTemplatePath(JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_flexicontent'.DS.'templates'.DS.'default'); if ($params->get('ilayout')) { $this->addTemplatePath(JPATH_COMPONENT.DS.'templates'.DS.$params->get('ilayout')); $this->addTemplatePath(JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_flexicontent'.DS.'templates'.DS.$params->get('ilayout')); } parent::display($tpl); } /** * Creates the item submit form * * @since 1.0 */ function _displayForm($tpl) { global $mainframe; $mainframe->redirect('index.php'); //Initialize variables //Add the js includes to the document <head> section JHTML::_('behavior.formvalidation'); JHTML::_('behavior.tooltip'); // Unify the introtext and fulltext fields and separated the fields by the readmore tag if (JString::strlen($item->fulltext) > 1) { $item->text = $item->introtext."<hr id=\"system-readmore\" />".$item->fulltext; } else { $item->text = $item->introtext; } } } ?> </div>
Attachments:

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.251 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline