Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/document/pdf/pdf.php

Documentation is available at pdf.php

  1. <?php
  2. /**
  3. @version        $Id: pdf.php 6677 2007-02-19 07:18:06Z louis $
  4. @package        Joomla.Framework
  5. @subpackage    Document
  6. @copyright    Copyright (C) 2005 - 2007 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.  * @author        Johan Janssens <[email protected]>
  22.  * @package        Joomla.Framework
  23.  * @subpackage    Document
  24.  * @since        1.5
  25.  */
  26.  
  27. class JDocumentPDF extends JDocument
  28. {
  29.     var $_engine    = null;
  30.     var $_name        = 'joomla';
  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.         /*
  88.          * Setup external configuration options
  89.          */
  90.         define('K_TCPDF_EXTERNAL_CONFIG'true);
  91.  
  92.         /*
  93.          * Path options
  94.          */
  95.  
  96.         // Installation path
  97.         define("K_PATH_MAIN"JPATH_LIBRARIES.DS."tcpdf");
  98.  
  99.         // URL path
  100.         define("K_PATH_URL"JPATH_BASE);
  101.  
  102.         // Fonts path
  103.         define("FPDF_FONTPATH"K_PATH_MAIN.DS."fonts".DS);
  104.  
  105.         // Cache directory path
  106.         define("K_PATH_CACHE"K_PATH_MAIN.DS."cache");
  107.  
  108.         // Cache URL path
  109.         define("K_PATH_URL_CACHE"K_PATH_URL.DS."cache");
  110.  
  111.         // Images path
  112.         define("K_PATH_IMAGES"K_PATH_MAIN.DS."images");
  113.  
  114.         // Blank image path
  115.         define("K_BLANK_IMAGE"K_PATH_IMAGES.DS."_blank.png");
  116.  
  117.         /*
  118.          * Format options
  119.          */
  120.  
  121.         // Cell height ratio
  122.         define("K_CELL_HEIGHT_RATIO"1.25);
  123.  
  124.         // Magnification scale for titles
  125.         define("K_TITLE_MAGNIFICATION"1.3);
  126.  
  127.         // Reduction scale for small font
  128.         define("K_SMALL_RATIO"2/3);
  129.  
  130.         // Magnication scale for head
  131.         define("HEAD_MAGNIFICATION"1.1);
  132.  
  133.         /*
  134.          * Create the pdf document
  135.          */
  136.  
  137.         jimport('tcpdf.tcpdf');
  138.  
  139.         // Default settings are a portrait layout with an A4 configuration using millimeters as units
  140.         $this->_engine = new TCPDF("P""mm""A4"true);
  141.  
  142.         //set margins
  143.         $this->_engine->SetMargins($this->_margin_left$this->_margin_top$this->_margin_right);
  144.         //set auto page breaks
  145.         $this->_engine->SetAutoPageBreak(TRUE$this->_margin_bottom);
  146.         $this->_engine->SetHeaderMargin($this->_margin_header);
  147.         $this->_engine->SetFooterMargin($this->_margin_footer);
  148.         $this->_engine->setImageScale($this->_image_scale);
  149.  
  150.         /*
  151.          * FONTS
  152.          */
  153.  
  154.         // Default font name
  155.         define("PDF_FONT_NAME_MAIN"'vera');
  156.         // Default font size
  157.         define("PDF_FONT_SIZE_MAIN"10);
  158.         // Data font name
  159.         define("PDF_FONT_NAME_DATA"'vera');
  160.         // Data font size
  161.         define("PDF_FONT_SIZE_DATA"8);
  162.     }
  163.  
  164.     function getEngine()
  165.     {
  166.         return $this->_engine;
  167.     }
  168.  
  169.      /**
  170.      * Sets the document name
  171.      *
  172.      * @param   string   $name    Document name
  173.      * @access  public
  174.      * @return  void 
  175.      */
  176.     function setName($name 'joomla')
  177.     {
  178.         $this->_name = $name;
  179.     }
  180.  
  181.     /**
  182.      * Returns the document name
  183.      *
  184.      * @access public
  185.      * @return string 
  186.      */
  187.     function getName()
  188.     {
  189.         return $this->_name;
  190.     }
  191.  
  192.      /**
  193.      * Sets the document header string
  194.      *
  195.      * @param   string   $text    Document header string
  196.      * @access  public
  197.      * @return  void 
  198.      */
  199.     function setHeader($text)
  200.     {
  201.         $this->_header = $text;
  202.     }
  203.  
  204.     /**
  205.      * Returns the document header string
  206.      *
  207.      * @access public
  208.      * @return string 
  209.      */
  210.     function getHeader()
  211.     {
  212.         return $this->_header;
  213.     }
  214.  
  215.     /**
  216.      * Get the contents of the document buffer
  217.      *
  218.      * @access public
  219.      * @return     The contents of the document buffer
  220.      */
  221.     function getData({
  222.         return $this->_data;
  223.     }
  224.  
  225.     /**
  226.      * Set the contents of the document buffer
  227.      *
  228.      * @access public
  229.      * @param string     $content    The content to be set in the buffer
  230.      */
  231.     function setData($content{
  232.         $this->_data $content;
  233.     }
  234.  
  235.     /**
  236.      * Set the contents of the document buffer
  237.      *
  238.      * @access public
  239.      * @param string     $content    The content to be set in the buffer
  240.      */
  241.     function appendData($content{
  242.         $this->_data .= $content;
  243.     }
  244.  
  245.     /**
  246.      * Render the document.
  247.      *
  248.      * @access public
  249.      * @param boolean     $cache        If true, cache the output
  250.      * @param array        $params        Associative array of attributes
  251.      * @return     The rendered data
  252.      */
  253.     function render$cache false$params array())
  254.     {
  255.         $pdf &$this->_engine;
  256.  
  257.         // Set PDF Metadata
  258.         $pdf->SetCreator($this->getGenerator());
  259.         $pdf->SetTitle($this->getTitle());
  260.         $pdf->header_title $this->getTitle();
  261.         $pdf->SetSubject($this->getDescription());
  262.         $pdf->SetKeywords($this->getMetaData('keywords'));
  263.  
  264.         // Set PDF Header data
  265.         $pdf->setHeaderData('',0,$this->getTitle()$this->getHeader());
  266.  
  267.         // Set PDF Header and Footer fonts
  268.         $pdf->setHeaderFont(array('vera'''10));
  269.         $pdf->setFooterFont(array('vera'''8));
  270.  
  271.         // Initialize PDF Document
  272.         $pdf->AliasNbPages();
  273.         $pdf->AddPage();
  274.  
  275.         // Build the PDF Document string from the document buffer
  276.         $pdf->WriteHTML($this->getData()true);
  277.         $data $pdf->Output('''S');
  278.  
  279.         // Set document type headers
  280.         parent::render();
  281.         //JResponse::setHeader('Content-Length', strlen($data), true);
  282.         JResponse::setHeader('Content-disposition''inline; filename="'.$this->getName().'.pdf"'true);
  283.  
  284.         //Close and output PDF document
  285.         return $data;
  286.     }
  287. }
  288. ?>

Documentation generated on Mon, 05 Mar 2007 21:16:31 +0000 by phpDocumentor 1.3.1