Print your dialog box to PDF with AlivePDF without PHP or such


 I use AlivePDF (http://alivepdf.bytearray.org/) and it is really good.
Btw i had some small problem :
1 ) When i try print my dialog box, it was truncated :(
2 ) I don't want use create.php for economy of bandwidth.

After fighting with many website I found the solution, it is pretty simple !
That's the source :

            protected function btnPrint_clickHandler(event:MouseEvent):void
            {
                var printPDF:PDF = new PDF( Orientation.LANDSCAPE, Unit.MM, Size.A4 );
                printPDF.setDisplayMode( Display.FULL_PAGE, Layout.SINGLE_PAGE );
                printPDF.addPage();
                var r:Resize=new Resize(Mode.FIT_TO_PAGE,Position.CENTERED);
                var image:ImageSnapshot = ImageSnapshot.captureImage(this, 0, new
                             mx.graphics.codec.JPEGEncoder(70));
                printPDF.addImageStream(image.data,ColorSpace.DEVICE_RGB,r);
                var fileReference:FileReference=new FileReference();
                var bytes:ByteArray = printPDF.save( Method.LOCAL );
                fileReference.save(bytes,"export.pdf");
            }

Some point :

  1. I don't use addImage, because that's truncate my dialog box. And if something is on your dialog box,it will be print with your dialogbox, that's not what we want !
  2. I used JPEGEncoder : PNGEncorder don't work with alivePDF, that's sad, but because the alpha, it send an error, so i use JPEG. bit sad, because it is slow...I try to put the quality less, and put 0 for DPI for means "pixel matching"..
  3. As i use addImageStream, I need use ImageSnapshot for have my diaigog box.
  4. I use Method.LOCAL for have a ByteArray, and a FileReference (new in flash 10) for save in local, without use bandwith with the famous "create.php" i saw everywhere.

A link : http://www.kalengibbons.com/blog/index.php/2009/03/custom-printing-with-flex-part-2-generating-pdfs-with-alivepdf/ who is the begin of solution I exposed here.

JPEG encoding fast

Go go http://www.bytearray.org/?p=775 it is really good !

Problem for debugging with Flex 4.6

As many people on internet, I had problem for debugging with the new Flex.
From all my research, that's begin with flex 4.5.
After tried many time,I always have  "the version of flex debugguer is not correct".
I tried with IE, Chrome, Firefox,  I installed many time, nothing to do, that's don't work at all.
Each time I tried install debug version of flex, adobe instalelr say "you have the last one" grrrrr.


So, how to do ?
My solution is a bit strange but work very very well for me :
Uninstall flash, and install again !

For do it, for windows in my case :

http://helpx.adobe.com/flash-player/kb/uninstall-flash-player-windows.html

After, just follow the normùal step for install and that's work !

How to take a photo by webcam with Flex Spark

The new Spark them is good, but it is less easy than before to watch the webcam,so here is a tips for do it easily. Here is the source:

<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx" width="800" height="300"   >
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            import spark.components.mediaClasses.DynamicStreamingVideoSource;
           
            private var _cam:DynamicStreamingVideoSource = new DynamicStreamingVideoSource();           
            protected function imgCamera_creationCompleteHandler(event:FlexEvent):void
            {
                var c:Camera=Camera.getCamera();
                imgCamera.videoObject.attachCamera(c);
            }
           
            protected function btnTakePhoto_clickHandler(event:MouseEvent):void
            {
                var imgBD: BitmapData = new BitmapData(imgCamera.width,imgCamera.height);
                imgBD.draw(imgCamera);
                imgResult.source=imgBD;
            }
           
        ]]>
    </fx:Script>
    <fx:Declarations>
    </fx:Declarations>
    <s:VideoDisplay id="imgCamera" x="19" y="6" width="320" height="240" creationComplete="imgCamera_creationCompleteHandler(event)" source="_cam"/>
    <s:Button id="btnTakePhoto" x="360" y="10" label="Take photo"       click="btnTakePhoto_clickHandler(event)"/>
    <s:Image id="imgResult" x="449" y="10" width="320" height="240"/>
</s:TitleWindow>

The main point is too use "source="_cam"" for be able to attach the webcam !

PS: for stop the video : imgCamera.source=null; (that's silly, but i searched 1 hour)