views:

40

answers:

1

Hi,
I am using urlloader to load a tiff file from the server. Then i get it as ByteArray and show the image in a popup window.

var bytes:ByteArray = urlloader.data as ByteArray; i use the TIFFbaselineDecoder to decode the bytes and open a popup to show the bitmap. Works nicely.

Now, i want to do the same thing for a pdf file. How can i show the pdf file in a window from the bytearray.

Please let me know.

Thanks
Vish

A: 

First, you can check if the user's machine is suitable for PDF display

if(HTMLLoader.pdfCapability == HTMLPDFCapability.STATUS_OK){
    trace("PDF content can be displayed");
} 
else {
    trace("PDF cannot be displayed. Error code:", HTMLLoader.pdfCapability); 
}

If so, then

var request:URLRequest = new URLRequest("http://www.example.com/test.pdf"); 
pdf = new HTMLLoader(); 
pdf.height = 800; 
pdf.width = 600; 
pdf.load(request); 
container.addChild(pdf);

Mind you, this works too :

<mx:HTML width="100%" height="100%" location="understanding_the_flex_3_lifecycle_v1.0.pdf"/>
kubarium
I was about to go down this same route with an answer. But, he said he wanted to display a PDF from a byteArray; not a URL. IF he has a URL; this is the way to go for sure.
www.Flextras.com
Hi Jeff, I thought triggering the server would bring a PDF output like TIFF in his previous case so location might be enough to listen to that. I guess he has to try and let us know if it's that easy to use HTML or do some other trick with ByteArray.
kubarium
Hi Kubarium/Jeff, The pdf is stored in MySQL DB and its streamed back to the client using PHP. All i have is the bytearray, after using the urlloader to call the server function for download. i guess, if the pdf is stored in some location on the server, then we can use the url-way, pl correct me if i am wrong. Guess, i need a decoder for pdf in actionscript.Pl let me know,Thanks
Vish
I think if your only choice is bytearray, maybe you can temporarily write bytearray data into a file and name it *.PDF then access it with HTML like in the example I gave. Would that work?
kubarium