
Question:
I'm giving users the ability to upload an image to my Air app, then displaying this image in an image control. But I need to allow for PDF uploading in the same manner, so I need to convert the PDF to an image. I only care about the first page of the PDF they upload for now.
What I'm doing is: 1) User browses for a file with the file reference control 2) User chooses the image or PDF to upload 3) I encode said image to base64 and store it 4) I then load from that base64 with something like:
public function decodeImage(b64String:String):void{ var decoder:Base64Decoder = new Base64Decoder(); decoder.decode(b64String); var imgLoader:Loader = new Loader(); imgLoader.loadBytes(decoder.toByteArray()); imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,decodedImageLoaded); } private function decodedImageLoaded(event:Event):void{ var imgLoader:Loader = (event.target as LoaderInfo).loader; var bmp:Bitmap = Bitmap(imgLoader.content); imgLoader.removeEventListener(Event.COMPLETE, decodedImageLoaded); var img:Image = new Image(); img.source = bmp; this.addChild(img); }
This method is working great for .gif, .jpg, and .png. At some point in my process, probably the initial upload I need to convert the first page of a PDF to a png so that I can use the rest of this process.
I welcome any ideas with the sole requirement being that it has to be a part of the Air app, I can't use something like ImageMagick that runs on a server, but I could use a component that I can compile in to the finished product.
Solution:1
I believe AlivePDF for Flash now has capabilities to read a PDF file. You might try PurePDF, as well. You could potentially use ones of these to get that desired page and convert it to an image.
Solution:2
Have you seen swftools? It has the ability to convert a PDF to a SWF, PNG, JPG, etc...
Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
EmoticonEmoticon