Sfoglia il codice sorgente

Zend_Pdf: improved Zend_Pdf::save() behavior. Closes [ZF-10820].

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23704 44c647ce-9c0f-0410-b52a-842ac1e357ba
alexander 15 anni fa
parent
commit
215fbba8e1
1 ha cambiato i file con 20 aggiunte e 2 eliminazioni
  1. 20 2
      library/Zend/Pdf.php

+ 20 - 2
library/Zend/Pdf.php

@@ -210,6 +210,14 @@ class Zend_Pdf
     protected static $_inheritableAttributes = array('Resources', 'MediaBox', 'CropBox', 'Rotate');
 
     /**
+     * True if the object is a newly created PDF document (affects save() method behavior)
+     * False otherwise
+     *
+     * @var boolean
+     */
+    protected $_isNewDocument = true;
+
+    /**
      * Request used memory manager
      *
      * @return Zend_Memory_Manager
@@ -262,7 +270,8 @@ class Zend_Pdf
     /**
      * Render PDF document and save it.
      *
-     * If $updateOnly is true, then it only appends new section to the end of file.
+     * If $updateOnly is true and it's not a new document, then it only
+     * appends new section to the end of file.
      *
      * @param string $filename
      * @param boolean $updateOnly
@@ -348,6 +357,8 @@ class Zend_Pdf
 
                 $this->_originalProperties = $this->properties;
             }
+
+            $this->_isNewDocument = false;
         } else {
             $this->_pdfHeaderVersion = Zend_Pdf::PDF_VERSION;
 
@@ -1174,7 +1185,8 @@ class Zend_Pdf
 
     /**
      * Render the completed PDF to a string.
-     * If $newSegmentOnly is true, then only appended part of PDF is returned.
+     * If $newSegmentOnly is true and it's not a new document,
+     * then only appended part of PDF is returned.
      *
      * @param boolean $newSegmentOnly
      * @param resource $outputStream
@@ -1183,6 +1195,12 @@ class Zend_Pdf
      */
     public function render($newSegmentOnly = false, $outputStream = null)
     {
+        if ($this->_isNewDocument) {
+            // Drop full document first time even $newSegmentOnly is set to true
+            $newSegmentOnly = false;
+            $this->_isNewDocument = false;
+        }
+
         // Save document properties if necessary
         if ($this->properties != $this->_originalProperties) {
             $docInfo = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());