我想在网页浏览中显示PDF文件。为此,我编写了如下代码:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"201507234Surat_GDCR.pdf"];
self.pdfWeb.hidden=FALSE;
self.JantriImage.hidden=TRUE;
self.pdfWeb.delegate=self;
self.pdfWeb = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,ScreenWidth,ScreenHeight-64)];
self.pdfWeb.scalesPageToFit = YES;
NSURL *url = [NSURL fileURLWithPath:filePath];
NSString *urlString = [url absoluteString];
NSString *encodedString=[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *webURL = [NSURL URLWithString:encodedString];
NSURLRequest *request = [NSURLRequest requestWithURL:webURL];
[self.pdfWeb loadRequest:request];
此处self.pdfWeb
是我的webview,文件已在文档目录中,但webview无法加载文件。
答案 0 :(得分:0)
试试这段代码:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"201507234Surat_GDCR.pdf”];
NSURL *url = [NSURL fileURLWithPath:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
答案 1 :(得分:0)
https://login.windows.net/<<MY-AD-TENANT-ID>>/oauth2/authorize?client_id=<<GUID>>&response_type=code