How to convert (.doc,.xls,.ppt) to pdf using objective c? [closed]

删除回忆录丶 提交于 2019-12-23 06:22:39

问题


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

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

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

Using UIKit or Quartz framework possible to implement ?


回答1:


You can do it with google docs API.

I have implement this.

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

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


(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) Count the number of div class = 'slide to get the slide count

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

(5) Get all the styles

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

Hope this helps



来源:https://stackoverflow.com/questions/25094341/how-to-convert-doc-xls-ppt-to-pdf-using-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!