sivarajankumar / alivepdf

Automatically exported from code.google.com/p/alivepdf
0 stars 0 forks source link

Multiple events dispatched in PDF.save(Method.REMOTE) #99

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
On version 1.4.6, looking in the source code, when Method is REMOTE (or
anything else, it's not checked), the code makes an unneeded recursive
call, with Method.LOCAL to obtain the byte buffer contents (line 2507).

This is no need for that call, wich can be repaced by the following line of
code:

myRequest.data = buffer;

The whole method should be replaced to control invalid methods, with
something like the attached file.

Cheers,

Juan

public function save ( method:String, url:String='',
downloadMethod:String='inline', fileName:String='generated.pdf' ):*
{
dispatcher.dispatchEvent( new ProcessingEvent ( ProcessingEvent.STARTED ) );
            var started:Number = getTimer();
            finish();
            dispatcher.dispatchEvent ( new ProcessingEvent (
ProcessingEvent.COMPLETE, getTimer() - started ) );
            buffer.position = 0;

            var output : * = null;
            switch (method)
            {
                case Method.LOCAL : 
                    output = buffer;
                    break;  

                case Method.BASE_64 : 
                    output = Base64.encode64 ( buffer );
                    break;

                case Method.REMOTE :
                    const header:URLRequestHeader = new URLRequestHeader ("Content-type",
"application/octet-stream");
                    const myRequest:URLRequest = new URLRequest (
url+'?name='+fileName+'&method='+downloadMethod );
                    myRequest.requestHeaders.push (header);
                    myRequest.method = URLRequestMethod.POST;
                    myRequest.data = buffer;

                    navigateToURL ( myRequest, "_self" );
                    break;

                default:
                    throw new Error("Unknown Method \"" + method + "\"");

            }

            return output;
        }

Original issue reported on code.google.com by juan.t...@gmail.com on 29 Jan 2009 at 8:05

Attachments:

GoogleCodeExporter commented 8 years ago
Sorry about the pasted code, it was a mistake.

Original comment by juan.t...@gmail.com on 29 Jan 2009 at 8:07

GoogleCodeExporter commented 8 years ago
Hi Juan,

That's true, save method will be updated in the next release.

Thanks for catching this optimization.

Thibault

Original comment by thibault.imbert on 4 Feb 2009 at 10:51