在我的应用程序中,我需要根据页面显示PDF。一次只有一页,下一页&底部的前一个按钮。单击“下一步”将加载下一页,依此类推...
我知道使用UIWebview可以显示PDF,但是整个PDF文档都是一次显示的。每次都需要显示单页
NSURL* url = [NSURL URLWithString:@"http://ExMonthly.pdf"];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
wbView.scalesPageToFit=YES;
[wbView loadRequest:request];
[self.view addSubview:wbView];
此代码显示该pdf的所有可用页面。如何获取单个页面
任何想法/帮助都会感激不尽
答案 0 :(得分:0)
这样的事情:
- (void)savePdfDataLocally {
NSData *dataPdf = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://ExMonthly.pdf"]];
//Get path directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//Create PDF_Documents directory
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"PDF_Documents"];
[[NSFileManager defaultManager] documentsDirectory withIntermediateDirectories:YES attributes:nil error:nil];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"ExMonthly.pdf"];
[dataPdf writeToFile:filePath atomically:YES];
}
- (void)loadPage:(int)page {
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath_from_previous_function]];
webView.scalesPageToFit=YES;
[webView loadRequest:request];
}
- (IBAction)nextTap:(id)sender {
currentPage++;
[self loadPage:currentPage];
}