My requirement is to render a PDF file which is dynamically generated from a web server in an Adobe AIR application.
The user posts some data to the web server. A PDF file is generated at the web server and is returned as the response with content-type : application/pdf
I use URLLoader to post the request and handle the response. When the response is received i am unable to read it as a PDF file.
code at client end
function submitRequest()
{
var server = 'http://localhost:8080/bikestore/';
var params = 'orderData=orderData';
var request = new air.URLRequest(server + 'submitOrder.bikes');
request.data = params;
request.method = air.URLRequestMethod.POST;
var loader = new air.URLLoader();
loader.dataFormat = air.URLLoaderDataFormat.BINARY;
loader.addEventListener(air.Event.COMPLETE, submitComplete);
try {
loader.load(request);
}
catch (error) {
air.trace("Error connecting to login server.");
}
}
function submitComplete(event)
{
air.trace(event.target.data);
new air.ByteArray(event.target.data);
}
I tried setting the URLLoaderDataFormat property to BINARY and when i try to instantiate a air.ByteArray with the returned data it gives me a Arg count mismatch error
> ArgumentError: Error #1063: Argument count mismatch on
> flash.utils::ByteArray().
> Expected 0, got 1.
> at flash.events::EventDispatcher/dispatchEventFunction()
> at flash.events::EventDispatcher/dispatchEvent()
> at flash.net::URLLoader/onComplete()
I use iText to generate the pdf and the file looks fine when the client is a browser instead of AIR.
Is there a way to accomplish this?