How to implement password protected PDF file in iPhone SDK
Is any one have an idea to how to implement a password protected PDF file in iphon开发者_如何学Goe sdk. I mean to I need to create a password pdf file from my application.Please help me.
Any one's help will be much appreciated.
Here's another solution that might be better for your purposes:
CGPDFContextCreate takes a dictionary in which you can pass a password as one of the attributes.
The details for CGPDFContxtCreate you'll find in Apple's reference documents at:
http://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGPDFContext/Reference/reference.html#//apple_ref/c/func/CGPDFContextCreate
And the password setting information you'll find in Apple's docs here:
http://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGPDFContext/Reference/reference.html#//apple_ref/doc/constant_group/Auxiliary_Dictionary_Keys
i had the same problem
I've solved the problem using a little trick... that is, generate a PDF and put into a "password protected" zip file
I've using the zip library ziparchive that allow protection
Hope this help
We can provide Password for PDF file by 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];
}
// Create the PDF context using the default page size of 612 x 792.
UIGraphicsBeginPDFContextToFile(fileName, CGRectZero, dictionary);
精彩评论