web/lib/Zend/Pdf.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    12  * obtain it through the world-wide-web, please send an email
    12  * obtain it through the world-wide-web, please send an email
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Pdf
    16  * @package    Zend_Pdf
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @version    $Id: Pdf.php 22908 2010-08-25 20:52:47Z alexander $
    19  * @version    $Id: Pdf.php 24593 2012-01-05 20:35:02Z matthew $
    20  */
    20  */
    21 
    21 
    22 
    22 
    23 /** User land classes and interfaces turned on by Zend/Pdf.php file inclusion. */
    23 /** User land classes and interfaces turned on by Zend/Pdf.php file inclusion. */
    24 /** @todo Section should be removed with ZF 2.0 release as obsolete            */
    24 /** @todo Section should be removed with ZF 2.0 release as obsolete            */
    76  * Class agregates document level properties and entities (pages, bookmarks,
    76  * Class agregates document level properties and entities (pages, bookmarks,
    77  * document level actions, attachments, form object, etc)
    77  * document level actions, attachments, form object, etc)
    78  *
    78  *
    79  * @category   Zend
    79  * @category   Zend
    80  * @package    Zend_Pdf
    80  * @package    Zend_Pdf
    81  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    81  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    82  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    82  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    83  */
    83  */
    84 class Zend_Pdf
    84 class Zend_Pdf
    85 {
    85 {
    86   /**** Class Constants ****/
    86   /**** Class Constants ****/
   208      * @var array
   208      * @var array
   209      */
   209      */
   210     protected static $_inheritableAttributes = array('Resources', 'MediaBox', 'CropBox', 'Rotate');
   210     protected static $_inheritableAttributes = array('Resources', 'MediaBox', 'CropBox', 'Rotate');
   211 
   211 
   212     /**
   212     /**
       
   213      * True if the object is a newly created PDF document (affects save() method behavior)
       
   214      * False otherwise
       
   215      *
       
   216      * @var boolean
       
   217      */
       
   218     protected $_isNewDocument = true;
       
   219 
       
   220     /**
   213      * Request used memory manager
   221      * Request used memory manager
   214      *
   222      *
   215      * @return Zend_Memory_Manager
   223      * @return Zend_Memory_Manager
   216      */
   224      */
   217     static public function getMemoryManager()
   225     static public function getMemoryManager()
   260     }
   268     }
   261 
   269 
   262     /**
   270     /**
   263      * Render PDF document and save it.
   271      * Render PDF document and save it.
   264      *
   272      *
   265      * If $updateOnly is true, then it only appends new section to the end of file.
   273      * If $updateOnly is true and it's not a new document, then it only
       
   274      * appends new section to the end of file.
   266      *
   275      *
   267      * @param string $filename
   276      * @param string $filename
   268      * @param boolean $updateOnly
   277      * @param boolean $updateOnly
   269      * @throws Zend_Pdf_Exception
   278      * @throws Zend_Pdf_Exception
   270      */
   279      */
   346                     }
   355                     }
   347                 }
   356                 }
   348 
   357 
   349                 $this->_originalProperties = $this->properties;
   358                 $this->_originalProperties = $this->properties;
   350             }
   359             }
       
   360 
       
   361             $this->_isNewDocument = false;
   351         } else {
   362         } else {
   352             $this->_pdfHeaderVersion = Zend_Pdf::PDF_VERSION;
   363             $this->_pdfHeaderVersion = Zend_Pdf::PDF_VERSION;
   353 
   364 
   354             $trailerDictionary = new Zend_Pdf_Element_Dictionary();
   365             $trailerDictionary = new Zend_Pdf_Element_Dictionary();
   355 
   366 
  1172         return null;
  1183         return null;
  1173     }
  1184     }
  1174 
  1185 
  1175     /**
  1186     /**
  1176      * Render the completed PDF to a string.
  1187      * Render the completed PDF to a string.
  1177      * If $newSegmentOnly is true, then only appended part of PDF is returned.
  1188      * If $newSegmentOnly is true and it's not a new document,
       
  1189      * then only appended part of PDF is returned.
  1178      *
  1190      *
  1179      * @param boolean $newSegmentOnly
  1191      * @param boolean $newSegmentOnly
  1180      * @param resource $outputStream
  1192      * @param resource $outputStream
  1181      * @return string
  1193      * @return string
  1182      * @throws Zend_Pdf_Exception
  1194      * @throws Zend_Pdf_Exception
  1183      */
  1195      */
  1184     public function render($newSegmentOnly = false, $outputStream = null)
  1196     public function render($newSegmentOnly = false, $outputStream = null)
  1185     {
  1197     {
       
  1198         if ($this->_isNewDocument) {
       
  1199             // Drop full document first time even $newSegmentOnly is set to true
       
  1200             $newSegmentOnly = false;
       
  1201             $this->_isNewDocument = false;
       
  1202         }
       
  1203 
  1186         // Save document properties if necessary
  1204         // Save document properties if necessary
  1187         if ($this->properties != $this->_originalProperties) {
  1205         if ($this->properties != $this->_originalProperties) {
  1188             $docInfo = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
  1206             $docInfo = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
  1189 
  1207 
  1190             foreach ($this->properties as $key => $value) {
  1208             foreach ($this->properties as $key => $value) {