We can provide a password for the PDF file using:
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"owner", kCGPDFContextOwnerPassword, @"user", kCGPDFContextUserPassword, kCFBooleanFalse, kCGPDFContextAllowsCopying, kCFBooleanFalse, kCGPDFContextAllowsPrinting, nil];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *fileName = [NSString stringWithFormat:@"%@/Documents/samplePDF.pdf", NSHomeDirectory()];
if (![fileManager fileExistsAtPath:fileName]) {
[fileManager createFileAtPath:fileName contents:nil attributes:nil];
}
UIGraphicsBeginPDFContextToFile(fileName, CGRectZero, dictionary);
Madhu source
share