Пример #1
0
 public function testProcessing()
 {
     $pdf = new PDF\PDFDocument();
     $page1 = $pdf->newPage(PDF\Page::SIZE_A4);
     $page2 = $pdf->newPage(PDF\Page::SIZE_A4);
     $page3 = $pdf->newPage(PDF\Page::SIZE_A4);
     // not actually included into pages array
     $pdf->pages[] = $page1;
     $pdf->pages[] = $page2;
     $this->assertTrue(count($pdf->getNamedDestinations()) == 0);
     $destination1 = Destination\Fit::create($page1);
     $destination2 = Destination\Fit::create($page2);
     $action1 = Action\GoToAction::create($destination1);
     $pdf->setNamedDestination('GoToPage1', $action1);
     $this->assertTrue($pdf->getNamedDestination('GoToPage1') === $action1);
     $this->assertTrue($pdf->getNamedDestination('GoToPage9') === null);
     $pdf->setNamedDestination('Page2', $destination2);
     $this->assertTrue($pdf->getNamedDestination('Page2') === $destination2);
     $this->assertTrue($pdf->getNamedDestination('Page9') === null);
     $pdf->setNamedDestination('Page1', $destination1);
     $pdf->setNamedDestination('Page1_1', Destination\Fit::create(1));
     $pdf->setNamedDestination('Page9_1', Destination\Fit::create(9));
     // will be egnored
     $action3 = Action\GoToAction::create(Destination\Fit::create($page3));
     $pdf->setNamedDestination('GoToPage3', $action3);
     $this->assertTrue(strpos($pdf->render(), '[(GoToPage1) <</Type /Action /S /GoTo /D [3 0 R /Fit ] >> (Page1) [3 0 R /Fit ] (Page1_1) [1 /Fit ] (Page2) [4 0 R /Fit ] ]') !== false);
 }
Пример #2
0
 public function testCreate()
 {
     $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);
     // 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\RGB(1, 0, 0))->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);
     $pdf->save(dirname(__FILE__) . '/_files/output.pdf');
     unset($pdf);
     $pdf1 = PDF\PDFDocument::load(dirname(__FILE__) . '/_files/output.pdf');
     $this->assertTrue($pdf1 instanceof PDF\PDFDocument);
     unset($pdf1);
     unlink(dirname(__FILE__) . '/_files/output.pdf');
 }
Пример #3
0
 public function testFontExtracting()
 {
     if (PHP_OS == 'AIX') {
         $this->markTestSkipped('Not supported on AIX');
     }
     $pdf = new PDF\PDFDocument();
     $fontsList = array(PDF\Font::FONT_COURIER, PDF\Font::FONT_HELVETICA_BOLD, PDF\Font::FONT_TIMES_BOLD_ITALIC);
     foreach ($fontsList as $fontName) {
         // Add new page generated by Zend_PDF object (page is attached to the specified the document)
         $pdf->pages[] = $page = $pdf->newPage(PDF\Page::SIZE_A4_LANDSCAPE);
         $font = PDF\Font::fontWithName($fontName);
         $page->setFont($font, 10)->drawText($font->getFontName(PDF\Font::NAME_POSTSCRIPT, 'en') . ':', 100, 400);
         $page->setFont($font, 20)->drawText("'The quick brown fox jumps over the lazy dog'", 100, 360);
         $type = $font->getFontType();
     }
     $TTFFontsList = array('VeraBd.ttf', 'VeraBI.ttf', 'VeraIt.ttf', 'VeraMoBd.ttf', 'VeraMoBI.ttf', 'VeraMoIt.ttf', 'VeraMono.ttf', 'VeraSeBd.ttf', 'VeraSe.ttf', 'Vera.ttf');
     foreach ($TTFFontsList as $fontName) {
         // Add new page generated by Zend_PDF object (page is attached to the specified the document)
         $pdf->pages[] = $page = $pdf->newPage(PDF\Page::SIZE_A4_LANDSCAPE);
         $font = PDF\Font::fontWithPath(__DIR__ . '/_fonts/' . $fontName);
         $page->setFont($font, 10)->drawText($font->getFontName(PDF\Font::NAME_POSTSCRIPT, 'en', 'CP1252') . ':', 100, 400);
         $page->setFont($font, 20)->drawText("'The quick brown fox jumps over the lazy dog'", 100, 360);
         $type = $font->getFontType();
     }
     $pdf->save(__DIR__ . '/_files/output.pdf');
     unset($pdf);
     $pdf1 = PDF\PDFDocument::load(__DIR__ . '/_files/output.pdf');
     $newPages = array();
     $fontList = array();
     $fontNames = array();
     foreach ($pdf1->pages as $page) {
         $pageFonts = $page->extractFonts();
         foreach ($pageFonts as $font) {
             $fontList[] = $font;
             $fontNames[] = $font->getFontName(PDF\Font::NAME_POSTSCRIPT, 'en', 'UTF-8');
         }
     }
     $this->assertEquals(array(PDF\Font::FONT_COURIER, PDF\Font::FONT_HELVETICA_BOLD, PDF\Font::FONT_TIMES_BOLD_ITALIC, 'BitstreamVeraSans-Bold', 'BitstreamVeraSans-BoldOblique', 'BitstreamVeraSans-Oblique', 'BitstreamVeraSansMono-Bold', 'BitstreamVeraSansMono-BoldOb', 'BitstreamVeraSansMono-Oblique', 'BitstreamVeraSansMono-Roman', 'BitstreamVeraSerif-Bold', 'BitstreamVeraSerif-Roman', 'BitstreamVeraSans-Roman'), $fontNames);
     $pdf1->pages[] = $page = $pdf1->newPage(PDF\Page::SIZE_A4);
     $yPosition = 700;
     foreach ($fontList as $font) {
         $page->setFont($font, 15)->drawText("The quick brown fox jumps over the lazy dog", 100, $yPosition);
         $yPosition -= 30;
     }
     $fontNames1 = array();
     foreach ($pdf1->extractFonts() as $font) {
         $fontNames1[] = $font->getFontName(PDF\Font::NAME_POSTSCRIPT, 'en', 'UTF-8');
     }
     $this->assertEquals(array(PDF\Font::FONT_COURIER, PDF\Font::FONT_HELVETICA_BOLD, PDF\Font::FONT_TIMES_BOLD_ITALIC, 'BitstreamVeraSans-Bold', 'BitstreamVeraSans-BoldOblique', 'BitstreamVeraSans-Oblique', 'BitstreamVeraSansMono-Bold', 'BitstreamVeraSansMono-BoldOb', 'BitstreamVeraSansMono-Oblique', 'BitstreamVeraSansMono-Roman', 'BitstreamVeraSerif-Bold', 'BitstreamVeraSerif-Roman', 'BitstreamVeraSans-Roman'), $fontNames1);
     $page = reset($pdf1->pages);
     $font = $page->extractFont(PDF\Font::FONT_COURIER);
     $this->assertTrue($font instanceof Font\Extracted);
     $font = $page->extractFont(PDF\Font::FONT_TIMES_BOLD_ITALIC);
     $this->assertNull($font);
     $font = $pdf1->extractFont(PDF\Font::FONT_TIMES_BOLD_ITALIC);
     $this->assertTrue($font instanceof Font\Extracted);
     $font = $pdf1->extractFont(PDF\Font::FONT_TIMES_ROMAN);
     $this->assertNull($font);
     $pdf1->save(__DIR__ . '/_files/output1.pdf');
     unset($pdf1);
     $pdf2 = PDF\PDFDocument::load(__DIR__ . '/_files/output1.pdf');
     $this->assertTrue($pdf2 instanceof PDF\PDFDocument);
     unset($pdf2);
     unlink(__DIR__ . '/_files/output.pdf');
     unlink(__DIR__ . '/_files/output1.pdf');
 }
Пример #4
0
 public function testGetDestination2()
 {
     $pdf = new PDF\PDFDocument();
     $page1 = $pdf->newPage(PDF\Page::SIZE_A4);
     $page2 = $pdf->newPage(PDF\Page::SIZE_A4);
     $page3 = $pdf->newPage(PDF\Page::SIZE_A4);
     // Page created, but not included into pages list
     $pdf->pages[] = $page1;
     $pdf->pages[] = $page2;
     $action1 = Action\GoToAction::create(Destination\Fit::create($page2));
     $action2 = Action\GoToAction::create(Destination\Fit::create($page3));
     $this->assertTrue($pdf->resolveDestination($action1->getDestination()) === $page2);
     $this->assertTrue($pdf->resolveDestination($action2->getDestination()) === null);
 }
Пример #5
0
 public function testCreate()
 {
     $pdf = new PDF\PDFDocument();
     $page1 = $pdf->newPage(PDF\Page::SIZE_A4);
     $page2 = $pdf->newPage(PDF\Page::SIZE_A4);
     $destination = Destination\Zoom::create($page2, 0, 842, 0.5);
     $this->assertTrue($destination instanceof Destination\Zoom);
     $this->assertEquals($destination->getResource()->toString(), '[4 0 R /XYZ 0 842 0.5 ]');
     $destination = Destination\Fit::create($page2);
     $this->assertTrue($destination instanceof Destination\Fit);
     $this->assertEquals($destination->getResource()->toString(), '[4 0 R /Fit ]');
     $destination = Destination\FitHorizontally::create($page2, 842);
     $this->assertTrue($destination instanceof Destination\FitHorizontally);
     $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitH 842 ]');
     $destination = Destination\FitVertically::create(2, 0);
     $this->assertTrue($destination instanceof Destination\FitVertically);
     $this->assertEquals($destination->getResource()->toString(), '[2 /FitV 0 ]');
     $destination = Destination\FitRectangle::create($page1, 0, 10, 595, 842);
     $this->assertTrue($destination instanceof Destination\FitRectangle);
     $this->assertEquals($destination->getResource()->toString(), '[3 0 R /FitR 0 10 595 842 ]');
     $destination = Destination\FitBoundingBox::create(1);
     $this->assertTrue($destination instanceof Destination\FitBoundingBox);
     $this->assertEquals($destination->getResource()->toString(), '[1 /FitB ]');
     $destination = Destination\FitBoundingBoxHorizontally::create($page2, 842);
     $this->assertTrue($destination instanceof Destination\FitBoundingBoxHorizontally);
     $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitBH 842 ]');
     $destination = Destination\FitBoundingBoxVertically::create($page2, 0);
     $this->assertTrue($destination instanceof Destination\FitBoundingBoxVertically);
     $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitBV 0 ]');
 }
Пример #6
0
 public function testNewPageCreator()
 {
     $pdf = new PDF\PDFDocument();
     $page = $pdf->newPage(PDF\Page::SIZE_A4);
     $this->assertTrue($page instanceof PDF\Page);
 }