我想将word文件分成多个页面并存储到一个数组中,当需要时我想将该特定页面显示到UIWebView
。我为PPT做了同样的事情但不能为word文件做。这是我的PPT代码。
(1)使用UIWebView
显示PPT的内容。格式良好的(!)HTML允许您解析它。使用
NSString *htmlContent = [self.webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];
(2)计算div class ='slide的数量以获得幻灯片计数
(3)您需要使用以下代码解析HTML以获取样式和div
(4)获取所有样式
- (NSString *)getStyles:(int)slideCount forView:(UIWebView *)view {
NSString *getElementByTag = [[NSString alloc] init];
NSString *allStyles = [[NSString alloc] init];
for (int i = 0; i < slideCount; i++) {
getElementByTag = [NSString stringWithFormat:@"document.getElementsByTagName('style')[%d].innerHTML", i];
NSString *style = [[view stringByEvaluatingJavaScriptFromString:getElementByTag] stringByAppendingString:@"\n"];
allStyles = [allStyles stringByAppendingString:style];
}
allStyles = [@"<style type='text/css'>" stringByAppendingString: allStyles];
return [allStyles stringByAppendingString:@"</style>"];
}
(5)将步骤5中的所有样式与div标签内容连接起来。定义NSMutableArray
变量以存储所有带样式的幻灯片以供将来参考。定义NSMutableArray
*幻灯片以存储所有幻灯片
- (void)makeSlides:(int)slideCount forView:(UIWebView *)view {
self.slides = [[NSMutableArray alloc] init];
for (int i = 0; i < slideCount; i++) {
NSString *slideBody = [NSString stringWithFormat:@"document.getElementsByClassName('slide')[%d].innerHTML", i];
NSString *div = [view stringByEvaluatingJavaScriptFromString:slideBody];
NSString *slide = [self.slideStyles stringByAppendingString:div];
[self.slides addObject:slide];
}
}
就像我想为word文档做同样的事情。请帮我。
我已经参考了这个链接。 IOS library to convert powerpoint presentations into images