0

How to save the pdf locally

I have loaded the pdf doc into imageView. Now i need to save into locally into iPhone device.

Any one advice me how to save the pdf file from image view

@All

Thanks in advance

4

1 回答 1

1

For saving the pdf in document directory use below code.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:@"data.pdf"];

        NSData *thedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:`ADD URL OF PDF DATA`]];

        [thedata writeToFile:localFilePath atomically:YES];

For retrieving the pdf use below code.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
            NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:@"data.pdf"];
if ( [[NSFileManager defaultManager] fileExistsAtPath:localFilePath] ) {
            NSData *data = [NSData dataWithContentsOfFile:localFilePath];
        }
于 2012-08-14T07:08:39.247 回答