Its been a long time , that I have posted anything on this blog. Recently , while working on a design application, came across requirment which needed to generate a PDF from my flex application.
Was looking for a neat solution. As the technology is so much evolved , was hoping to find one, which does not include too much of sever side interaction , (using java tools like jasper and IText) .
And Alive PDF is the solution(http://alivepdf.bytearray.org/) . Very very nicely done.
It made the task too easy. It has multiple apis and a very good level of abstraction.
Although its a open source, it does not require too much of digging in.
We can take the screen shot of any UI component in our application , convert it to image using any encoder (pngEncoder or jpegEncoder , which is now included in the graphics.codec package of mx in 3.2 sdk of flex) and the use the bytearray returned by these encoders to insert in pdf using "addImageStream" method of the PDF class.
here is how you can do,
1) add AlivePDF.swc from AlivePDF to build path of the flex project, or directly use source
2) var myPDF:PDF = new PDF( Orientation.PORTRAIT, Unit.MM, Size.A4 ); // can add multiple pages and also can clone pages.
3) there are apis to draw in pdf, write text in pdf.
and finally, save.
4) save can be done in AIR, by file class or use filereferance class to save on server.
5) if we are using flash player 10, filereferance can be used to save locally.
to use "save" method of filereferance class , do this:
use 3.2 sdk and write this in compiler option : -target-player = 10;
For more details visit : http://alivepdf.bytearray.org/ , they have good video tutorials and source file too