/**
  * Returns the instance, if the instance is not created by now, the instance
  * ic created.
  *
  * @return modxHelper The modxHelper object
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 require_once $basePath . $tcpdfPath . 'config/lang/eng.php';
 require_once $basePath . $tcpdfPath . 'tcpdf.php';
 require_once $basePath . $htmlToPdfPath . 'class.htmlToPDF.php';
 require_once $basePath . $htmlToPdfPath . 'class.modxHelper.php';
 // Get the footer properties before the creation of the PDF object, because
 // it is not possible to set them after the creation.
 $footerFontType = isset($footerFontType) ? $footerFontType : htmlToPDF::DEFAULT_FONT_TYPE;
 $footerFontItalic = isset($footerFontItalic) ? $footerFontItalic == 1 : true;
 $footerFontSize = isset($footerFontSize) && is_numeric($footerFontSize) ? $footerFontSize : htmlToPDF::DEFAULT_FOOTER_FONT_SIZE;
 $footerChunk = isset($footerChunk) ? $footerChunk : '';
 $footerPositionFromBottom = isset($footerPositionFromBottom) && is_numeric($footerPositionFromBottom) ? $footerPositionFromBottom : htmlToPDF::DEFAULT_FOOTER_POSITION_FROM_BOTTOM;
 $headerImageHeight = isset($headerImageHeight) && is_numeric($headerImageHeight) ? $headerImageHeight : 20;
 // Create new PDF document
 $pdf = new htmlToPDF($footerChunk, $footerFontType, $footerFontItalic, $footerFontSize, $footerPositionFromBottom, $headerImageHeight);
 // Create the MODX helper
 $modxHelper = modxHelper::getInstance();
 // Set document information
 $pdf->setPrintHeader(isset($printHeader) ? $printHeader == 1 : true);
 $pdf->setPrintFooter(isset($printFooter) ? $printFooter == 1 : true);
 $pdf->setLanguageArray(isset($languageCode) ? $languageCode : 'EN');
 $pdf->setDateFormat(isset($dateFormat) ? $dateFormat : 'Y-m-d');
 $marginLeft = isset($marginLeft) && is_numeric($marginLeft) ? $marginLeft : 10;
 $marginRight = isset($marginRight) && is_numeric($marginRight) ? $marginRight : 10;
 $marginTop = isset($marginTop) && is_numeric($marginTop) ? $marginTop : 30;
 $pdf->SetAutoPageBreak(TRUE, isset($marginBottom) && is_numeric($marginBottom) ? $marginBottom : 25);
 if (isset($printHeader) ? $printHeader == 1 : true) {
     $pdf->SetHeaderMargin(isset($marginHeader) && is_numeric($marginHeader) ? $marginHeader : 5);
     $pdf->setHeaderFontType(isset($headerFontType) ? $headerFontType : htmlToPDF::DEFAULT_FONT_TYPE);
     $pdf->setHeaderFontSize(isset($headerFontSize) && is_numeric($headerFontSize) ? $headerFontSize : htmlToPDF::DEFAULT_HEADER_FONT_SIZE);
     $pdf->setImageFile(isset($headerLogo) ? $basePath . $tcpdfPath : '', isset($headerLogo) ? $headerLogo : '');
     $pdf->setHeaderFontBold(isset($headerFontBold) ? $headerFontBold == 1 : true);
Exemplo n.º 3
0
 /**
  * When $sourceIsChunk is true, the variable $content should contain the name
  * of a chunk. The chunk should contain a template in HTML style with MODX
  * placeholders, snippets, and chunks. This works the same way, as a MODX
  * Document, because it makes use of the MODX function to parse a document.
  * Otherwise the content of the current document is used for the PDF content.
  * Links are translated into links with the complete URI, because they would
  * not work otherwise.
  *
  * @global object $modx
  * @param string $content Contains the document content or the a chunk, if
  *               $sourceIsChunk is true. Default is empty.
  * @param boolean $sourceIsChunk Whether the content is in a chunk and
  *                $content contains the chunk name, or not. Default is false.
  * @return string The content for the PDF document.
  */
 public function setContent($sourceIsChunk = false, $content = '')
 {
     global $modx;
     $result = '';
     $modxHelper = modxHelper::getInstance();
     if ($sourceIsChunk) {
         // Create the content with a chunk
         $chunk = $modx->getChunk($content);
         if ($this->getYamsId() != '') {
             $chunk = str_replace('(yams_id)', $this->getYamsId(), $chunk);
         }
         // Parse the content from the chunk with the MODX functions
         $result = $modx->parseDocumentSource($chunk);
         // Strip inline CSS
         if ($this->_stripCSSFromContent) {
             $result = $modxHelper->removeInlineCSS($result);
         }
         // The content footer is only available with standard parameters
         $this->_contentFooter = '';
     } else {
         // Create the content with standard content and parameters
         // Check, whether the long title should be above the content
         if ($this->_longTitleAboveContent) {
             if ($this->getYamsId() == '') {
                 $result = '<h1>' . $modx->documentObject['longtitle'] . "</h1>\n";
             } else {
                 $result = '<h1>' . $modx->documentObject['longtitle' . '_' . $this->getYamsId()] . "</h1>\n";
             }
         }
         // Get document content
         if ($this->getYamsId() == '') {
             $documentContent = $modx->documentObject['content'];
         } else {
             $documentContent = $modx->documentObject['content' . '_' . $this->getYamsId()];
             $documentContent = str_replace('(yams_id)', $this->getYamsId(), $documentContent);
         }
         // Check for calls to htmlToPDF in the content and remove the calls
         $start = strpos($documentContent, '[!htmlToPDF?');
         $end = strpos($documentContent, '!]', $start);
         $documentContent = str_replace(substr($documentContent, $start, $end - $start + 2), '', $documentContent);
         // Add the document content and parse the content for chunks, etc.
         $result .= $modx->parseDocumentSource($documentContent);
         // Strip inline CSS
         if ($this->_stripCSSFromContent) {
             $result = $modxHelper->removeInlineCSS($result);
         }
     }
     $result = $modxHelper->removeYAMSTags($result);
     // Parse the URLs and replace them to work from a PDF document,
     // add CSS style above the content
     // and add the content footer beneath the content
     $result = $this->getCSS() . $modxHelper->rewriteUrls($result) . $this->_contentFooter;
     // Set the content to the class variable
     $this->_content = $result;
     return $this->_content;
 }