| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: pdf.php 14401 2010-01-26 14:10:00Z louis $ 4 * @package Joomla.Framework 5 * @subpackage Document 6 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant 9 * to the GNU General Public License, and as distributed it includes or 10 * is derivative of works licensed under the GNU General Public License or 11 * other free or open source software licenses. 12 * See COPYRIGHT.php for copyright notices and details. 13 */ 14 15 // Check to ensure this file is within the rest of the framework 16 defined('JPATH_BASE') or die(); 17 18 /** 19 * DocumentPDF class, provides an easy interface to parse and display a pdf document 20 * 21 * @package Joomla.Framework 22 * @subpackage Document 23 * @since 1.5 24 */ 25 class JDocumentPDF extends JDocument 26 { 27 var $_engine = null; 28 29 var $_name = 'joomla'; 30 31 var $_header = null; 32 33 var $_margin_header = 5; 34 var $_margin_footer = 10; 35 var $_margin_top = 27; 36 var $_margin_bottom = 25; 37 var $_margin_left = 15; 38 var $_margin_right = 15; 39 40 // Scale ratio for images [number of points in user unit] 41 var $_image_scale = 4; 42 43 /** 44 * Class constructore 45 * 46 * @access protected 47 * @param array $options Associative array of options 48 */ 49 function __construct($options = array()) 50 { 51 parent::__construct($options); 52 53 if (isset($options['margin-header'])) { 54 $this->_margin_header = $options['margin-header']; 55 } 56 57 if (isset($options['margin-footer'])) { 58 $this->_margin_footer = $options['margin-footer']; 59 } 60 61 if (isset($options['margin-top'])) { 62 $this->_margin_top = $options['margin-top']; 63 } 64 65 if (isset($options['margin-bottom'])) { 66 $this->_margin_bottom = $options['margin-bottom']; 67 } 68 69 if (isset($options['margin-left'])) { 70 $this->_margin_left = $options['margin-left']; 71 } 72 73 if (isset($options['margin-right'])) { 74 $this->_margin_right = $options['margin-right']; 75 } 76 77 if (isset($options['image-scale'])) { 78 $this->_image_scale = $options['image-scale']; 79 } 80 81 //set mime type 82 $this->_mime = 'application/pdf'; 83 84 //set document type 85 $this->_type = 'pdf'; 86 /* 87 * Setup external configuration options 88 */ 89 define('K_TCPDF_EXTERNAL_CONFIG', true); 90 91 /* 92 * Path options 93 */ 94 95 // Installation path 96 define("K_PATH_MAIN", JPATH_LIBRARIES.DS."tcpdf"); 97 98 // URL path 99 define("K_PATH_URL", JPATH_BASE); 100 101 // Fonts path 102 define("K_PATH_FONTS", JPATH_SITE.DS.'language'.DS."pdf_fonts".DS); 103 104 // Cache directory path 105 define("K_PATH_CACHE", K_PATH_MAIN.DS."cache"); 106 107 // Cache URL path 108 define("K_PATH_URL_CACHE", K_PATH_URL.DS."cache"); 109 110 // Images path 111 define("K_PATH_IMAGES", K_PATH_MAIN.DS."images"); 112 113 // Blank image path 114 define("K_BLANK_IMAGE", K_PATH_IMAGES.DS."_blank.png"); 115 116 /* 117 * Format options 118 */ 119 120 // Cell height ratio 121 define("K_CELL_HEIGHT_RATIO", 1.25); 122 123 // Magnification scale for titles 124 define("K_TITLE_MAGNIFICATION", 1.3); 125 126 // Reduction scale for small font 127 define("K_SMALL_RATIO", 2/3); 128 129 // Magnication scale for head 130 define("HEAD_MAGNIFICATION", 1.1); 131 132 /* 133 * Create the pdf document 134 */ 135 136 jimport('tcpdf.tcpdf'); 137 138 // Default settings are a portrait layout with an A4 configuration using millimeters as units 139 $this->_engine = new TCPDF(); 140 141 //set margins 142 $this->_engine->SetMargins($this->_margin_left, $this->_margin_top, $this->_margin_right); 143 //set auto page breaks 144 $this->_engine->SetAutoPageBreak(TRUE, $this->_margin_bottom); 145 $this->_engine->SetHeaderMargin($this->_margin_header); 146 $this->_engine->SetFooterMargin($this->_margin_footer); 147 $this->_engine->setImageScale($this->_image_scale); 148 } 149 150 /** 151 * Sets the document name 152 * 153 * @param string $name Document name 154 * @access public 155 * @return void 156 */ 157 function setName($name = 'joomla') { 158 $this->_name = $name; 159 } 160 161 /** 162 * Returns the document name 163 * 164 * @access public 165 * @return string 166 */ 167 function getName() { 168 return $this->_name; 169 } 170 171 /** 172 * Sets the document header string 173 * 174 * @param string $text Document header string 175 * @access public 176 * @return void 177 */ 178 function setHeader($text) { 179 $this->_header = $text; 180 } 181 182 /** 183 * Returns the document header string 184 * 185 * @access public 186 * @return string 187 */ 188 function getHeader() { 189 return $this->_header; 190 } 191 192 /** 193 * Render the document. 194 * 195 * @access public 196 * @param boolean $cache If true, cache the output 197 * @param array $params Associative array of attributes 198 * @return The rendered data 199 */ 200 function render( $cache = false, $params = array()) 201 { 202 $pdf = &$this->_engine; 203 204 // Set PDF Metadata 205 $pdf->SetCreator($this->getGenerator()); 206 $pdf->SetTitle($this->getTitle()); 207 $pdf->SetSubject($this->getDescription()); 208 $pdf->SetKeywords($this->getMetaData('keywords')); 209 210 // Set PDF Header data 211 $pdf->setHeaderData('',0,$this->getTitle(), $this->getHeader()); 212 213 // Set PDF Header and Footer fonts 214 $lang = &JFactory::getLanguage(); 215 $font = $lang->getPdfFontName(); 216 $font = ($font) ? $font : 'freesans'; 217 218 $pdf->setRTL($lang->isRTL()); 219 220 $pdf->setHeaderFont(array($font, '', 10)); 221 $pdf->setFooterFont(array($font, '', 8)); 222 223 // Initialize PDF Document 224 $pdf->AliasNbPages(); 225 $pdf->AddPage(); 226 227 // Build the PDF Document string from the document buffer 228 $this->fixLinks(); 229 $pdf->WriteHTML($this->getBuffer(), true); 230 $data = $pdf->Output('', 'S'); 231 232 // Set document type headers 233 parent::render(); 234 235 //JResponse::setHeader('Content-Length', strlen($data), true); 236 237 JResponse::setHeader('Content-disposition', 'inline; filename="'.$this->getName().'.pdf"', true); 238 239 //Close and output PDF document 240 return $data; 241 } 242 243 function fixLinks() 244 { 245 246 } 247 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |