示例#1
0
 /**
  * Return object as string
  *
  * @param \ZendPdf\ObjectFactory $factory
  * @return string
  */
 public function toString(Pdf\ObjectFactory $factory = null)
 {
     $outStr = '<<';
     $lastNL = 0;
     foreach ($this->_items as $name => $element) {
         if (!is_object($element)) {
             throw new Exception\RuntimeException('Wrong data');
         }
         if (strlen($outStr) - $lastNL > 128) {
             $outStr .= "\n";
             $lastNL = strlen($outStr);
         }
         $nameObj = new NameObject($name);
         $outStr .= $nameObj->toString($factory) . ' ' . $element->toString($factory) . ' ';
     }
     $outStr .= '>>';
     return $outStr;
 }
示例#2
0
文件: Page.php 项目: marcyniu/vendors
 /**
  * Draw an image at the specified position on the page.
  *
  * @param \ZendPdf\Image $image
  * @param float $x1
  * @param float $y1
  * @param float $x2
  * @param float $y2
  * @return \ZendPdf\Page
  */
 public function drawImage(Resource\Image\AbstractImage $image, $x1, $y1, $x2, $y2)
 {
     $this->_addProcSet('PDF');
     $imageName = $this->_attachResource('XObject', $image);
     $imageNameObj = new InternalType\NameObject($imageName);
     $x1Obj = new InternalType\NumericObject($x1);
     $y1Obj = new InternalType\NumericObject($y1);
     $widthObj = new InternalType\NumericObject($x2 - $x1);
     $heightObj = new InternalType\NumericObject($y2 - $y1);
     $this->_contents .= "q\n" . '1 0 0 1 ' . $x1Obj->toString() . ' ' . $y1Obj->toString() . " cm\n" . $widthObj->toString() . ' 0 0 ' . $heightObj->toString() . " 0 0 cm\n" . $imageNameObj->toString() . " Do\n" . "Q\n";
     return $this;
 }
示例#3
0
 public function testUnescape()
 {
     $this->assertEquals(InternalType\NameObject::unescape('My#20Cool#20Name#28#29'), 'My Cool Name()');
 }
示例#4
0
 /**
  * Read elemental object from a PDF stream
  *
  * @return \ZendPdf\InternalType\AbstractTypeObject
  * @throws \ZendPdf\Exception\ExceptionInterface
  */
 public function readElement($nextLexeme = null)
 {
     if ($nextLexeme === null) {
         $nextLexeme = $this->readLexeme();
     }
     /**
      * Note: readElement() method is a public method and could be invoked from other classes.
      * We should care about _elements member management only if readElement() is invoked
      * by self::getObject() method.
      */
     switch ($nextLexeme) {
         case '(':
             return $this->_elements[] = $this->_readString();
         case '<':
             return $this->_elements[] = $this->_readBinaryString();
         case '/':
             return $this->_elements[] = new InternalType\NameObject(InternalType\NameObject::unescape($this->readLexeme()));
         case '[':
             return $this->_elements[] = $this->_readArray();
         case '<<':
             return $this->_elements[] = $this->_readDictionary();
         case ')':
             // fall through to next case
         // fall through to next case
         case '>':
             // fall through to next case
         // fall through to next case
         case ']':
             // fall through to next case
         // fall through to next case
         case '>>':
             // fall through to next case
         // fall through to next case
         case '{':
             // fall through to next case
         // fall through to next case
         case '}':
             throw new Exception\CorruptedPdfException(sprintf('PDF file syntax error. Offset - 0x%X.', $this->offset));
         default:
             if (strcasecmp($nextLexeme, 'true') == 0) {
                 return $this->_elements[] = new InternalType\BooleanObject(true);
             } elseif (strcasecmp($nextLexeme, 'false') == 0) {
                 return $this->_elements[] = new InternalType\BooleanObject(false);
             } elseif (strcasecmp($nextLexeme, 'null') == 0) {
                 return $this->_elements[] = new InternalType\NullObject();
             }
             $ref = $this->_readReference($nextLexeme);
             if ($ref !== null) {
                 return $this->_elements[] = $ref;
             }
             return $this->_elements[] = $this->_readNumeric($nextLexeme);
     }
 }