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