I've been working a budgeting application and I've gotten to the point where everything works the way I had envisioned. But as with any financial application, you want to be able to generate printouts of the data. My task was to print a table of data (shown in a DataGrid in the app) which could span multiple pages with some header and footer information at the beginning and end. Nothing extravagant. So I charged off into the realm of how to do this.
My first attempt was using Flex PrintJob. It's easy to use, can do multiple pages, and can print tables using MXML files as the source. During the development I learned that it's easy to print tables, but not so easy to print multi-page tables with headers and footers. I found examples on how to do this but didn't feel like trying them because of a more fundamental flaw (at least in my opinion) in PrintJob. That flaw is that there is no way of doing a print preview. So I used up a good bit of ink and paper before I decided that wasn't the way to go. I did find one solution to this which was to print to a PDF printer but I thought that would be strange for a user.
My next attempt was FlexReport. That had some promise, but I ditched that when I found out it had issues with HBox layouts, the documentation seemed to be almost non-existent and it seemed like the project wasn't being actively developed.
Next I tried AlivePDF. This was probably the best I had tried, from a Flex solution. It worked well. But one quirky thing I found was when using it for a Flex web app. You end up generating the pdf in the client flex app then sending it to your server so your server can stream the bytes back to the client and show it in a new window. Yes this supports the print preview I was wanting but there didn't seem to be easy support for datagrid. It looked to me like I would need to draw the tables out that I wanted to print.
Finally, even though AlivePDF was adequate for my needs, I didn't like the idea of having to draw the tables by hand (with lineto methods and such) and since I was going to have to hit the server anyway, why not use a server side solution. Since my server was Ruby based, and I had used a Ruby server based PDF renderer before (PDF::Writer). I chose that as my solution. The one thing I don't like about this solution is I have to duplicate the data manipulation code that is on the client used to provide the data to the tables on the server.
I guess my final comment is the Flex environment seems to be a mess when it comes to printing support. Being new to Flex I find this very odd and disappointing. I wonder if Flex 4 will help close this hole?
No comments:
Post a Comment