Example #1
0
 /**
  * @param null $fileName
  * @return void|string
  */
 public function output($fileName = null)
 {
     if ($fileName !== null) {
         $this->pdf->save($fileName);
         return;
     }
     return $this->pdf->render();
 }
 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;
 }
 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);
 }
Example #4
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();
 }
Example #5
0
$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>
</ul>', 30, 530, 330, 30);
$pdf->pages[] = $page;
$pdfContent = $pdf->render();
header("HTTP/1.0 200 OK");
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="downloaded.pdf"');
header('Content-Length: ' . strlen($pdfContent));
print $pdfContent;
 /**
  * @{inheritDoc}
  */
 public function render()
 {
     return $this->pdf->render();
 }
Example #7
0
 /**
  * Fetches the buffer containing the generated PDF data.
  * 
  * @return string
  */
 public function get_buffer()
 {
     return $this->_zpdf->render();
 }