protected function drawFont($object)
 {
     $fontItem = $object->getItem();
     if ($fontItem->getFace() == 'bold') {
         $fontDecoration = 'bold';
     } else {
         $fontDecoration = 'regular';
     }
     $fontPath = SERVER_BASE . '/fonts/' . $fontItem->getName() . '.ttf';
     if (is_file($fontPath)) {
         $font = Zend_Pdf_Font::fontWithPath($fontPath, Zend_Pdf_Font::EMBED_SUPPRESS_EMBED_EXCEPTION);
     } else {
         if ($fontDecoration == "bold") {
             $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD);
         } else {
             $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
         }
     }
     if ($fontItem->getFace() == "invert") {
         $this->page->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0));
         //schwarze farbe setzen fuer Hintergrund
         $width = $this->widthForStringUsingFontSize($object->getValue(), $font, $fontItem->getSize());
         $height = $fontItem->getSize();
         $this->page->drawRectangle($this->coordX($this->mmToPts($object->getPosx())), $this->coordY($this->mmToPts($object->getPosy())) + $height / 2, $this->coordX($this->mmToPts($object->getPosx())) + $width, $this->coordY($this->mmToPts($object->getPosy())) - $height / 2, Zend_Pdf_Page::SHAPE_DRAW_FILL);
         $this->page->setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 1));
         //weiße farbe setzen fuer Text
     } else {
         $this->page->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0));
         //schwarze farbe setzen fuer text
     }
     $this->page->setFont($font, $fontItem->getSize());
     if ($fontItem->getRotation() !== null) {
         $this->page->rotate($this->coordX($this->mmToPts($object->getPosx())), $this->coordY($this->mmToPts($object->getPosy())), deg2rad(360 - $fontItem->getRotation()));
     }
     $this->page->drawText($object->getValue(), $this->coordX($this->mmToPts($object->getPosx())), $this->coordY($this->mmToPts($object->getPosy()) + $fontItem->getSize() / 2), 'UTF-8');
     if ($fontItem->getRotation() !== null) {
         $this->page->rotate($this->coordX($this->mmToPts($object->getPosx())), $this->coordY($this->mmToPts($object->getPosy())), -deg2rad(360 - $fontItem->getRotation()));
     }
 }
示例#2
0
 public function testPageCloning()
 {
     $pdf = Zend_Pdf::load(dirname(__FILE__) . '/_files/pdfarchiving.pdf');
     $srcPageCount = count($pdf->pages);
     try {
         $newPage = clone reset($pdf->pages);
     } catch (Zend_Pdf_Exception $e) {
         if (strpos($e->getMessage(), 'Cloning Zend_Pdf_Page object using \'clone\' keyword is not supported.') !== 0) {
             throw $e;
         }
         // Exception is thrown
     }
     $outputPageSet = array();
     foreach ($pdf->pages as $srcPage) {
         $page = new Zend_Pdf_Page($srcPage);
         $outputPageSet[] = $srcPage;
         $outputPageSet[] = $page;
         $page->saveGS();
         // Create new Style
         $page->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0.9))->setLineColor(new Zend_Pdf_Color_GrayScale(0.2))->setLineWidth(3)->setLineDashingPattern(array(3, 2, 3, 4), 1.6)->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 32);
         $page->rotate(0, 0, M_PI_2 / 3);
         $page->drawText('Modified by Zend Framework!', 150, 0);
         $page->restoreGS();
     }
     // Add new page generated by Zend_Pdf object (page is attached to the specified the document)
     $pdf->pages = $outputPageSet;
     $pdf->save(dirname(__FILE__) . '/_files/output.pdf');
     unset($pdf);
     $pdf1 = Zend_Pdf::load(dirname(__FILE__) . '/_files/output.pdf');
     $this->assertTrue($pdf1 instanceof Zend_Pdf);
     $this->assertEquals($srcPageCount * 2, count($pdf1->pages));
     unset($pdf1);
     unlink(dirname(__FILE__) . '/_files/output.pdf');
 }
 /**
  * Apply stamp on one page with given style.
  * 
  * @param Zend_Pdf_Page  $page
  * @param Zend_Pdf_Style $style
  * @param String         $stamp
  * 
  * @return void
  */
 protected function stampOnePage($page, $style, $stamp)
 {
     $height = $page->getHeight();
     $page->setStyle($style);
     $page->drawRectangle(40, 40, 60, $height - 40, Zend_Pdf_Page::SHAPE_DRAW_STROKE);
     $page->rotate(20, 20, 1.57);
     $page->drawText($stamp, 50, -10);
 }