Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Dynamic PDFs with Zend Framework and Java Bridge


Published on

Existing methods of PDF generation can be cumbersome and/or time consuming. However, this does not need to be the case. With the help of Zend Framework and Zend Java Bridge this presentation will demonstrate how to use simple templating to generate PDF documents as easily as you would produce HTML.

Published in: Technology
  • D0WNL0AD FULL ▶ ▶ ▶ ▶ ◀ ◀ ◀ ◀
    Are you sure you want to  Yes  No
    Your message goes here

Dynamic PDFs with Zend Framework and Java Bridge

  1. 1. Generating Dynamic PDFs Using Zend Framework and Zend Java Bridge By Eric Ritchie
  2. 2. <ul><li>Senior Technical Consultant and Trainer at Zend Technologies </li></ul><ul><li>Zend Framework and PHP 5 ZCE </li></ul><ul><li>Fifteen years of system administration experience </li></ul><ul><li>Ten years of PHP (3,4 & 5) and four years Zend Framework development experience </li></ul><ul><li>Hobbies: Sampling good wines/whiskies (gifts welcome) </li></ul>Eric Ritchie bids you welcome !
  3. 3. What do we want to achieve? <ul><li>Template based PDF generation </li></ul><ul><li>Assumption: </li></ul><ul><ul><li>You know a little about Zend Framework. </li></ul></ul><ul><ul><li>If this is a bad assumption raise your hand  </li></ul></ul>| Feb 10, 2010 |
  4. 4. Other (historic?) methods of PDF generation <ul><li>Many options… </li></ul><ul><ul><li>PDFlib (PECL component) </li></ul></ul><ul><ul><li>Zend_Pdf (Zend Framework component) </li></ul></ul><ul><ul><li>HTML2PDF </li></ul></ul><ul><ul><li>Others… </li></ul></ul><ul><li>… but somehow not quite right </li></ul><ul><ul><li>Either complex to use </li></ul></ul><ul><ul><li>Or not flexible enough </li></ul></ul>| Feb 10, 2010 |
  5. 5. A better way: Apache FOP <ul><li>Many advantages </li></ul><ul><ul><li>FO: Printing industry standard </li></ul></ul><ul><ul><li>HTML like syntax </li></ul></ul><ul><ul><li>Very powerful </li></ul></ul><ul><ul><li>Details of PDF generation are hidden from the user. </li></ul></ul><ul><li>The catch? </li></ul><ul><ul><li>FO format is a bit touchy: The price of power </li></ul></ul><ul><ul><li>The J word: Java </li></ul></ul><ul><ul><li>Work in progress: Not feature complete (yet) </li></ul></ul>| Feb 10, 2010 |
  6. 6. A better way: Apache FOP <ul><li>What catch? There is no catch! </li></ul><ul><ul><li>Use a template engine </li></ul></ul><ul><ul><li>Use Zend Java Bridge </li></ul></ul><ul><li>How do we put this together…? </li></ul>| Feb 10, 2010 |
  7. 7. Zend Server | Feb 10, 2010 | <ul><li>Complete, well-tested PHP stack – PHP, Zend Framework, debugging extension, Java Bridge and more </li></ul><ul><li>A free community edition and a commercial edition – both are production-ready </li></ul><ul><li>Application monitoring and diagnostics (integrated with Zend Studio) </li></ul><ul><li>Multi-level performance enhancement capabilities </li></ul><ul><li>Software updates and security hot fixes </li></ul><ul><li>Easy and quick installation </li></ul>
  8. 8. Why Java Bridge? <ul><li>Easy to use </li></ul><ul><li>Transparently integrates Java objects into PHP projects </li></ul><ul><li>High performance </li></ul><ul><li>Free! </li></ul>| Feb 10, 2010 |
  9. 9. Why Zend Framework? <ul><li>Popular implementation of MVC </li></ul><ul><li>Lightweight templating engine </li></ul><ul><li>Easily extendable </li></ul><ul><li>Free! </li></ul>| Feb 10, 2010 |
  10. 10. Zend_View: The V in MVC <ul><li>Zend_View is a component class of Zend Framework for working with the “View” portion of the MVC design pattern </li></ul><ul><li>It provides a system of helpers, output filters, and variable escaping </li></ul><ul><li>Zend_View is not tied to one template system - it can utilize PHP templates or other systems, manipulated through the view script </li></ul>| Feb 10, 2010 |
  11. 11. Zend_View: The V in MVC <ul><li>But Zend_View works with HTML, right? </li></ul><ul><ul><li>Yes, by default, but we can bend it to our will! </li></ul></ul><ul><ul><li>Time to create a class: </li></ul></ul>| Feb 10, 2010 |
  12. 12. Zend_View_FO2PDF: Continued | Feb 10, 2010 |
  13. 13. Zend_View_FO2PDF: Continued | Feb 10, 2010 |
  14. 14. Zend_View_FO2PDF: Java Bridge call <ul><li>Could not be easier… </li></ul><ul><ul><li>Create an instance of our Java class in PHP </li></ul></ul><ul><ul><li>Then use it by calling class methods </li></ul></ul><ul><ul><li>Only two lines of code! </li></ul></ul>| Feb 10, 2010 |
  15. 15. The dark side: Our Java code | Feb 10, 2010 |
  16. 16. Defining our class path <ul><li>Who said “hack”? </li></ul><ul><ul><li>Need to edit /usr/local/zend/etc/watchdog.jb </li></ul></ul>| Feb 10, 2010 |
  17. 17. Feed the view class: Write a template <ul><li>We need to write some FO (nothing offensive) </li></ul><ul><li>All features of ZF available to us </li></ul><ul><li>…but we must omit something! </li></ul><ul><li>The XML header </li></ul><ul><ul><li><?xml causes a conflict! </li></ul></ul><ul><ul><li>So we add it in the view class (did you notice?) </li></ul></ul>| Feb 10, 2010 |
  18. 18. Putting it together <ul><li>We need a controller… </li></ul>| Feb 10, 2010 |
  19. 19. … and done! | Feb 10, 2010 |
  20. 20. What next? <ul><li>The sky’s the limit </li></ul><ul><ul><li>Add tables </li></ul></ul><ul><ul><li>Add images </li></ul></ul><ul><ul><li>Add vector graphics (SVG) </li></ul></ul>| Feb 10, 2010 |
  21. 21. What next? <ul><li>But I don’t like PDFs what about me? </li></ul><ul><ul><li>You can render Excel/Word documents too </li></ul></ul><ul><ul><li>… or anything text based really </li></ul></ul><ul><ul><li>Use your imagination! </li></ul></ul>| Feb 10, 2010 |
  22. 22. Questions? | Feb 10, 2010 |
  23. 23. <ul><li>Thanks for listening! </li></ul>| Feb 10, 2010 |