How to convert (.doc,.xls,.ppt) to pdf using objec

2019-06-14 17:29发布

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条回答
家丑人穷心不美
2楼-- · 2019-06-14 18:15

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

查看更多
登录 后发表回答