kiran
kiran

Reputation: 4409

How to save pdf locally from image view

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

Upvotes: 0

Views: 206

Answers (1)

Deepak
Deepak

Reputation: 348

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];
        }

Upvotes: 1

Related Questions