IOS不会在webview中显示填写的PDF表单填充文本

时间:2015-09-17 05:49:43

标签: ios objective-c ipad pdf

这是我目前正在做的事情, 我的应用程序可以使用相应字段中的值填写PDF表单,并生成PDF的新副本。好吧,它工作正常,并按我的意愿得到预期的结果。 但我的问题是, 当我想查看填写了数据的生成的PDF文件时,它在我的IPAD中没有显示任何内容。

Here is the end result of my filled form which I grab from the container of my IPAD

Here is what it display in my IPAD

我从IPAD容器中获取生成的PDF文件,它能够在MacBook的相应字段中显示文本,但无法在IOS中显示。 这是我的Objective-C代码:

NSString *txtFilePath = [[self getDocumentsFolder] stringByAppendingPathComponent:@"geForm1.pdf"];

NSURL *targetURL = [NSURL fileURLWithPath:txtFilePath];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:targetURL];
CGFloat  height  = [[UIScreen mainScreen] bounds].size.height;
CGFloat  width  = [[UIScreen mainScreen] bounds].size.width;
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
[webView loadRequest:request];
[self.view addSubview:webView];

我想知道我犯了哪些错误导致填充数据未在IOS中显示。

更新

我尝试在iBook中打开pdf文件,但各个字段中没有任何值。该文件是空白的。然后我尝试在Adobe Reader中打开pdf文件,感谢上帝所有文本显示在各自的字段中。

现在我的问题是,如何在默认/本机pdf查看器或Web视图中显示这些填充文本?

1 个答案:

答案 0 :(得分:-1)

它适用于我的情况。

-(void)readPDFFile{
//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
//    NSString *txtFilePath = [documentsDirectory stringByAppendingPathComponent:@"geForm1.pdf"];
NSString *txtFilePath = [[NSBundle mainBundle] pathForResource:@"geForm1" ofType:@"pdf"];
NSLog(@"txtFilePath:%@",txtFilePath);

NSURL *targetURL = [NSURL fileURLWithPath:txtFilePath];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:targetURL];
CGFloat  height  = [[UIScreen mainScreen] bounds].size.height;
CGFloat  width  = [[UIScreen mainScreen] bounds].size.width;
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
[webView loadRequest:request];
[self.view addSubview:webView];

}

注意:我从应用程序的包文件夹中读取了pdf文件