问题
I am using UIKit Framework to generate pdf in iOS device. I am wondering if we can lock (provide security) to the generated pdf so that after emailing or downloading it , one can not edit/modify using any pdf editable tool.
回答1:
Yes - this is possible. If you start the creation of a PDF with UIGraphicsBeginPDFContextToFile you can then send a dictionary to it with options to specify what kind of encryption/locking you want. Here is the documentation for it:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIKitFunctionReference/Reference/reference.html
And here is an example creating it:
NSDictionary * pdfInfo = nil;
if (trimmedPassPhrase && [trimmedPassPhrase length] > 0) {
pdfInfo = [NSDictionary dictionaryWithObjectsAndKeys:trimmedPassPhrase, kCGPDFContextOwnerPassword,
trimmedPassPhrase, kCGPDFContextUserPassword,
[NSNumber numberWithInt:128], kCGPDFContextEncryptionKeyLength, nil];
}
BOOL pdfContextSuccess = UIGraphicsBeginPDFContextToFile(newFilePath, CGRectZero, pdfInfo );
来源:https://stackoverflow.com/questions/10286732/secure-pdf-locked-uneditable-to-prevent-changes-after-generating-from-ios-devi