Joomla-pdf-document-view

Joomla 2.5 universal pdf render(dompdf, mpdf, tcpdf, wkhtmltopdf)


Project maintained by studio42 Hosted on GitHub Pages — Theme by mattgraham

DOWNLOAD IT - Return to home Page

Display your PDF

You can display directly your pdf an adding &format=pdf to the link.(or ?format=pdf in case of a full sef URL), no need to create a specific view, with the quality of some render you get a nice PDF without changing your original page

Save PDF document to file

To save your pdf in your remote server, you have to change only one line in your component.

$document->setDestination('F') ;

if you have to change the directory or name, provide a full path link

`$document->setPath( JPATH_ROOT.'/media/mydocument.pdf/') ;

but you can write outside the JPATHROOT using a full valid path

$document->setPath('D:\pdfs\mydocument.pdf')

is valid in window

$document->setPath('/home/myfolder/mydocument.pdf'

is valid in linux if you have the right to write on this folders of course.

Add PDF link button in a template

One of easiest way , is of course hard coding the link in the view.
but a nicer way is provided by the Joomla 2.5 CMS :

extending JHtml

Here a little code, to add in your template.
File : /templates/MYTEMPLATE/helpers/pdf.php

class JHtmlPdf
{
  static function article($article, $params, $attribs = array())
	{
		$url  = ContentHelperRoute::getArticleRoute($article->slug, $article->catid);
		$url .= '&tmpl=component&print=1&format=pdf&layout=default&page='.@ $request->limitstart;

		$status = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no';

		// checks template image directory for image, if non found default are loaded
		if ($params->get('show_icons')) {
			$text = JHtml::_('image', 'system/pdf_button.png', JText::_('JGLOBAL_PRINT'), NULL, true);
		} else {
			$text = JText::_('JGLOBAL_ICON_SEP') .' '. JText::_('JGLOBAL_PRINT') .' '. JText::_('JGLOBAL_ICON_SEP');
		}

		$attribs['title']	= JText::_('JGLOBAL_PRINT');
		$attribs['onclick'] = "window.open(this.href,'win2','".$status."'); return false;";
		$attribs['rel']		= 'nofollow';

		return JHtml::_('link', JRoute::_($url), $text, $attribs);
	}
}
and how to add it in your view


 // icones overide or why not only PDF icon in your case
 /* CODE TO ADD */
 JHTML::addIncludePath(JPATH_SITE . '/templates/MYTEMPLATE/helpers');
 /* LINE TO ADD END */
 // This code is original icons (but can be add in your own helper)
 JHtml::addIncludePath(JPATH_COMPONENT . '/helpers');
search

 echo JHtml::_('icon.print_popup',  $this->item, $params);
and replace with

 echo JHtml::_('pdf.article',  $this->item, $params);

A little explain,
JHTML pdf.article say to call class JHtmlPdf and the function article. and because we added the path to the helepr folder. Joomla know where the class is.

Of course whe have to add the class in the /templates/MYTEMPLATE/helpers and the file must be named pdf.php in case of using JHtml::_('pdf.XXX .
It's the naming convention of joomla JHTML

Another advantage is in case of the image 'system/pdf_button.png' exist in the media/system folder but not in MYTEMPLATE/images/system, then joomla display this from joomla system folder