0

I want to create a PDF document, that can't get printed. I am using the Quartz framework for that. This is what I do (shorted):

    PDFDocument *pdfDocument = ...

    NSMutableDictionary *options = [[NSMutableDictionary alloc] init];
    [options setValue:@"test-password" forKey:(NSString *)kCGPDFContextUserPassword];
    [options setValue:@0 forKey:(NSString *)kCGPDFContextAllowsPrinting];

    [pdfDocument writeToFile:savePath withOptions:options];

But I can still print the resulting file with Preview.app without having to type in a password.

If I set a kCGPDFContextOwnerPassword, the document is locked with the password (but not the print function)

What am I doing wrong?

Thanks!

CGPDFContext Reference

Daniel
  • 1,473
  • 3
  • 33
  • 63

2 Answers2

2

After using CFMutableDictionaryRef instead of NSMutableDictionary, it finally works. Don't ask me why... :D

Daniel
  • 1,473
  • 3
  • 33
  • 63
0

Set kCGPDFContextAllowsPrinting value to kCFBooleanFalse but by The default value of this key is kCFBooleanTrue.

Whether the document allows printing when unlocked with the user password.

Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132