Reputation: 365
Here is what I am doing currently, My application can fill in the PDF forms with values in the respective fields and generate a new copy of a PDF. Alright, it works fine and get the expected results as I wish. But my questions are, When I want to view the generated PDF files with data filled in, it shows nothing in my IPAD.
I grab the generated PDF files from IPAD container and it's able to show the text in the respective fields in MacBook but fail to display in IOS. Here is my Objective-C code:
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];
I wonder where is the mistake I had made which cause the filled data not shown in IOS.
UPDATE:
I tried open the pdf files in iBook and it do not have any values inside the respective fields. The document is blank. Then I tried open the pdf files in Adobe Reader and thank god all the text is shown in respective fields.
Now my questions, how to make those filled text shown on default/native pdf viewer or web view?
Upvotes: 4
Views: 972
Reputation: 2999
It works for my case.
-(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];
}
Note: I read pdf file from application's bundle folder
Upvotes: -1