Thursday, August 25, 2011

Using AlivePDF to export PDF in Flex

I have recently been working with AlivePDF for exporting UIComponents into PDF and liked it very much. It is a simple tool, easy to use. A small code snippet

private function exportToPDF(uiComponent:IUIComponent):void

function callOnComplete(event:Event):void
if(onComplete != null), event);
_fileReference.removeEventListener(Event.COMPLETE, callOnComplete);
function callOnCancel(event:Event):void
if(onCancel != null), event);
_fileReference.removeEventListener(Event.CANCEL, callOnCancel);

var pdfEncoder:PDF = new PDF(Orientation.PORTRAIT, Unit.MM, Size.A4);
pdfEncoder.addImage(uiComponent as DisplayObject, 
                        new Resize("FitToPage", Position.LEFT));

var bytes:ByteArray =;, (fileName + ".pdf"));

I am assuming that we are using Flash 10. For player below that version, FileReference would not work. You'd need to do a server side implementation to download the PDF.

If anyone has any questions, please feel free to ask.

No comments :