SlideShare a Scribd company logo
Dennis De Cock
PHPBenelux meeting, 2010, Houthalen
About me
 Independent consultant
 Owner of DE COCK ICT, company specialized in PHP / ZF / Drupal
development
Sponsors
About this presentation
 The intro
 Requirements
 Creating and loading
 Saving
 Working with pages
 Page sizes
 Duplication and cloning
 Colors & fonts
 Text & image drawing
 Styles
 Advanced topics
Zend_PDF: the intro
 Create or load pdf files
 Manipulate pages within documents, reorder, delete, and so on…
 Drawing possibilities for shapes, lines, …)
 Drawing of text using 14 built-in fonts or use own TrueType Fonts
 Image drawing (JPG, PNG [Up to 8bit per channel+Alpha] and TIFF images
are supported)
Requirements
 Zend_PDF is a component that can be found in the standard Zend library
 Latest Zend library available from http://framework.zend.com/download/latest
Folder structure
How to integrate
 Use the autoloader for automatic load of the module when needed (or load it
yourself without ) :
protected function _initAutoload() {
$moduleLoader = new Zend_Application_Module_Autoloader(
array(
'namespace' => ‘demo',
'basePath' => APPLICATION_PATH
)
);
return $moduleLoader;
}
Creating and loading
 One way to create a new pdf document:
 Two ways to load an existing document:
 Load it from a file:
 Load it from a string:
$pdf = new Zend_Pdf();
$pdf = Zend_Pdf::load($fileName);
$pdf = Zend_Pdf::parse($pdfString);
Saving
 Save a pdf document as a file:
 Update an existing file by using true as second parameter:
 You can also render the pdf to a string (example for passing through http)
$pdf->save(‘demo.pdf');
$pdf->save(‘demo.pdf‘, true);
$pdfData = $pdf->render();
Working with pages
 Add a page to an existing file:
 Remove a page from an existing file:
 Reverse page order:
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
$pdf->pages[] = $page;
unset($pdf->pages[$id]);
$pdf->pages = array_reverse($pdf->pages);
Page sizes, some possibilities
 Specify a specific size:
Some other possibilities are:
 Use x and y coords to define your page:
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
$pdf->pages[] = $page;
$page = $pdf->newPage(200, 400);
$pdf->pages[] = $page;
Zend_Pdf_Page::SIZE_A4_LANDSCAPE
Zend_Pdf_Page::SIZE_LETTER
Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE
Page sizes, some possibilities
 Get the height and width from a pdf page:
$page = $pdf->pages[$id];
$width = $page->getWidth();
$height = $page->getHeight();
Duplicating pages
 Duplicate a page from a pdf document to create pages faster
 Duplicated pages share resources from the template page so you can only duplicate
within the same file
// Store template page in a separate variable
$template = $pdf->pages[$templatePageIndex];
// Add new page
$page1 = new Zend_Pdf_Page($template);
$page1->drawText('Some text...', $x, $y);
$pdf->pages[] = $page1;
Cloning pages
 Clone a page from any document. PDF resources are copied, so you are
not bound to the same document.
$page1 = clone $pdf1->pages[$templatePageIndex1];
$page2 = clone $pdf2->pages[$templatePageIndex2];
$page1->drawText('Some text...', $x, $y);
$page2->drawText('Another text...', $x, $y);
$pdf = new Zend_Pdf();
$pdf->pages[] = $page1;
$pdf->pages[] = $page2;
Colors
 Zend_Pdf_Color supports grayscale, rgb and cmyk
 Html style colors are also supported through Zend_Pdf_Color_Html
// $grayLevel (float number). 0.0 (black) - 1.0 (white)
$color1 = new Zend_Pdf_Color_GrayScale($grayLevel);
// $r, $g, $b (float numbers). 0.0 (min intensity) - 1.0 (max intensity)
$color2 = new Zend_Pdf_Color_Rgb($r, $g, $b);
// $c, $m, $y, $k (float numbers). 0.0 (min intensity) - 1.0 (max intensity)
$color3 = new Zend_Pdf_Color_Cmyk($c, $m, $y, $k);
$color1 = new Zend_Pdf_Color_Html('#3366FF');
Fonts at your disposal
 Specify a font to use:
Some other possibilities are:
$page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA),
12);
Zend_Pdf_Font::FONT_COURIER
Zend_Pdf_Font::FONT_COURIER_BOLD
Zend_Pdf_Font::FONT_COURIER_ITALIC
Zend_Pdf_Font::FONT_COURIER_BOLD_ITALIC
Zend_Pdf_Font::FONT_TIMES
Zend_Pdf_Font::FONT_TIMES_BOLD
Zend_Pdf_Font::FONT_TIMES_ITALIC
Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC
Zend_Pdf_Font::FONT_HELVETICA
Zend_Pdf_Font::FONT_HELVETICA_BOLD
Zend_Pdf_Font::FONT_HELVETICA_ITALIC
Zend_Pdf_Font::FONT_HELVETICA_BOLD_ITALIC
Zend_Pdf_Font::FONT_SYMBOL
Zend_Pdf_Font::FONT_ZAPFDINGBATS
Use your own fonts
 Only truetype fonts can be used, create the font:
 Then use the font on the page:
$myFont = Zend_Pdf_Font::fontWithPath('/path/to/my/special/font__.TTF');
$page->setFont($myFont, 12);
An error with a custom font?
 Errors can arise with embedding the font into the file or compressing the font.
 You can use the following options to handle these errors:
 Zend_Pdf_Font::EMBED_DONT_EMBED
Do not embed the font
 Zend_Pdf_Font::EMBED_SUPPRESS_EMBED_EXCEPTION
Do not throw the error
 Zend_Pdf_Font::EMBED_DONT_COMPRESS
Do not compress
 You can combine the above options to match your specific solution.
Adding text to the page
 Function drawtext needs 3 parameters
drawText($text, $x, $y);
 Optional you can specify character encoding as fourth parameter:
drawText($text, $x, $y, $charEncoding = ‘’);
 Example:
$page->drawText('Hello world!', 50, 600 );
Adding shapes to the page
 Different possibilities for shape drawing:
 drawLine($x1, $y1, $x2, $y2)
 drawRectangle($x1, $y1, $x2, $y2,
$fillType =
Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE)
 drawRoundedRectangle($x1, $y1, $x2, $y2, $radius,
$fillType =
Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE)
 drawPolygon($x, $y, $fillType =
Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE,
$fillMethod =
Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING)
 drawCircle($x, $y, $radius, $param4 = null, $param5 = null, $param6 = null)
Adding images to the page
 JPG, PNG and TIFF images are now supported
 An example:
// Load the image
$image = Zend_Pdf_Image::imageWithPath(APPLICATION_FRONT .
'/images/logo.tif');
// Draw image
$page->drawImage($image, 40, 764, 240, 820);
// -> $image, $left, $bottom, $right, $top
An example in detail
 Here’s a more complete example and the result:
$pdf = new Zend_Pdf();
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
$pdf->pages[] = $page;
$page->setFont(Zend_Pdf_Font::fontWithName(
Zend_Pdf_Font::FONT_HELVETICA), 12);
$page->drawText('Hello world!', 50, 600 );
$image = Zend_Pdf_Image::imageWithPath(APPLICATION_FRONT .
'/images/logo.tif');
$page->drawImage($image, 40, 764, 240, 820);
$page->drawLine(50, 755, 545, 755);
$pdf->save('demo.pdf');
The result
Using styles
 Create styles to combine your own specific layout of pdf in one place:
 After creating the style, add some elements to your style
 Apply the style
$mystyle = new Zend_Pdf_Style();
$mystyle->setFont(Zend_Pdf_Font::fontWithName(
Zend_Pdf_Font::FONT_HELVETICA), 12);
$mystyle->Zend_Pdf_Color_Rgb(1, 1, 0));
$mystyle->setLineWidth(1);
$page1->setStyle($mystyle);
Document info
 Add information to your document through the properties:
$pdf = Zend_Pdf::load($pdfPath);
echo $pdf->properties[‘Demo'] . "n";
echo $pdf->properties[‘Dennis'] . "n";
$pdf->properties['Title'] = ‘Demo';
$pdf->save($pdfPath);
Advanced topics
 Zend_Pdf_Resource_Extractor class for cloning pages and share resources
through the different templates
 Linear transformations, most of them are available as from ZF 1,8
(skew, scale, …)
Summary
 Zend_PDF has powerful capabilities
 Combining the extended pdf class on framework.zend.com makes life a little
easier
Recommended reading
http://devzone.zend.com/article/2525
Zend_PDF tutorial by Cal Evans
Thank you!
Questions?

More Related Content

What's hot (20)

PDF
Tenedis: Déployer un socle de Monitoring Unifié
Elasticsearch
 
PDF
Data wrangling week2
Ferdin Joe John Joseph PhD
 
PPTX
Python Data Structures and Algorithms.pptx
ShreyasLawand
 
PDF
Py.test
soasme
 
PPTX
시스템 프로그램 설계1 최종발표
Jeongmin Cha
 
PDF
Python Generators
Akshar Raaj
 
PDF
Natural Language Processing (NLP) & Text Mining Tutorial Using NLTK | NLP Tra...
Edureka!
 
PPTX
Project of data structure
Umme habiba
 
PDF
Ontologies
Mani Kumar
 
PPT
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
PDF
Python Memory Management 101(Europython)
Jose Manuel Ortega Candel
 
PDF
Python For Data Analysis | Python Pandas Tutorial | Learn Python | Python Tra...
Edureka!
 
PDF
Data Visualization in Python
Jagriti Goswami
 
PPTX
Visual regression with applitools eyes
Shama Ugale
 
PDF
Unsafe Java
Misha Kozik
 
PPT
Amortized analysis
ajmalcs
 
PDF
RESEARCH in software engineering
Ivano Malavolta
 
PDF
Practical Natural Language Processing From Theory to Industrial Applications
Jaganadh Gopinadhan
 
PPTX
Binary Search Tree
Abhishek L.R
 
PPTX
The Art of Clean code
Victor Rentea
 
Tenedis: Déployer un socle de Monitoring Unifié
Elasticsearch
 
Data wrangling week2
Ferdin Joe John Joseph PhD
 
Python Data Structures and Algorithms.pptx
ShreyasLawand
 
Py.test
soasme
 
시스템 프로그램 설계1 최종발표
Jeongmin Cha
 
Python Generators
Akshar Raaj
 
Natural Language Processing (NLP) & Text Mining Tutorial Using NLTK | NLP Tra...
Edureka!
 
Project of data structure
Umme habiba
 
Ontologies
Mani Kumar
 
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
Python Memory Management 101(Europython)
Jose Manuel Ortega Candel
 
Python For Data Analysis | Python Pandas Tutorial | Learn Python | Python Tra...
Edureka!
 
Data Visualization in Python
Jagriti Goswami
 
Visual regression with applitools eyes
Shama Ugale
 
Unsafe Java
Misha Kozik
 
Amortized analysis
ajmalcs
 
RESEARCH in software engineering
Ivano Malavolta
 
Practical Natural Language Processing From Theory to Industrial Applications
Jaganadh Gopinadhan
 
Binary Search Tree
Abhishek L.R
 
The Art of Clean code
Victor Rentea
 

Similar to Introduction to Zend_Pdf (20)

PPT
Zend framework 06 - zend config, pdf, i18n, l10n, sessions
Tricode (part of Dept)
 
PPTX
ZFConf 2012: Реализация доступа к СУБД IBM DB2 посредством встраиваемого SQL ...
ZFConf Conference
 
PPT
Zend_Tool: Rapid Application Development with Zend Framework
Ralph Schindler
 
KEY
Zend Code in ZF 2.0
Ralph Schindler
 
PPT
Introduction to FPDF - DC PHP
Jeremy Curcio
 
PDF
ZF2 Presentation @PHP Tour 2011 in Lille
Zend by Rogue Wave Software
 
PPT
Pdf Presentation Final
amheling
 
PPT
Introduction to FPDF
Jeremy Curcio
 
PPTX
MVC Frameworks for building PHP Web Applications
Vforce Infotech
 
PPT
green
alind tiwari
 
PPT
Greenathan
alind tiwari
 
PPT
Greenathan
alind tiwari
 
PPT
latest slide
alind tiwari
 
PPT
latest slide
alind tiwari
 
PPT
dfgdfgf
alind tiwari
 
PPT
latest slide
alind tiwari
 
PPT
Unit Test for ZF SlideShare Component
zftalk
 
PPT
Unit Test for ZF SlideShare Component
zftalk
 
PPT
Unit Test for ZF SlideShare Component
zftalk
 
PPT
test
alind tiwari
 
Zend framework 06 - zend config, pdf, i18n, l10n, sessions
Tricode (part of Dept)
 
ZFConf 2012: Реализация доступа к СУБД IBM DB2 посредством встраиваемого SQL ...
ZFConf Conference
 
Zend_Tool: Rapid Application Development with Zend Framework
Ralph Schindler
 
Zend Code in ZF 2.0
Ralph Schindler
 
Introduction to FPDF - DC PHP
Jeremy Curcio
 
ZF2 Presentation @PHP Tour 2011 in Lille
Zend by Rogue Wave Software
 
Pdf Presentation Final
amheling
 
Introduction to FPDF
Jeremy Curcio
 
MVC Frameworks for building PHP Web Applications
Vforce Infotech
 
Greenathan
alind tiwari
 
Greenathan
alind tiwari
 
latest slide
alind tiwari
 
latest slide
alind tiwari
 
dfgdfgf
alind tiwari
 
latest slide
alind tiwari
 
Unit Test for ZF SlideShare Component
zftalk
 
Unit Test for ZF SlideShare Component
zftalk
 
Unit Test for ZF SlideShare Component
zftalk
 
Ad

Recently uploaded (20)

PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
PPTX
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
PDF
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PDF
Next level data operations using Power Automate magic
Andries den Haan
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
Practical Applications of AI in Local Government
OnBoard
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Next level data operations using Power Automate magic
Andries den Haan
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
Ad

Introduction to Zend_Pdf

  • 1. Dennis De Cock PHPBenelux meeting, 2010, Houthalen
  • 2. About me  Independent consultant  Owner of DE COCK ICT, company specialized in PHP / ZF / Drupal development
  • 4. About this presentation  The intro  Requirements  Creating and loading  Saving  Working with pages  Page sizes  Duplication and cloning  Colors & fonts  Text & image drawing  Styles  Advanced topics
  • 5. Zend_PDF: the intro  Create or load pdf files  Manipulate pages within documents, reorder, delete, and so on…  Drawing possibilities for shapes, lines, …)  Drawing of text using 14 built-in fonts or use own TrueType Fonts  Image drawing (JPG, PNG [Up to 8bit per channel+Alpha] and TIFF images are supported)
  • 6. Requirements  Zend_PDF is a component that can be found in the standard Zend library  Latest Zend library available from http://framework.zend.com/download/latest
  • 8. How to integrate  Use the autoloader for automatic load of the module when needed (or load it yourself without ) : protected function _initAutoload() { $moduleLoader = new Zend_Application_Module_Autoloader( array( 'namespace' => ‘demo', 'basePath' => APPLICATION_PATH ) ); return $moduleLoader; }
  • 9. Creating and loading  One way to create a new pdf document:  Two ways to load an existing document:  Load it from a file:  Load it from a string: $pdf = new Zend_Pdf(); $pdf = Zend_Pdf::load($fileName); $pdf = Zend_Pdf::parse($pdfString);
  • 10. Saving  Save a pdf document as a file:  Update an existing file by using true as second parameter:  You can also render the pdf to a string (example for passing through http) $pdf->save(‘demo.pdf'); $pdf->save(‘demo.pdf‘, true); $pdfData = $pdf->render();
  • 11. Working with pages  Add a page to an existing file:  Remove a page from an existing file:  Reverse page order: $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; unset($pdf->pages[$id]); $pdf->pages = array_reverse($pdf->pages);
  • 12. Page sizes, some possibilities  Specify a specific size: Some other possibilities are:  Use x and y coords to define your page: $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; $page = $pdf->newPage(200, 400); $pdf->pages[] = $page; Zend_Pdf_Page::SIZE_A4_LANDSCAPE Zend_Pdf_Page::SIZE_LETTER Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE
  • 13. Page sizes, some possibilities  Get the height and width from a pdf page: $page = $pdf->pages[$id]; $width = $page->getWidth(); $height = $page->getHeight();
  • 14. Duplicating pages  Duplicate a page from a pdf document to create pages faster  Duplicated pages share resources from the template page so you can only duplicate within the same file // Store template page in a separate variable $template = $pdf->pages[$templatePageIndex]; // Add new page $page1 = new Zend_Pdf_Page($template); $page1->drawText('Some text...', $x, $y); $pdf->pages[] = $page1;
  • 15. Cloning pages  Clone a page from any document. PDF resources are copied, so you are not bound to the same document. $page1 = clone $pdf1->pages[$templatePageIndex1]; $page2 = clone $pdf2->pages[$templatePageIndex2]; $page1->drawText('Some text...', $x, $y); $page2->drawText('Another text...', $x, $y); $pdf = new Zend_Pdf(); $pdf->pages[] = $page1; $pdf->pages[] = $page2;
  • 16. Colors  Zend_Pdf_Color supports grayscale, rgb and cmyk  Html style colors are also supported through Zend_Pdf_Color_Html // $grayLevel (float number). 0.0 (black) - 1.0 (white) $color1 = new Zend_Pdf_Color_GrayScale($grayLevel); // $r, $g, $b (float numbers). 0.0 (min intensity) - 1.0 (max intensity) $color2 = new Zend_Pdf_Color_Rgb($r, $g, $b); // $c, $m, $y, $k (float numbers). 0.0 (min intensity) - 1.0 (max intensity) $color3 = new Zend_Pdf_Color_Cmyk($c, $m, $y, $k); $color1 = new Zend_Pdf_Color_Html('#3366FF');
  • 17. Fonts at your disposal  Specify a font to use: Some other possibilities are: $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 12); Zend_Pdf_Font::FONT_COURIER Zend_Pdf_Font::FONT_COURIER_BOLD Zend_Pdf_Font::FONT_COURIER_ITALIC Zend_Pdf_Font::FONT_COURIER_BOLD_ITALIC Zend_Pdf_Font::FONT_TIMES Zend_Pdf_Font::FONT_TIMES_BOLD Zend_Pdf_Font::FONT_TIMES_ITALIC Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC Zend_Pdf_Font::FONT_HELVETICA Zend_Pdf_Font::FONT_HELVETICA_BOLD Zend_Pdf_Font::FONT_HELVETICA_ITALIC Zend_Pdf_Font::FONT_HELVETICA_BOLD_ITALIC Zend_Pdf_Font::FONT_SYMBOL Zend_Pdf_Font::FONT_ZAPFDINGBATS
  • 18. Use your own fonts  Only truetype fonts can be used, create the font:  Then use the font on the page: $myFont = Zend_Pdf_Font::fontWithPath('/path/to/my/special/font__.TTF'); $page->setFont($myFont, 12);
  • 19. An error with a custom font?  Errors can arise with embedding the font into the file or compressing the font.  You can use the following options to handle these errors:  Zend_Pdf_Font::EMBED_DONT_EMBED Do not embed the font  Zend_Pdf_Font::EMBED_SUPPRESS_EMBED_EXCEPTION Do not throw the error  Zend_Pdf_Font::EMBED_DONT_COMPRESS Do not compress  You can combine the above options to match your specific solution.
  • 20. Adding text to the page  Function drawtext needs 3 parameters drawText($text, $x, $y);  Optional you can specify character encoding as fourth parameter: drawText($text, $x, $y, $charEncoding = ‘’);  Example: $page->drawText('Hello world!', 50, 600 );
  • 21. Adding shapes to the page  Different possibilities for shape drawing:  drawLine($x1, $y1, $x2, $y2)  drawRectangle($x1, $y1, $x2, $y2, $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE)  drawRoundedRectangle($x1, $y1, $x2, $y2, $radius, $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE)  drawPolygon($x, $y, $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE, $fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING)  drawCircle($x, $y, $radius, $param4 = null, $param5 = null, $param6 = null)
  • 22. Adding images to the page  JPG, PNG and TIFF images are now supported  An example: // Load the image $image = Zend_Pdf_Image::imageWithPath(APPLICATION_FRONT . '/images/logo.tif'); // Draw image $page->drawImage($image, 40, 764, 240, 820); // -> $image, $left, $bottom, $right, $top
  • 23. An example in detail  Here’s a more complete example and the result: $pdf = new Zend_Pdf(); $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; $page->setFont(Zend_Pdf_Font::fontWithName( Zend_Pdf_Font::FONT_HELVETICA), 12); $page->drawText('Hello world!', 50, 600 ); $image = Zend_Pdf_Image::imageWithPath(APPLICATION_FRONT . '/images/logo.tif'); $page->drawImage($image, 40, 764, 240, 820); $page->drawLine(50, 755, 545, 755); $pdf->save('demo.pdf');
  • 25. Using styles  Create styles to combine your own specific layout of pdf in one place:  After creating the style, add some elements to your style  Apply the style $mystyle = new Zend_Pdf_Style(); $mystyle->setFont(Zend_Pdf_Font::fontWithName( Zend_Pdf_Font::FONT_HELVETICA), 12); $mystyle->Zend_Pdf_Color_Rgb(1, 1, 0)); $mystyle->setLineWidth(1); $page1->setStyle($mystyle);
  • 26. Document info  Add information to your document through the properties: $pdf = Zend_Pdf::load($pdfPath); echo $pdf->properties[‘Demo'] . "n"; echo $pdf->properties[‘Dennis'] . "n"; $pdf->properties['Title'] = ‘Demo'; $pdf->save($pdfPath);
  • 27. Advanced topics  Zend_Pdf_Resource_Extractor class for cloning pages and share resources through the different templates  Linear transformations, most of them are available as from ZF 1,8 (skew, scale, …)
  • 28. Summary  Zend_PDF has powerful capabilities  Combining the extended pdf class on framework.zend.com makes life a little easier

Editor's Notes

  • #3: Working with php for 5 years Develop webapplications and services for medium sized companies Working with zend for 1 year
  • #4: Special thanks to Inventis for the accomodation.
  • #11: $this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender();