Exemplo n.º 1
0
 /**
  * Create destination object
  *
  * @param \Zend\Pdf\Page|integer $page  Page object or page number
  * @param float $left  Left edge of displayed page
  * @param float $top   Top edge of displayed page
  * @param float $zoom  Zoom factor
  * @return \Zend\Pdf\Destination\Zoom
  * @throws \Zend\Pdf\Exception\ExceptionInterface
  */
 public static function create($page, $left = null, $top = null, $zoom = null)
 {
     $destinationArray = new InternalType\ArrayObject();
     if ($page instanceof Pdf\Page) {
         $destinationArray->items[] = $page->getPageDictionary();
     } elseif (is_integer($page)) {
         $destinationArray->items[] = new InternalType\NumericObject($page);
     } else {
         throw new Exception\InvalidArgumentException('$page parametr must be a \\Zend\\Pdf\\Page object or a page number.');
     }
     $destinationArray->items[] = new InternalType\NameObject('XYZ');
     if ($left === null) {
         $destinationArray->items[] = new InternalType\NullObject();
     } else {
         $destinationArray->items[] = new InternalType\NumericObject($left);
     }
     if ($top === null) {
         $destinationArray->items[] = new InternalType\NullObject();
     } else {
         $destinationArray->items[] = new InternalType\NumericObject($top);
     }
     if ($zoom === null) {
         $destinationArray->items[] = new InternalType\NullObject();
     } else {
         $destinationArray->items[] = new InternalType\NumericObject($zoom);
     }
     return new self($destinationArray);
 }
Exemplo n.º 2
0
Arquivo: Zoom.php Projeto: stunti/zf2
 /**
  * Create destination object
  *
  * @param \Zend\PDF\Page|integer $page  Page object or page number
  * @param float $left  Left edge of displayed page
  * @param float $top   Top edge of displayed page
  * @param float $zoom  Zoom factor
  * @return \Zend\PDF\Destination\Zoom
  * @throws \Zend\PDF\Exception
  */
 public static function create($page, $left = null, $top = null, $zoom = null)
 {
     $destinationArray = new InternalType\ArrayObject();
     if ($page instanceof PDF\Page) {
         $destinationArray->items[] = $page->getPageDictionary();
     } else {
         if (is_integer($page)) {
             $destinationArray->items[] = new InternalType\NumericObject($page);
         } else {
             throw new PDF\Exception('Page entry must be a Zend_PDF_Page object or a page number.');
         }
     }
     $destinationArray->items[] = new InternalType\NameObject('XYZ');
     if ($left === null) {
         $destinationArray->items[] = new InternalType\NullObject();
     } else {
         $destinationArray->items[] = new InternalType\NumericObject($left);
     }
     if ($top === null) {
         $destinationArray->items[] = new InternalType\NullObject();
     } else {
         $destinationArray->items[] = new InternalType\NumericObject($top);
     }
     if ($zoom === null) {
         $destinationArray->items[] = new InternalType\NullObject();
     } else {
         $destinationArray->items[] = new InternalType\NumericObject($zoom);
     }
     return new self($destinationArray);
 }
Exemplo n.º 3
0
 /**
  * Create destination object
  *
  * @param \Zend\Pdf\Page|integer $page  Page object or page number
  * @return \Zend\Pdf\Destination\Fit
  * @throws \Zend\Pdf\Exception
  */
 public static function create($page)
 {
     $destinationArray = new InternalType\ArrayObject();
     if ($page instanceof Pdf\Page) {
         $destinationArray->items[] = $page->getPageDictionary();
     } else {
         if (is_integer($page)) {
             $destinationArray->items[] = new InternalType\NumericObject($page);
         } else {
             throw new Pdf\Exception('Page entry must be a Zend_PDF_Page object or a page number.');
         }
     }
     $destinationArray->items[] = new InternalType\NameObject('Fit');
     return new self($destinationArray);
 }
Exemplo n.º 4
0
 /**
  * Create destination object
  *
  * @param \Zend\Pdf\Page|integer $page  Page object or page number
  * @return \Zend\Pdf\Destination\Fit
  * @throws \Zend\Pdf\Exception\ExceptionInterface
  */
 public static function create($page)
 {
     $destinationArray = new InternalType\ArrayObject();
     if ($page instanceof Pdf\Page) {
         $destinationArray->items[] = $page->getPageDictionary();
     } else {
         if (is_integer($page)) {
             $destinationArray->items[] = new InternalType\NumericObject($page);
         } else {
             throw new Exception\InvalidArgumentException('$page parametr must be a \\Zend\\Pdf\\Page object or a page number.');
         }
     }
     $destinationArray->items[] = new InternalType\NameObject('Fit');
     return new self($destinationArray);
 }
Exemplo n.º 5
0
 public function testDrawing()
 {
     $pdf = new Pdf\PdfDocument();
     // Add new page generated by \Zend\Pdf\PdfDocument object (page is attached to the specified the document)
     $pdf->pages[] = $page1 = $pdf->newPage('A4');
     // Add new page generated by \Zend\Pdf\Page object (page is not attached to the document)
     $pdf->pages[] = $page2 = new Pdf\Page(Pdf\Page::SIZE_LETTER_LANDSCAPE);
     // Add new page generated by \Zend\Pdf\Page object (page is attached to the document)
     $pdf->pages[] = $page3 = $pdf->newPage('A4');
     // Create new font
     $font = Pdf\Font::fontWithName(Pdf\Font::FONT_HELVETICA);
     // Apply font and draw text
     $page1->setFont($font, 36)->setFillColor(Color\Html::color('#9999cc'))->drawText('Helvetica 36 text string', 60, 500);
     // Use font object for another page
     $page2->setFont($font, 24)->drawText('Helvetica 24 text string', 60, 500);
     // Use another font
     $page2->setFont(Pdf\Font::fontWithName(Pdf\Font::FONT_TIMES), 32)->drawText('Times-Roman 32 text string', 60, 450);
     // Draw rectangle
     $page2->setFillColor(new Color\GrayScale(0.8))->setLineColor(new Color\GrayScale(0.2))->setLineDashingPattern(array(3, 2, 3, 4), 1.6)->drawRectangle(60, 400, 500, 350);
     // Draw rounded rectangle
     $page2->setFillColor(new Color\GrayScale(0.9))->setLineColor(new Color\GrayScale(0.5))->setLineDashingPattern(Pdf\Page::LINE_DASHING_SOLID)->drawRoundedRectangle(425, 350, 475, 400, 20);
     // Draw circle
     $page2->setLineDashingPattern(Pdf\Page::LINE_DASHING_SOLID)->setFillColor(new Color\Rgb(1, 0, 0))->drawCircle(85, 375, 25);
     // Draw sectors
     $page2->drawCircle(200, 375, 25, 2 * M_PI / 3, -M_PI / 6)->setFillColor(new Color\Cmyk(1, 0, 0, 0))->drawCircle(200, 375, 25, M_PI / 6, 2 * M_PI / 3)->setFillColor(new Color\Rgb(1, 1, 0))->drawCircle(200, 375, 25, -M_PI / 6, M_PI / 6);
     // Draw ellipse
     $page2->setFillColor(new Color\Html('Red'))->drawEllipse(250, 400, 400, 350)->setFillColor(new Color\Cmyk(1, 0, 0, 0))->drawEllipse(250, 400, 400, 350, M_PI / 6, 2 * M_PI / 3)->setFillColor(new Color\Rgb(1, 1, 0))->drawEllipse(250, 400, 400, 350, -M_PI / 6, M_PI / 6);
     // Draw and fill polygon
     $page2->setFillColor(new Color\Rgb(1, 0, 1));
     $x = array();
     $y = array();
     for ($count = 0; $count < 8; $count++) {
         $x[] = 140 + 25 * cos(3 * M_PI_4 * $count);
         $y[] = 375 + 25 * sin(3 * M_PI_4 * $count);
     }
     $page2->drawPolygon($x, $y, Pdf\Page::SHAPE_DRAW_FILL_AND_STROKE, Pdf\Page::FILL_METHOD_EVEN_ODD);
     // Draw line
     $page2->setLineWidth(0.5)->drawLine(60, 375, 500, 375);
     // -----------------------------------------------------------------------------------
     $page3->translate(200, 10)->rotate(10, 10, M_PI_2 / 9)->scale(0.7, 1.2)->skew(60, 350, M_PI_2 / 9, -M_PI_2 / 9);
     // Use font object for another page
     $page3->setFont($font, 24)->drawText('Helvetica 24 text string', 60, 500);
     // Use another font
     $page3->setFont(Pdf\Font::fontWithName(Pdf\Font::FONT_TIMES), 32)->drawText('Times-Roman 32 text string', 60, 450);
     // Draw rectangle
     $page3->setFillColor(new Color\GrayScale(0.8))->setLineColor(new Color\GrayScale(0.2))->setLineDashingPattern(array(3, 2, 3, 4), 1.6)->drawRectangle(60, 400, 500, 350);
     // Draw rounded rectangle
     $page3->setFillColor(new Color\GrayScale(0.9))->setLineColor(new Color\GrayScale(0.5))->setLineDashingPattern(Pdf\Page::LINE_DASHING_SOLID)->drawRoundedRectangle(425, 350, 475, 400, 20);
     // Draw circle
     $page3->setLineDashingPattern(Pdf\Page::LINE_DASHING_SOLID)->setFillColor(new Color\Rgb(1, 0, 0))->drawCircle(85, 375, 25);
     // Draw sectors
     $page3->drawCircle(200, 375, 25, 2 * M_PI / 3, -M_PI / 6)->setFillColor(new Color\Cmyk(1, 0, 0, 0))->drawCircle(200, 375, 25, M_PI / 6, 2 * M_PI / 3)->setFillColor(new Color\Rgb(1, 1, 0))->drawCircle(200, 375, 25, -M_PI / 6, M_PI / 6);
     // Draw ellipse
     $page3->setFillColor(new Color\Html('Red'))->drawEllipse(250, 400, 400, 350)->setFillColor(new Color\Cmyk(1, 0, 0, 0))->drawEllipse(250, 400, 400, 350, M_PI / 6, 2 * M_PI / 3)->setFillColor(new Color\Rgb(1, 1, 0))->drawEllipse(250, 400, 400, 350, -M_PI / 6, M_PI / 6);
     // Draw and fill polygon
     $page3->setFillColor(new Color\Rgb(1, 0, 1));
     $x = array();
     $y = array();
     for ($count = 0; $count < 8; $count++) {
         $x[] = 140 + 25 * cos(3 * M_PI_4 * $count);
         $y[] = 375 + 25 * sin(3 * M_PI_4 * $count);
     }
     $page3->drawPolygon($x, $y, Pdf\Page::SHAPE_DRAW_FILL_AND_STROKE, Pdf\Page::FILL_METHOD_EVEN_ODD);
     // Draw line
     $page3->setLineWidth(0.5)->drawLine(60, 375, 500, 375);
     $pdf->save(__DIR__ . '/_files/output.pdf');
     unset($pdf);
     $pdf1 = Pdf\PdfDocument::load(__DIR__ . '/_files/output.pdf');
     $this->assertTrue($pdf1 instanceof Pdf\PdfDocument);
     unset($pdf1);
     unlink(__DIR__ . '/_files/output.pdf');
 }
Exemplo n.º 6
0
 public function testPageDuplicating()
 {
     $pdf = Pdf\PdfDocument::load(__DIR__ . '/_files/pdfarchiving.pdf');
     $srcPageCount = count($pdf->pages);
     $outputPageSet = array();
     foreach ($pdf->pages as $srcPage) {
         $page = new Pdf\Page($srcPage);
         $outputPageSet[] = $srcPage;
         $outputPageSet[] = $page;
         $page->saveGS();
         // Create new Style
         $page->setFillColor(new Color\Rgb(0, 0, 0.9))->setLineColor(new Color\GrayScale(0.2))->setLineWidth(3)->setLineDashingPattern(array(3, 2, 3, 4), 1.6)->setFont(Pdf\Font::fontWithName(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(__DIR__ . '/_files/output.pdf');
     unset($pdf);
     $pdf1 = Pdf\PdfDocument::load(__DIR__ . '/_files/output.pdf');
     $this->assertTrue($pdf1 instanceof Pdf\PdfDocument);
     $this->assertEquals($srcPageCount * 2, count($pdf1->pages));
     unset($pdf1);
     unlink(__DIR__ . '/_files/output.pdf');
 }
Exemplo n.º 7
0
 public function testPageCloning()
 {
     $pdf = PDF\PDFDocument::load(dirname(__FILE__) . '/_files/pdfarchiving.pdf');
     $srcPageCount = count($pdf->pages);
     try {
         $newPage = clone reset($pdf->pages);
     } catch (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 PDF\Page($srcPage);
         $outputPageSet[] = $srcPage;
         $outputPageSet[] = $page;
         $page->saveGS();
         // Create new Style
         $page->setFillColor(new Color\RGB(0, 0, 0.9))->setLineColor(new Color\GrayScale(0.2))->setLineWidth(3)->setLineDashingPattern(array(3, 2, 3, 4), 1.6)->setFont(PDF\Font::fontWithName(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 = PDF\PDFDocument::load(dirname(__FILE__) . '/_files/output.pdf');
     $this->assertTrue($pdf1 instanceof PDF\PDFDocument);
     $this->assertEquals($srcPageCount * 2, count($pdf1->pages));
     unset($pdf1);
     unlink(dirname(__FILE__) . '/_files/output.pdf');
 }
Exemplo n.º 8
0
 /**
  * Clone page, extract it and dependent objects from the current document,
  * so it can be used within other docs
  *
  * return \Zend\Pdf\Page
  */
 public function clonePage(Pdf\Page $page)
 {
     return $page->clonePage($this->_factory, $this->_processed);
 }