当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Pdf_Element::phpToPdf方法代码示例

本文整理汇总了PHP中Zend_Pdf_Element::phpToPdf方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Pdf_Element::phpToPdf方法的具体用法?PHP Zend_Pdf_Element::phpToPdf怎么用?PHP Zend_Pdf_Element::phpToPdf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Pdf_Element的用法示例。


在下文中一共展示了Zend_Pdf_Element::phpToPdf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render

    /**
     * Render the completed PDF to a string.
     * 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
     * @return string
     * @throws Zend_Pdf_Exception
     */
    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());

            foreach ($this->properties as $key => $value) {
                switch ($key) {
                    case 'Trapped':
                        switch ($value) {
                            case true:
                                $docInfo->$key = new Zend_Pdf_Element_Name('True');
                                break;

                            case false:
                                $docInfo->$key = new Zend_Pdf_Element_Name('False');
                                break;

                            case null:
                                $docInfo->$key = new Zend_Pdf_Element_Name('Unknown');
                                break;

                            default:
                                require_once 'Zend/Pdf/Exception.php';
                                throw new Zend_Pdf_Exception('Wrong Trapped document property vale: \'' . $value . '\'. Only true, false and null values are allowed.');
                                break;
                        }

                    case 'CreationDate':
                        // break intentionally omitted
                    case 'ModDate':
                        $docInfo->$key = new Zend_Pdf_Element_String((string)$value);
                        break;

                    case 'Title':
                        // break intentionally omitted
                    case 'Author':
                        // break intentionally omitted
                    case 'Subject':
                        // break intentionally omitted
                    case 'Keywords':
                        // break intentionally omitted
                    case 'Creator':
                        // break intentionally omitted
                    case 'Producer':
                        if (extension_loaded('mbstring') === true) {
                            $detected = mb_detect_encoding($value);
                            if ($detected !== 'ASCII') {
                                $value = "\xfe\xff" . mb_convert_encoding($value, 'UTF-16', $detected);
                            }
                        }
                        $docInfo->$key = new Zend_Pdf_Element_String((string)$value);
                        break;

                    default:
                        // Set property using PDF type based on PHP type
                        $docInfo->$key = Zend_Pdf_Element::phpToPdf($value);
                        break;
                }
            }

            $this->_trailer->Info = $docInfo;
        }

        $this->_dumpPages();
        $this->_dumpNamedDestinations();
        $this->_dumpOutlines();

        // Check, that PDF file was modified
        // File is always modified by _dumpPages() now, but future implementations may eliminate this.
        if (!$this->_objFactory->isModified()) {
            if ($newSegmentOnly) {
                // Do nothing, return
                return '';
            }

            if ($outputStream === null) {
                return $this->_trailer->getPDFString();
            } else {
                $pdfData = $this->_trailer->getPDFString();
                while ( strlen($pdfData) > 0 && ($byteCount = fwrite($outputStream, $pdfData)) != false ) {
                    $pdfData = substr($pdfData, $byteCount);
                }

//.........这里部分代码省略.........
开发者ID:nhp,项目名称:shopware-4,代码行数:101,代码来源:Pdf.php

示例2: phpToPdf

 /**
  * Convert PHP value into PDF element.
  *
  * @param mixed $input
  * @return Zend_Pdf_Element
  */
 public static function phpToPdf($input)
 {
     if (is_numeric($input)) {
         //require_once 'Zend/Pdf/Element/Numeric.php';
         return new Zend_Pdf_Element_Numeric($input);
     } else {
         if (is_bool($input)) {
             //require_once 'Zend/Pdf/Element/Boolean.php';
             return new Zend_Pdf_Element_Boolean($input);
         } else {
             if (is_array($input)) {
                 $pdfElementsArray = array();
                 $isDictionary = false;
                 foreach ($input as $key => $value) {
                     if (is_string($key)) {
                         $isDictionary = true;
                     }
                     $pdfElementsArray[$key] = Zend_Pdf_Element::phpToPdf($value);
                 }
                 if ($isDictionary) {
                     //require_once 'Zend/Pdf/Element/Dictionary.php';
                     return new Zend_Pdf_Element_Dictionary($pdfElementsArray);
                 } else {
                     //require_once 'Zend/Pdf/Element/Array.php';
                     return new Zend_Pdf_Element_Array($pdfElementsArray);
                 }
             } else {
                 //require_once 'Zend/Pdf/Element/String.php';
                 return new Zend_Pdf_Element_String((string) $input);
             }
         }
     }
 }
开发者ID:chaimvaid,项目名称:linet3,代码行数:39,代码来源:Element.php

示例3: render

 public function render($newSegmentOnly = false, $outputStream = null)
 {
     if ($this->_isNewDocument) {
         $newSegmentOnly = false;
         $this->_isNewDocument = false;
     }
     if ($this->properties != $this->_originalProperties) {
         $docInfo = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
         foreach ($this->properties as $key => $value) {
             switch ($key) {
                 case 'Trapped':
                     switch ($value) {
                         case true:
                             $docInfo->{$key} = new Zend_Pdf_Element_Name('True');
                             break;
                         case false:
                             $docInfo->{$key} = new Zend_Pdf_Element_Name('False');
                             break;
                         case null:
                             $docInfo->{$key} = new Zend_Pdf_Element_Name('Unknown');
                             break;
                         default:
                             throw new Zend_Pdf_Exception('Wrong Trapped document property vale: \'' . $value . '\'. Only true, false and null values are allowed.');
                             break;
                     }
                 case 'CreationDate':
                 case 'ModDate':
                     $docInfo->{$key} = new Zend_Pdf_Element_String((string) $value);
                     break;
                 case 'Title':
                 case 'Author':
                 case 'Subject':
                 case 'Keywords':
                 case 'Creator':
                 case 'Producer':
                     if (extension_loaded('mbstring') === true) {
                         $detected = mb_detect_encoding($value);
                         if ($detected !== 'ASCII') {
                             $value = "■ " . mb_convert_encoding($value, 'UTF-16', $detected);
                         }
                     }
                     $docInfo->{$key} = new Zend_Pdf_Element_String((string) $value);
                     break;
                 default:
                     $docInfo->{$key} = Zend_Pdf_Element::phpToPdf($value);
                     break;
             }
         }
         $this->_trailer->Info = $docInfo;
     }
     $this->_dumpPages();
     $this->_dumpNamedDestinations();
     $this->_dumpOutlines();
     if (!$this->_objFactory->isModified()) {
         if ($newSegmentOnly) {
             return '';
         }
         if ($outputStream === null) {
             return $this->_trailer->getPDFString();
         } else {
             $pdfData = $this->_trailer->getPDFString();
             while (strlen($pdfData) > 0 && ($byteCount = fwrite($outputStream, $pdfData)) != false) {
                 $pdfData = substr($pdfData, $byteCount);
             }
             return '';
         }
     }
     $offset = $this->_trailer->getPDFLength();
     $lastFreeObject = $this->_trailer->getLastFreeObject();
     $xrefTable = array();
     $xrefSectionStartNums = array();
     $xrefSection = array();
     $xrefSection[] = 0;
     $xrefSectionStartNums[] = 0;
     $lastObjNum = 0;
     if ($outputStream !== null) {
         if (!$newSegmentOnly) {
             $pdfData = $this->_trailer->getPDFString();
             while (strlen($pdfData) > 0 && ($byteCount = fwrite($outputStream, $pdfData)) != false) {
                 $pdfData = substr($pdfData, $byteCount);
             }
         }
     } else {
         $pdfSegmentBlocks = $newSegmentOnly ? array() : array($this->_trailer->getPDFString());
     }
     foreach ($this->_objFactory->listModifiedObjects() as $updateInfo) {
         $objNum = $updateInfo->getObjNum();
         if ($objNum - $lastObjNum != 1) {
             $xrefTable[] = $xrefSection;
             $xrefSection = array();
             $xrefSectionStartNums[] = $objNum;
         }
         if ($updateInfo->isFree()) {
             $xrefSection[] = sprintf("%010d %05d f \n", $lastFreeObject, $updateInfo->getGenNum());
             $lastFreeObject = $objNum;
         } else {
             $xrefSection[] = sprintf("%010d %05d n \n", $offset, $updateInfo->getGenNum());
             $pdfBlock = $updateInfo->getObjectDump();
             $offset += strlen($pdfBlock);
             if ($outputStream === null) {
//.........这里部分代码省略.........
开发者ID:subashemphasize,项目名称:test_site,代码行数:101,代码来源:Pdf_Pack.php


注:本文中的Zend_Pdf_Element::phpToPdf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。