<?xml version="1.0" encoding="utf-8"?>
<mx:Application  xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:mh="mh.components.*"
     viewSourceURL="srcview/index.html">

    <mx:Style source="styles/obsidian/obsidian.css" />
    <mx:Script>
        <![CDATA[
            import org.alivepdf.pdf.PDF;
            import org.alivepdf.layout.Orientation;
            import org.alivepdf.layout.Size;
            import org.alivepdf.layout.Unit;
            import org.alivepdf.display.Display;
            import org.alivepdf.saving.Method;
            import org.alivepdf.fonts.FontFamily;
            import org.alivepdf.fonts.Style;
            import org.alivepdf.colors.RGBColor;
            
            private var myPDF:PDF;

            function generatePDF ( e:MouseEvent )
            {
                // we create the PDF
                myPDF = new PDF(  Orientation.LANDSCAPE, Unit.MM, Size.LETTER );
                // we set the zoom to 100%
                myPDF.setDisplayMode ( Display.FULL_WIDTH ); 
                
        
                // we add a page
                myPDF.addPage();
                myPDF.addImage(dc_main);
                
                // to save the PDF your specificy the path to the create.php script
                // alivepdf takes care of the rest, if you are using AIR and want to save the PDF locally just use Method.LOCAL
                // and save the returned bytes on the disk through the FileStream class
            /**///myPDF.save( Method.REMOTE, "http://alivepdf.bytearray.org/wp-content/demos/create.php", "drawing.pdf" );
                
                /***** MODIFICACIONES DON KENSHIN ***********/
                // se crea una variable ByteArray para almacenar el archivo PDF que devuelve el metodo
                // save() de la libreria AlivePDF, en forma de arreglo de bytes.
                var bytes : ByteArray = myPDF.save(Method.LOCAL);
                // se crea una variable FileReference para poder acceder a disco mediante un cuadro de 
                // dialogo del sistema operativo.
                var fileRefer : FileReference = new FileReference();
                // se abre el dialogo de "guardar como" del sistema operativo.
                fileRefer.save(bytes,"garabatoRIA212.pdf");
                /********************************************/
                
                /////fileRefer.browse();
            }
        ]]>
    </mx:Script>
        <mx:Button horizontalCenter="0" click="generatePDF(event)" label="Generate PDF" id="generate_btn" />
        
        <mx:Panel layout="absolute" title="Draw On Me" backgroundColor="#ffffff" borderThicknessBottom="10" left="20" right="20" top="20" bottom="20">
            <mx:Canvas x="0" y="0" width="100%" height="100%" backgroundColor="#ffffff">
                <mh:DrawableCanvas id="dc_main" backgroundColor="#ffff80" backgroundAlpha="0" width="100%" height="100%" y="0" x="0">
                </mh:DrawableCanvas>
            </mx:Canvas>
            
        </mx:Panel>
</mx:Application>










    <!-- El presente ejemplo con fines ilustrativos y educacionales se realizo inspirado en el 
         codigo fuente publicado en el blog Flex Examples en la siguiente direccion web:
         http://blog.flexexamples.com/2007/10/05/creating-view-states-in-a-flex-application/ 
         por Juan Manrique. http://groups.google.com/group/flex-air-ve -->