1
votes

i am new to flex, i have no idea to convert pdf file into byte array.and also i tried in google also but no results yet.can u prefer how to convert pdf file into byte array and retrieve byte array into pdf file in flex application.

it is urgent....

Thanks in advance.(nothing is impossible)

1
why do you need the pdf as bytearray ? DO you access the pdf via FileReference ? please post your code... - Adrian Pirvulescu

1 Answers

1
votes

If you have a Flex (web) app, you will be using the FileReference class

private var ref:FileReference;
//This generally is a mouse click handler, to initiate the process of file reading (i.e. Selection)
public function mc():void {
    ref=new FileReference();
    ref.addEventListener(Event.SELECT, fileSelected);
    ref.browse([new FileFilter("PDF Files (*.pdf)", "*.pdf")]);
}

private function fileSelected(e:Event):void {
    ref.removeEventListener(Event.SELECT, fileSelected);
    ref.addEventListener(Event.COMPLETE, fileOpen);
    ref.load();
}

private function fileOpen(e:Event):void {
    var byteArrayToProcess:ByteArray=ref.data;
}

If you have an AIR (desktop / mobile) app, you can directly use the File and FileStream class.

public function mc():void {
    var f:File=new File("path/to/file");
    var s:FileStream=new FileStream();
    s.open(f, FileMode.READ);
    var byteArrayToProcess:ByteArray=new ByteArray()
    s.readBytes(byteArrayToProcess, 0, s.bytesAvailable);
}