【发布时间】:2016-08-11 09:13:08
【问题描述】:
在我的项目中,我正在使用PDFJS 库。我正在UIWebView 上加载本地 pdf。但这会占用大量 RAM 内存,并且有时会崩溃。为了避免这种情况,我想使用WKWebView。
在UIWebview,我是这样使用的(self指UIView的子类)
UIWebView *uiWebview = [[UIWebView alloc] initWithFrame:self.frame];
[self addSubview:uiWebview];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"swift_tutorial" ofType:@"pdf"];
NSString *sPath = [[NSBundle mainBundle] pathForResource:@"viewer" ofType:@"html" inDirectory:@"PDFJS/web"];
NSString *finalPath = [NSString stringWithFormat:@"%@?file=%@#page=1",sPath,filePath];
self.urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:finalPath]];
[uiWebview loadRequest:self.urlRequest];
当我在上面的sn-p中打印finalPath时,控制台输出为/var/containers/Bundle/Application/DF419672-CF14-4B60-BE4F-EC0AC07C23AE/WebviewPOC.app/PDFJS/web/viewer.html?file=/var/containers/Bundle/Application/DF419672-CF14-4B60-BE4F-EC0AC07C23AE/WebviewPOC.app/swift_tutorial.pdf#page=1
在WKWebView, loadFileURL, loadHTMLString 方法可以用来加载本地html文件或本地pdf文件,效果很好。但不是两者兼而有之。对于这个html文件,如何追加本地pdf路径并加载到WKWebView中?
任何帮助表示赞赏。
【问题讨论】:
标签: ios uiwebview wkwebview pdfjs