How do you use Zend_Pdf to generate PDF documents?

How do you use Zend_Pdf to generate PDF documents?

 

Here are the minimal steps to use Zend_Pdf for generating PDF documents:

Minimal Steps to Use Zend_Pdf

  1. Install Zend_Pdf:

Example

composer require zendframework/zend-pdf

Create a New PDF Document:

Example

<?php
use ZendPdf\PdfDocument;
use ZendPdf\Page;

$pdf = new PdfDocument();
$page = new Page(Page::SIZE_A4);
$pdf->pages[] = $page;
?>

Add Text:

Example

<?php
$font = Font::fontWithName(Font::FONT_HELVETICA);
$page->setFont($font, 12);
$page->drawText('Hello, World!', 72, 720);
?>

Save the PDF Document:

Example

<?php
$pdf->save('path/to/document.pdf');
?>

(Optional) Stream PDF to Browser:

Example

<?php
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="document.pdf"');
readfile('path/to/document.pdf');
?>

Related Questions & Topics

Powered and designed by igetvapeaustore.com | © 2024 codestap.com.