In my application I need to allow the user to browse some PDF files from iPhone stored in local or document directory.
Want to put one button when user click that button its shows the pdf file and attach that file and send it server.[ex:attach document in gmail].
How can i achive this.help me. Thanks advance.
In viewdidload ///// download the pdf file in document directory.
NSString *stringURL = @"http://www.khazanah.com.my/khazanah/files/20/200f21f3-07ff-4903-ab99-7c0cb557eb51.pdf";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"filename.pdf"];
NSLog(@"filePath %@",filePath);
[urlData writeToFile:filePath atomically:YES];
}
Get the file in in document directory.
-(IBAction)favbtnClicked:(id)sender
{
NSString *searchFilename = @"filename.pdf"; // name of the PDF you are searching for
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:documentsDirectory];
NSString *documentsSubpath;
while (documentsSubpath = [direnum nextObject])
{
if (![documentsSubpath.lastPathComponent isEqual:searchFilename]) {
continue;
}
NSLog(@"found %@", documentsSubpath);
}
}
documentsSubpath in string got that pdf file how can i show in UICollectionView. help me.