如何使用目标 c 将 (.doc,.xls,.ppt) 转换为 pdf? [英] How to convert (.doc,.xls,.ppt) to pdf using objective c?

查看:75
本文介绍了如何使用目标 c 将 (.doc,.xls,.ppt) 转换为 pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在pdf文件上实现注释并将其导出.

I can able to implement the annotation on pdf file and export it.

但是在 doc、xls 和 ppt 的情况下,我无法使用目标 c 应用注释?

But in the case of doc,xls and ppt i couldn't able to apply the annotation using objective c ?

所以我计划将 (.doc,.xls,.ppt) 文件转换为 pdf 格式.

So i had plan to convert the (.doc,.xls,.ppt) files to pdf format.

使用 UIKit 或 Quartz 框架可以实现吗?

Using UIKit or Quartz framework possible to implement ?

推荐答案

您可以使用 google docs API 来完成.

You can do it with google docs API.

我已经实施了这个.

试试吧,很容易实现...

Just try it it is very easy to implement...

第二个选项:使用以下,我从 这里.

Second Option : Use following, I found it from here.

(1) 使用UIWebView来显示PPT的内容.格式良好的 (!) HTML 允许您解析它.使用

(1) Use UIWebView to display the content of the PPT. The well formed (!) HTML allows you to parse it. Get the html using

NSString *htmlContent = [self.webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];

(2) 统计div class = 'slide的数量,得到幻灯片数

(2) Count the number of div class = 'slide to get the slide count

(4) 您需要使用以下代码解析 HTML 以获取样式和 div

(4) You need to parse the HTML to get the styles and div using the below code

(5) 获取所有样式

- (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>"];
}

(6) 将第 5 步中的所有样式与 div 标签内容连接起来.定义一个 NSMutableArray 变量来存储所有带有样式的幻灯片以供将来参考.定义 NSMutableArray *slides 来存储所有的幻灯片

(6) Concatenate all the styles from step 5 with div tag content. Define a NSMutableArray variable to to store all slides with styles for future reference. Define NSMutableArray *slides to store all the slides

- (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];
    }
}

希望能帮到你

这篇关于如何使用目标 c 将 (.doc,.xls,.ppt) 转换为 pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆