forked from Fabrik/fabrik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ec9766
commit ce89fc1
Showing
1 changed file
with
258 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
<?php | ||
/** | ||
* Joomla! Content Management System | ||
* | ||
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
namespace Joomla\CMS\Document; | ||
|
||
defined('JPATH_PLATFORM') or die; | ||
|
||
//require_once JPATH_SITE . '/components/com_fabrik/helpers/pdf.php'; | ||
|
||
use Fabrik\Helpers\Pdf; | ||
|
||
jimport('joomla.utilities.utility'); | ||
|
||
/** | ||
* PdfDocument class, provides an easy interface to parse and display a PDF document | ||
* | ||
* @since 11.1 | ||
*/ | ||
class PdfDocument extends Document | ||
{ | ||
/** | ||
* Array of Header `<link>` tags | ||
* | ||
* @var array | ||
* @since 11.1 | ||
*/ | ||
public $_links = array(); | ||
|
||
/** | ||
* Array of custom tags | ||
* | ||
* @var array | ||
* @since 11.1 | ||
*/ | ||
public $_custom = array(); | ||
|
||
/** | ||
* Name of the template | ||
* | ||
* @var string | ||
* @since 11.1 | ||
*/ | ||
public $template = null; | ||
|
||
/** | ||
* Base url | ||
* | ||
* @var string | ||
* @since 11.1 | ||
*/ | ||
public $baseurl = null; | ||
|
||
/** | ||
* Array of template parameters | ||
* | ||
* @var array | ||
* @since 11.1 | ||
*/ | ||
public $params = null; | ||
|
||
/** | ||
* File name | ||
* | ||
* @var array | ||
* @since 11.1 | ||
*/ | ||
public $_file = null; | ||
|
||
/** | ||
* String holding parsed template | ||
* | ||
* @var string | ||
* @since 11.1 | ||
*/ | ||
protected $_template = ''; | ||
|
||
/** | ||
* Array of parsed template JDoc tags | ||
* | ||
* @var array | ||
* @since 11.1 | ||
*/ | ||
protected $_template_tags = array(); | ||
|
||
/** | ||
* Integer with caching setting | ||
* | ||
* @var integer | ||
* @since 11.1 | ||
*/ | ||
protected $_caching = null; | ||
|
||
/** | ||
* Set to true when the document should be output as HTML5 | ||
* | ||
* @var boolean | ||
* @since 12.1 | ||
* | ||
* @note 4.0 Will be replaced by $html5 and the default value will be true. | ||
*/ | ||
private $_html5 = null; | ||
|
||
/** | ||
* Class constructor | ||
* | ||
* @param array $options Associative array of options | ||
* | ||
* @since 11.1 | ||
*/ | ||
public function __construct($options = array()) | ||
{ | ||
parent::__construct($options); | ||
|
||
$config = \JComponentHelper::getParams('com_fabrik'); | ||
if ($config->get('pdf_debug', false)) | ||
{ | ||
$this->setMimeEncoding('text/html'); | ||
$this->_type = 'pdf'; | ||
} | ||
else | ||
{ | ||
// Set mime type | ||
$this->_mime = 'application/pdf'; | ||
|
||
// Set document type | ||
$this->_type = 'pdf'; | ||
} | ||
if (!$this->iniDomPdf()) | ||
{ | ||
throw new RuntimeException(FText::_('COM_FABRIK_NOTICE_DOMPDF_NOT_FOUND')); | ||
} | ||
} | ||
|
||
/** | ||
* Set up DomPDF engine | ||
* | ||
* @return bool | ||
*/ | ||
protected function iniDomPdf() | ||
{ | ||
$this->engine = Pdf::iniDomPdf(true); | ||
|
||
return $this->engine; | ||
} | ||
|
||
/** | ||
* Set the paper size and orientation | ||
* Note if too small for content then the pdf renderer will bomb out in an infinite loop | ||
* Legal seems to be more lenient than a4 for example | ||
* If doing landscape set large paper size | ||
* | ||
* @param string $size Paper size E.g A4,legal | ||
* @param string $orientation Paper orientation landscape|portrait | ||
* | ||
* @since 3.0.7 | ||
* | ||
* @return void | ||
*/ | ||
public function setPaper($size = 'A4', $orientation = 'landscape') | ||
{ | ||
$size = strtoupper($size); | ||
$this->engine->set_paper($size, $orientation); | ||
} | ||
|
||
/** | ||
* Sets the document name | ||
* | ||
* @param string $name Document name | ||
* | ||
* @return void | ||
*/ | ||
public function setName($name = 'joomla') | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
* Returns the document name | ||
* | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* Render the document. | ||
* | ||
* @param boolean $cache If true, cache the output | ||
* @param array $params Associative array of attributes | ||
* | ||
* @return string | ||
*/ | ||
public function render($cache = false, $params = array()) | ||
{ | ||
// mb_encoding foo when content-type had been set to text/html; uft-8; | ||
$this->_metaTags['http-equiv'] = array(); | ||
$this->_metaTags['http-equiv']['content-type'] = 'text/html'; | ||
|
||
// Testing using futural font. | ||
// $this->addStyleDeclaration('body: { font-family: futural !important; }'); | ||
$pdf = $this->engine; | ||
parent::render(); | ||
$data = $this->getBuffer(); | ||
|
||
Pdf::fullPaths($data); | ||
|
||
/** | ||
* I think we need this to handle some HTML entities when rendering otherlanguages (like Polish), | ||
* but haven't tested it much | ||
*/ | ||
$data = mb_convert_encoding($data,'HTML-ENTITIES','UTF-8'); | ||
|
||
$pdf->load_html($data); | ||
$config = \JComponentHelper::getParams('com_fabrik'); | ||
|
||
if ($config->get('pdf_debug', false)) | ||
{ | ||
return $pdf->output_html(); | ||
} | ||
else | ||
{ | ||
$pdf->render(); | ||
$pdf->stream($this->getName() . '.pdf'); | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
/** | ||
* Get the contents of a document include | ||
* | ||
* @param string $type The type of renderer | ||
* @param string $name The name of the element to render | ||
* @param array $attribs Associative array of remaining attributes. | ||
* | ||
* @return The output of the renderer | ||
*/ | ||
/* | ||
public function getBuffer($type = null, $name = null, $attribs = array()) | ||
{ | ||
if ($type == 'head' || $type == 'component') | ||
{ | ||
return parent::getBuffer($type, $name, $attribs); | ||
} | ||
else | ||
{ | ||
return ''; | ||
} | ||
} | ||
*/ | ||
} |