3 Replies Latest reply on Apr 19, 2011 12:28 PM by JoshBeall

    Generating a PDF of what the user sees, and sending it as a binary stream to the server

    JoshBeall Level 1

      Hi All,

       

      On the final page of our Flex app, we allow the user to print out a copy of everything they've entered for their own records.

       

      I'm wondering if there is a way for me, programmatically, to generate a PDF document that is the same as their printout (I pass a particular container to the "print" button I've got for the user), and send those bytes back to the server.  We can store this PDF along with all the rest of their data, and it would be useful as a "snapshot" of exactly what the user saw when they submitted their application.

       

      I'm looking into Flex PDF generation, but so far haven't gotten this figured out.  I thought some folks here might be able to point me in the right direction.

       

      Thanks!

       

        -Josh

        • 1. Re: Generating a PDF of what the user sees, and sending it as a binary stream to the server
          JoshBeall Level 1

          Or, another idea would be saving a snapshot of what they see as an image, and sending the bytes for that to the server (preferably PNG or GIF compressed, so it's not huge).  A small pallette (e.g., 256 colors) would be acceptable, we really just want to have a snapshot of all the data they entered, not necessarily perfectly preserving the colors on everything.

           

          Is there an easy way I could take a container and figure out the bitmap image that represents that object on the canvas?  And once I've got that, I'd want to compress it before sending it back to the server.

          • 2. Re: Generating a PDF of what the user sees, and sending it as a binary stream to the server
            Zolotoj Level 3

            Here is how you can take a snapshot.

             

            import mx.graphics.ImageSnapshot;
            import mx.graphics.codec.IImageEncoder;
            import mx.graphics.codec.PNGEncoder;
            import mx.utils.Base64Encoder;
            private function uploadImage(rSource:IBitmapDrawable):void
                           {
                                var tBitmapData:BitmapData = ImageSnapshot.captureBitmapData(rSource);
                                
                                var tEnc:IImageEncoder = new PNGEncoder();
                                var tBA:ByteArray = tEnc.encode(tBitmapData);
                                var tB64:Base64Encoder = new Base64Encoder();
                                tB64.encodeBytes(tBA);
                                // send tB64.toString() using POST to the server to save the image.
                           }
            

             

            // call

            uploadImage(this) // where parameter is an object to get the snapshot of. Can be anything including Application. ("this" in my case).

            • 3. Re: Generating a PDF of what the user sees, and sending it as a binary stream to the server
              JoshBeall Level 1

              Zolotoj, this helped out tremendously and helped me solve my problem.  Thank you!

               

                -Josh