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);
 }
 /**
  * @{inheritDoc}
  */
 public function newPage($pageSize)
 {
     $pageSizeConstant = constant('\\ZendPdf\\Page::' . $pageSize);
     $page = $this->pdf->newPage($pageSizeConstant);
     $this->pdf->pages[] = $page;
     return $page;
 }
 /**
  * Generate the Pdf
  * @param IntentDocumentGeneratedEvent $event the event
  * @see http://stackoverflow.com/questions/7585474/accessing-files-relative-to-bundle-in-symfony2
  * @todo finaliser l'inscrition de toutes les info dynamiques
  * @todo  avoir une sepa-template neutre
  * @todo  insérer le logo du layout courant dans le pdf
  * @todo  insérer des textes simple en y ajoutant le nom du client dynamiquement
  * @todo  insérer l'ICS
  */
 public function generate(IntentDocumentGeneratedEvent $event)
 {
     /**
      * @var Ecedi\Donate\CoreBundle\Entity\Intent
      */
     $intent = $event->getIntent();
     if ($intent->getPaymentMethod() === SepaOfflinePaymentMethod::ID && $event->getDocument() === null) {
         $pdf = new Pdf\PdfDocument();
         $pdf->pages[] = $page1 = $pdf->newPage('A4');
         $page1->setFont(Pdf\Font::fontWithName(Pdf\Font::FONT_HELVETICA), 12);
         $path = $this->kernel->locateResource('@DonatePaymentBundle/Resources/public/img/sepa-template.jpg');
         $stampImageJPG = Pdf\Image::imageWithPath($path);
         $page1->drawImage($stampImageJPG, 0, 0, 595, 842);
         $page1->drawText($this->rumGenerator->generate($intent), 170, 389, 'UTF-8');
         //TODO faire la suite
         $event->setDocument($pdf);
         $event->stopPropagation();
     }
 }
Example #4
0
 public function testCreate()
 {
     $pdf = new Pdf\PdfDocument();
     // Add new page generated by \ZendPdf\PdfDocument object (page is attached to the specified the document)
     $pdf->pages[] = $page1 = $pdf->newPage('A4');
     // Add new page generated by \ZendPdf\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(__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');
 }
Example #5
0
 public function testNewPageCreator()
 {
     $pdf = new Pdf\PdfDocument();
     $page = $pdf->newPage(Pdf\Page::SIZE_A4);
     $this->assertTrue($page instanceof Pdf\Page);
 }
Example #6
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);
 }
Example #7
0
use VectorGraphics\IO\SVG\SVGWriter;
use VectorGraphics\IO\ZF\PDFWriter;
use VectorGraphics\Model\Graphic;
use ZendPdf\PdfDocument;
$name = isset($_GET['name']) ? $_GET['name'] : 'sample';
$type = isset($_GET['type']) ? $_GET['type'] : 'svg';
if (!file_exists(__DIR__ . "/{$name}.php")) {
    die("Unknown sample: {$name}");
}
$graphic = (require __DIR__ . "/{$name}.php");
if (!$graphic instanceof Graphic) {
    die("Invalid sample: {$name}");
}
switch ($type) {
    case 'svg':
        header('Content-Type: image/svg+xml');
        echo (new SVGWriter())->toSVG($graphic, 15, 15);
        break;
    case 'pdf':
        $document = new PdfDocument();
        $document->pages[] = $page = $document->newPage("A4");
        (new PDFWriter())->drawGraphic($page, $graphic, 50, 400, 400, 400);
        header('Content-Type: application/pdf');
        $tmp = tempnam(sys_get_temp_dir(), 'vector-graphics');
        $document->save($tmp);
        readfile($tmp);
        unlink($tmp);
        break;
    default:
        die("Unknown type: {$type} - (allowed: svg, pdf)");
}
Example #8
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 ]');
 }
Example #9
0
 /**
  * Start new page
  *
  * Adds a new page to the document.
  * 
  * @param float $width  Width
  * @param float $height Height
  *
  * @return bool Returns TRUE on success or FALSE on failure.
  */
 public function begin_page($width, $height)
 {
     $this->_page = $this->_zpdf->newPage($width, $height);
     $this->_zpdf->pages[] = $this->_page;
 }