I have used the CGPDFDocument
class to read .pdf
documents and retrieve the # of pages or pul开发者_JAVA百科l back a page by number.
I am looking for a similar library which will do the same for documents in Microsoft Word format. I'm not interested in using Safari to view the document.
I have seen some apps in the app store which claim to read MS Office docs such as .docx
, .xlsx
, etc, but I am looking for a library to enable the development of my own app to do the same. Can anyone point me in the right direction?
The document types produced from the latest versions of Microsoft Office (those which have an x
at the end, such as .docx
, .xlsx
, .pptx
, etc) are actually saved according to the OpenXML
standard, which is fairly well documented. I mention that because it will be helpful to you in searching for further help in reading and parsing the document formats for your application(s).
That said, it sounds like you're looking for a standard library with which you can read and manipulate these kinds of documents from Objective-C.
An discussion with examples of how to do this using the OpenXML SDK 2.0 can be found here. As an exerpt:
using (WordprocessingDocument document = WordprocessingDocument.Open(fileName, false))
{
int pageCount = (int) document.ExtendedFilePropertiesPart.Properties.Pages.Text;
}
A tutorial for using the OpenXML SDK from Objective-C can be found here (though the images from the article appear to be broken). The tutorial bases its code on the GData Objective-C Client found on Google Code.
You might also refer to this SO Question and it's answer, which refers to the open-source library libOPC, the web-page for which gives examples of how to build Word Document manipulation in an iPhone app.
Unfortunately, none of these resources are likely to assist you in reading an old-format .doc
file, which is in a far more proprietary Microsoft format. So - I'm hoping that isn't what you need to do. Either way, I hope these resources help! Let us know if you get it working.
Loading a document using a UIWebView :
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
// Calling -loadDocument:inView:
[self loadDocument:@"mydocument.rtfd.zip" inView:self.myWebview];
Taken from here. Besides, also check out this forum discussion.
Loading a local PDF file into the web view
- (void)viewDidLoad {
[super viewDidLoad];
NSString *thePath = [[NSBundle mainBundle] pathForResource:@"iPhone_User_Guide" ofType:@"doc"];
if (thePath) {
NSData *pdfData = [NSData dataWithContentsOfFile:thePath];
[(UIWebView *)self.view loadData:pdfData MIMEType:@"application/doc"
textEncodingName:@"utf-8" baseURL:nil];
}
}
and if through network then
[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/iphone_user_guide.pdf"]]];
精彩评论