public function pdfAction()
 {
     $iso2 = $this->params()->fromRoute('iso2');
     $table = $this->getServiceLocator()->get('city-codes-table');
     $viewModel = new ViewModel(array('cityList' => $table->getListByCountry($iso2), 'countryCode' => $iso2));
     $viewModel->setTemplate('form-demo/application/index/pdf-cities');
     $viewRender = $this->getServiceLocator()->get('ViewRenderer');
     $list = explode(PHP_EOL, $viewRender->render($viewModel));
     $font = Font::fontWithPath('/usr/share/fonts/truetype/freefont/FreeMono.ttf');
     $pdf = new PdfDocument();
     // top left 1" from top 1" from left
     $x = 72;
     $y = 720;
     $dec = 18;
     foreach ($list as $index => $row) {
         if (substr($row, 0, 1) == '=' || $y <= 72) {
             if ($index > 0) {
                 $pdf->pages[] = $page;
             }
             $page = new Page(Page::SIZE_LETTER);
             $page->setFont($font, 12);
             $y = 720;
         }
         $page->drawText($row, $x, $y);
         $y -= $dec;
     }
     $pdf->pages[] = $page;
     // retrieve the response object
     $response = $this->getResponse();
     // set the header
     $response->getHeaders()->addHeaders(array('Content-Type' => 'application/pdf'));
     $response->setContent($pdf->render());
     return $response;
 }
Пример #2
0
 /**
  * @param null $fileName
  * @return void|string
  */
 public function output($fileName = null)
 {
     if ($fileName !== null) {
         $this->pdf->save($fileName);
         return;
     }
     return $this->pdf->render();
 }
Пример #3
0
 public function testImplodePdfsReturnNotEmptyPdf()
 {
     /** @var $pdf \ZendPdf\PdfDocument */
     $pdf = implodePdfs(array(\ZendPdf\PdfDocument::load(__DIR__ . '/data/pdf1.pdf'), \ZendPdf\PdfDocument::load(__DIR__ . '/data/pdf2.pdf')));
     $this->assertGreaterThan(20000, strlen($pdf->render()));
     $this->assertSame(3, count($pdf->pages));
 }
Пример #4
0
 /**
  * Generates certificate of exellence and
  * triggers an event when the file is generated
  * @param \User\Model\Entity\User $user
  * @param string $examName
  */
 public function generateCertificate($user, $examName)
 {
     $config = $this->services->get('config');
     $pdf = PdfDocument::load($config['pdf']['exam_certificate']);
     // get the first page
     $page = $pdf->pages[0];
     // Extract the AdineKirnberg-Script font included in the PDF sample
     $font = $page->extractFont('AdineKirnberg-Script');
     $page->setFont($font, 80);
     // and write the name of the user with it
     $page->drawText($user->getName(), 200, 280);
     // after that use Time Bold to write the name of the exam
     $font = PdfFont::fontWithName(PdfFont::FONT_TIMES_BOLD);
     $page->setFont($font, 40);
     $page->drawText($examName, 200, 120);
     // We use the png image from the public/images folder
     $imageFile = 'public/images/zf2-logo.png';
     // get the right size to do some calculations
     $size = getimagesize($imageFile);
     // load the image
     $image = \ZendPdf\Image::imageWithPath($imageFile);
     $x = 580;
     $y = 440;
     // and finally draw the image
     $page->drawImage($image, $x, $y, $x + $size[0], $y + $size[1]);
     return $pdf;
 }
Пример #5
0
 /**
  * Close pdf resource
  * Closes the generated PDF file, and frees all document-related resources.
  * 
  * @return bool Returns TRUE on success or FALSE on failure.
  */
 public function close()
 {
     if ($this->_filename) {
         $this->_zpdf->save($this->_filename);
     }
     return true;
 }
Пример #6
0
 /**
  * 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();
     }
 }
Пример #7
0
 /**
  * Object constructor
  *
  * @param integer $objCount
  */
 public function __construct($objNum, $genNum, $isFree, $dump = null)
 {
     $this->_objNum = $objNum;
     $this->_genNum = $genNum;
     $this->_isFree = $isFree;
     if ($dump !== null) {
         if (strlen($dump) > 1024) {
             $this->_dump = Pdf\PdfDocument::getMemoryManager()->create($dump);
         } else {
             $this->_dump = $dump;
         }
     }
 }
Пример #8
0
 public function __construct()
 {
     parent::__construct();
     $this->single_page = $this->newPage('A4');
     // Bond paper portrait
 }
Пример #9
0
 /**
  * If the book defines a custom PDF cover, this method prepends it
  * to the PDF book.
  *
  * @param string $bookFilePath  The path of the original PDF book without the cover
  * @param string $coverFilePath The path of the PDF file which will be displayed as the cover of the book
  */
 public function addBookCover($bookFilePath, $coverFilePath)
 {
     if (!empty($coverFilePath)) {
         $pdfBook = PdfDocument::load($bookFilePath);
         $pdfCover = PdfDocument::load($coverFilePath);
         $pdfCover = clone $pdfCover->pages[0];
         array_unshift($pdfBook->pages, $pdfCover);
         $pdfBook->save($bookFilePath, true);
     }
 }
Пример #10
0
 /**
  * @{inheritDoc}
  */
 public function save($filename)
 {
     $this->pdf->save($filename);
     return $this;
 }
Пример #11
0
 public function setMetadataValue($name, $value)
 {
     switch ($name) {
         case 'Trapped':
             $value = $value === 'null' ? null : Util::convertBooleanValue($value);
             $this->getZendPdf()->properties[$name] = $value;
             break;
         case 'CreationDate':
         case 'ModDate':
             $value = PdfDocument::pdfDate(strtotime($value));
             $this->getZendPdf()->properties[$name] = $value;
             break;
         case 'Title':
         case 'Author':
         case 'Subject':
         case 'Keywords':
         case 'Creator':
             $this->getZendPdf()->properties[$name] = $value;
             break;
     }
 }
Пример #12
0
<?php

require 'vendor/autoload.php';
use Ibrows\ZendPdfHtml\HtmlDrawer;
use Ibrows\ZendPdfHtml\Parser\Tag;
use ZendPdf\PdfDocument;
use ZendPdf\Page;
$pdf = new PdfDocument();
$page = new Page(Page::SIZE_A4_LANDSCAPE);
$htmlPage = new HtmlDrawer();
$htmlPage->getParser()->registerTag(new Tag\Br());
$htmlPage->getParser()->registerTag(new Tag\Em());
$htmlPage->getParser()->registerTag(new Tag\H4());
$htmlPage->getParser()->registerTag(new Tag\Li());
$htmlPage->getParser()->registerTag(new Tag\P());
$htmlPage->getParser()->registerTag(new Tag\Strong());
$htmlPage->getParser()->registerTag(new Tag\Ul());
$htmlPage->drawHtml($page, '<h4>Produktbeschrieb</h4>
<ul>
<li>Winkelprofile mit Wandstärke 2.3 mm</li>
<li>Randzone konisch verjüngt als Einführhilfe</li>
<li>Längsrillen zur Markierung des minimalen Randabstandes<br />für Befestigungsmittel</li>
</ul>
<h4>Material</h4>
<p>Aluminium ENAW-6060</p>
<h4>Spezifikationen</h4>
<ul>
<li>Zuschnitt und Positionierung</li>
<li>Gehrungsschnitte</li>
<li>Ausklinkungen</li>
<li>Schweissen / Vernieten von Eckelementen</li>
Пример #13
0
 public function testPageCloning()
 {
     $pdf = Pdf\PdfDocument::load(__DIR__ . '/_files/pdfarchiving.pdf');
     $pdf1 = new Pdf\PdfDocument();
     $srcPageCount = count($pdf->pages);
     $outputPageSet = array();
     foreach ($pdf->pages as $srcPage) {
         $page = clone $srcPage;
         $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();
         $pdf1->pages[] = $page;
     }
     $pdf1->save(__DIR__ . '/_files/output.pdf');
     unset($pdf);
     unset($pdf1);
     $pdf2 = Pdf\PdfDocument::load(__DIR__ . '/_files/output.pdf');
     $this->assertTrue($pdf2 instanceof Pdf\PdfDocument);
     $this->assertEquals($srcPageCount, count($pdf2->pages));
     unset($pdf2);
     unlink(__DIR__ . '/_files/output.pdf');
 }
Пример #14
0
 public function testNewPageCreator()
 {
     $pdf = new Pdf\PdfDocument();
     $page = $pdf->newPage(Pdf\Page::SIZE_A4);
     $this->assertTrue($page instanceof Pdf\Page);
 }
Пример #15
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);
 }
Пример #16
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 ]');
 }
Пример #17
0
 /**
  * Object constructor
  *
  * @param string $val
  */
 public function __construct($val)
 {
     $this->value = Pdf\PdfDocument::getMemoryManager()->create($val);
 }
Пример #18
0
/**
 * @param string $content
 * @return \ZendPdf\PdfDocument
 */
function pdfFromContent($content)
{
    return PdfDocument::parse($content);
}
Пример #19
0
 private function createPdfFile($filePath, $contents)
 {
     $pdf = new PdfDocument();
     $page = new Page(Page::SIZE_A4);
     $font = Font::fontWithName(Font::FONT_HELVETICA);
     $page->setFont($font, 18);
     $page->drawText($contents, 50, 780);
     $pdf->pages[] = $page;
     $pdf->save($filePath);
 }
Пример #20
0
 /**
  * Draw the barcode in the PDF, send headers and the PDF
  * @return mixed
  */
 public function render()
 {
     $this->draw();
     header("Content-Type: application/pdf");
     echo $this->resource->render();
 }
Пример #21
0
 private function generatePdf(Invoice $invoice)
 {
     $pdf = new PdfDocument();
     // Add new page generated by ZendPdf\Page object
     $page1 = new Page(Page::SIZE_A4);
     $pdf->pages[] = $page1;
     // Load the needed fonts
     $fontHelvetica = Font::fontWithName(Font::FONT_HELVETICA);
     $fontHelveticaBold = Font::fontWithName(Font::FONT_HELVETICA_BOLD);
     $fontTimes = Font::fontWithName(Font::FONT_TIMES);
     $fontTimesBold = Font::fontWithName(Font::FONT_TIMES_BOLD);
     $colorWhite = new \ZendPdf\Color\GrayScale(1);
     $colorBlack = new \ZendPdf\Color\GrayScale(0);
     $pdf->properties['Author'] = 'Marinvägen IT';
     $pdf->properties['Creator'] = 'Marinvägen IT';
     $pdf->properties['Title'] = 'Invoice';
     $pdf->properties['Subject'] = 'Invoice';
     $page1->setFillColor($colorWhite)->setLineColor($colorBlack)->drawRectangle(50, 747, 295, 787)->drawRectangle(300, 747, 545, 787)->drawRectangle(50, 622, 295, 742)->drawRectangle(300, 622, 545, 742)->drawRectangle(50, 95, 545, 617)->drawRectangle(50, 597, 545, 617)->drawRectangle(50, 30, 545, 90);
     // Draw header
     $page1->setFont($fontTimes, 10)->setFillColor($colorBlack)->drawText('Faktura nr', 305, 775)->drawText('Kund nr', 540 - $this->widthForStringUsingFontSize('Kund nr', $fontTimes, 10), 775)->drawText('Fakturadatum', 55, 775)->drawText('Förfallodatum', 290 - $this->widthForStringUsingFontSize('Förfallodatum', $fontTimes, 10), 775)->drawText('Fakturaadress', 305, 730)->drawText('Er referens:', 55, 730)->drawText($invoice->getClientReference(), 290 - $this->widthForStringUsingFontSize($invoice->getClientReference(), $fontTimes, 10), 730)->drawText('Vår referens:', 55, 719)->drawText($invoice->getOwnReference(), 290 - $this->widthForStringUsingFontSize($invoice->getOwnReference(), $fontTimes, 10), 719)->drawText('Betalningsvillkor:', 55, 708)->drawText($invoice->getDueDays() . ' dagar netto', 290 - $this->widthForStringUsingFontSize($invoice->getDueDays() . ' dagar netto', $fontTimes, 10), 708)->drawText('Dröjsmålsränta:', 55, 697)->drawText('9,50 %', 290 - $this->widthForStringUsingFontSize('9,50 %', $fontTimes, 10), 697)->drawText('Innehar F-skattebevis', 290 - $this->widthForStringUsingFontSize('Innehar F-skattebevis', $fontTimes, 10), 627)->drawText('Adress:', 55, 80)->drawText('Telefon:', 178, 80)->drawText('Bankgiro:', 178, 52)->drawText('E-post:', 301, 80)->drawText('Organisationsnr:', 301, 52)->drawText('Hemsida:', 424, 80)->drawText('Momsreg.nr:', 424, 52)->drawText('Netto', 125 - $this->widthForStringUsingFontSize('Netto', $fontTimes, 10), 122)->drawText('Moms kr', 330 - $this->widthForStringUsingFontSize('Moms kr', $fontTimes, 10), 122)->drawText('Avrundning', 410 - $this->widthForStringUsingFontSize('Avrundning', $fontTimes, 10), 122);
     // Footer texts
     $page1->setFont($fontTimes, 12)->setFillColor($colorBlack)->drawText($this->settingTable->getSettingByName('CompanyName'), 55, 68)->drawText($this->settingTable->getSettingByName('CompanyAddress'), 55, 56)->drawText($this->settingTable->getSettingByName('CompanyPostAddress'), 55, 44)->drawText($this->settingTable->getSettingByName('CompanyCellphone'), 178, 68)->drawText($this->settingTable->getSettingByName('CompanyBankGiro'), 178, 40)->drawText($this->settingTable->getSettingByName('CompanyEmail'), 301, 68)->drawText($this->settingTable->getSettingByName('CompanyRegistrationNumber'), 301, 40)->drawText($this->settingTable->getSettingByName('CompanyWebpage'), 424, 68)->drawText($this->settingTable->getSettingByName('CompanyVATNumber'), 424, 40);
     // Invoice headers
     $page1->setFont($fontTimes, 14)->setFillColor($colorBlack)->drawText('Benämning', 55, 603)->drawText('Antal', 350 - $this->widthForStringUsingFontSize('Antal', $fontTimes, 14), 603)->drawText('á-pris', 450 - $this->widthForStringUsingFontSize('á-pris', $fontTimes, 14), 603)->drawText('Summa', 540 - $this->widthForStringUsingFontSize('Summa', $fontTimes, 14), 603);
     // Invoice summary text
     $page1->setFont($fontTimes, 16)->setFillColor($colorBlack)->drawText('ATT BETALA', 540 - $this->widthForStringUsingFontSize('ATT BETALA', $fontTimes, 16), 126)->drawText($invoice->getNumber(), 310, 755)->drawText($invoice->getClientId(), 535 - $this->widthForStringUsingFontSize($invoice->getClientId(), $fontTimes, 16), 755)->drawText(date("Y-m-d", strtotime($invoice->getBaseDate())), 60, 755)->drawText(date("Y-m-d", strtotime($invoice->getBaseDate() . ' +' . $invoice->getDueDays() . ' days')), 285 - $this->widthForStringUsingFontSize($invoice->getBaseDate(), $fontTimes, 16), 755);
     // Draw header
     $page1->setFont($fontTimes, 22)->setFillColor($colorBlack)->drawText('Faktura', 478, 792);
     // Draw company name
     $page1->setFont($fontHelveticaBold, 32)->setFillColor($colorBlack)->drawText($this->settingTable->getSettingByName('CompanyName'), 50, 792);
     $intPosition = 582;
     $intTotalSum = 0;
     $intTotalVat = 0;
     $intTotalSumWithVat = 0;
     foreach ($invoice->getRows() as $row) {
         $intRowPrice = number_format($row->getPrice(), 2, ',', ' ');
         $intRowSum = number_format($row->getQuantity() * $row->getPrice(), 2, ',', ' ');
         $intTotalSum = $intTotalSum + $row->getQuantity() * $row->getPrice();
         $intTotalVat = $intTotalVat + $row->getQuantity() * $row->getPrice() * ($row->getVat() / 100);
         $page1->setFont($fontTimes, 12)->setFillColor($colorBlack)->drawText($row->getText(), 55, $intPosition)->drawText($row->getQuantity(), 350 - $this->widthForStringUsingFontSize($row->getQuantity(), $fontTimes, 12), $intPosition)->drawText($intRowPrice, 450 - $this->widthForStringUsingFontSize($intRowPrice, $fontTimes, 12), $intPosition)->drawText($intRowSum, 540 - $this->widthForStringUsingFontSize($intRowSum, $fontTimes, 12), $intPosition);
         $intPosition = $intPosition - 14;
     }
     $intTotalSumWithVat = $intTotalSum + $intTotalVat;
     $intRound = round($intTotalSumWithVat) - $intTotalSumWithVat;
     $intTotalSumWithVat = $intTotalSumWithVat + $intRound;
     $intTotalSum = number_format($intTotalSum, 2, ',', ' ');
     $intTotalVat = number_format($intTotalVat, 2, ',', ' ');
     $intRound = number_format($intRound, 2, ',', ' ');
     $intTotalSumWithVat = number_format($intTotalSumWithVat, 2, ',', ' ');
     $page1->setFont($fontTimes, 12)->setFillColor($colorBlack)->drawText($intTotalSum, 125 - $this->widthForStringUsingFontSize($intTotalSum, $fontTimes, 12), 110)->drawText($intTotalVat, 330 - $this->widthForStringUsingFontSize($intTotalVat, $fontTimes, 12), 110)->drawText($intRound, 410 - $this->widthForStringUsingFontSize($intRound, $fontTimes, 12), 110);
     $page1->setFont($fontTimes, 16)->setFillColor($colorBlack)->drawText($intTotalSumWithVat, 540 - $this->widthForStringUsingFontSize($intTotalSumWithVat, $fontTimes, 16), 110);
     // Draw address
     $intAddressPosition = 710;
     foreach (explode(';', $invoice->getAddress()) as $part) {
         $page1->setFont($fontTimes, 16)->setFillColor($colorBlack)->drawText($part, 315, $intAddressPosition);
         $intAddressPosition = $intAddressPosition - 20;
     }
     try {
         $pdf->save('data/invoice/invoice-' . sprintf('%06d', $invoice->getNumber()) . '.pdf');
     } catch (\ZendPdf\Exception\IOException $e) {
         throw $e;
     }
 }
Пример #22
0
 /**
  * Test capture request saves file to
  * disk with correct orientation.
  *
  * @access public
  * @return void
  */
 public function testPdfRequestSavesFileToDiskWithCorrectOrientation()
 {
     $this->filename = 'test.pdf';
     $file = $this->directory . '/' . $this->filename;
     $client = $this->getClient();
     $request = $client->getMessageFactory()->createPdfRequest();
     $response = $client->getMessageFactory()->createResponse();
     $request->setMethod('GET');
     $request->setUrl('http://jonnyw.kiwi/tests/test-capture.php');
     $request->setOutputFile($file);
     $request->setFormat('A4');
     $request->setOrientation('landscape');
     $request->setMargin('0cm');
     $client->send($request, $response);
     $pdf = \ZendPdf\PdfDocument::load($file);
     $pdfWidth = round($pdf->pages[0]->getWidth() * 0.0352777778);
     $pdfHeight = round($pdf->pages[0]->getHeight() * 0.0352777778);
     $this->assertEquals(30, $pdfWidth);
     $this->assertEquals(21, $pdfHeight);
 }
Пример #23
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)");
}
Пример #24
0
 *
 * @category Default
 * @package  None
 * @author   Kei Nakayama <*****@*****.**>
 * @license  MIT https://opensource.org/licenses/MIT
 * @link     None
 */
require_once __DIR__ . "/../vendor/autoload.php";
use ZendPdf\PdfDocument;
if (count($argv) < 3) {
    echo "USAGE: php {$argv['0']} " . "<pdf_file1> <pdf_file2> [<pdf_file3> [...]] <output_pdf_file>" . PHP_EOL;
    exit;
}
$pdfs = [];
for ($i = 1; $i <= count($argv) - 2; $i++) {
    echo "loading: " . $argv[$i] . PHP_EOL;
    $pdfs[] = PdfDocument::load($argv[$i]);
    echo "loaded: " . $argv[$i] . PHP_EOL;
}
$outPdfFn = $argv[count($argv) - 1];
echo "creating: " . $outPdfFn . PHP_EOL;
$outPdf = new PdfDocument();
foreach ($pdfs as $pdf) {
    foreach ($pdf->pages as $page) {
        $outPdf->pages[] = clone $page;
    }
}
echo "saving: " . $outPdfFn . PHP_EOL;
$outPdf->save($outPdfFn);
echo "created: " . $outPdfFn . PHP_EOL;
exit;
Пример #25
0
 /**
  * @group ZF-8462
  */
 public function testPhpVersionBug()
 {
     $this->setExpectedException('\\ZendPdf\\Exception\\NotImplementedException', 'Cross-reference streams are not supported yet');
     $pdf = Pdf\PdfDocument::load(__DIR__ . '/_files/ZF-8462.pdf');
 }