How to implement password protected PDF file in iPhone SDK

Does anyone have an idea how to implement a password protected PDF file in iphone sdk. I want me to create a PDF file with a password from my application. Please help me.

Any help would be greatly appreciated.

+3
source share
3 answers

i had the same problem

I solved the problem with a little trick ... that is, I generated a PDF file and put it in a "password protected" zip file

I am using the ziparchive zip library which allow me to protect

Hope for this help

0
source

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

        // Create the PDF context using the default page size of 612 x 792.
        UIGraphicsBeginPDFContextToFile(fileName, CGRectZero, dictionary);
+1
source

Source: https://habr.com/ru/post/1743460/


All Articles