开发者

How can I convert a PDF file to an image?

开发者 https://www.devze.com 2023-01-08 21:39 出处:网络
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 ma开发者_C百科nner, so I need to conve

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 ma开发者_C百科nner, 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.


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.


Have you seen swftools? It has the ability to convert a PDF to a SWF, PNG, JPG, etc...

0

精彩评论

暂无评论...
验证码 换一张
取 消