Reading .ppt (MS PowerPoint) file in Cocoa Touch

2019-06-20 01:31发布

Any idea how to read a .ppt file in Cocoa Touch ?

I tried to load the contents of the file in UIWebView but it didn't work. Here is the code :

[aWebView loadData:[NSData dataWithContentsOfFile:filePath]
          MIMEType:@"application/vnd.ms-powerpoint"
  textEncodingName:@"utf-8"
           baseURL:[NSURL fileURLWithPath:filePath]];

[powerWeb loadData:[NSData dataWithContentsOfFile:filePath]
          MIMEType:@"application/vnd.ms-powerpoint"
  textEncodingName:@"utf-8"
           baseURL:[NSURL fileURLWithPath:filePath]]; 

All suggestions are highly appreciated.

Thanks

3条回答
淡お忘
2楼-- · 2019-06-20 02:04
NSString *powerPointFilePath = [[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"ppt"];

NSURL *powerPointFileURL = [NSURL fileURLWithPath:powerPointFilePath];

[self.webView loadRequest:[NSURLRequest requestWithURL:powerPointFileURL]];
查看更多
贼婆χ
3楼-- · 2019-06-20 02:10

If Webkit doesn't have a PPT parser, you're on your own - you have to manually load PPT files, parse them, and render them; it might be easiest to make a web service to do this (this way you get real libraries), then have them download the images over HTTP so the client-side implementation is simple

查看更多
啃猪蹄的小仙女
4楼-- · 2019-06-20 02:20

UIWebView is for displaying web content, in a format you could view directly in a browser. It has no idea about how to display PowerPoint files — most applications don't, since it's a proprietary Microsoft format. (I stand corrected — apparently, UIWebView does know how to display PowerPoint files and others. If it's not working, I'd suggest trying a different MIME type, such as application/mspowerpoint.) Just remember that simply loading a file into an NSData doesn't mean that anyone else you pass that data to will know how to interpret the bytes.

You might check whether Microsoft offers any tools for parsing PPT files, or look around for open-source tools — for example, Google searches often convert to HTML. Just be aware that your browser is usually not loading a PowerPoint version of the file directly.

查看更多
登录 后发表回答