密码字段在受密码保护的pdf上不可见

时间:2017-02-11 07:30:53

标签: objective-c cocoa pdf macos-sierra

我正在使用PDF工具包框架来显示/编辑pdf文件。它在macOS 10.12上严重破坏。有时密码保护的文件不显示密码字段,有时密码字段在普通文件中可见。

1 个答案:

答案 0 :(得分:3)

我可以使用未记录的API修复此问题。它的问题与隐藏/取消隐藏密码视图有关。

/*
 From class dump of pdf kit
 @interface PDFPasswordViewController : NSViewController
 {
 NSTextField *_passwordField;
 NSTextField *_passwordPrompt;
 NSTextField *_passwordInstruction;
 NSView *_passwordView;
 PDFView *_pdfView;
 }

 - (void).cxx_destruct;
 - (void)_commonInit;
 - (void)passwordEntered:(id)arg1;
 - (void)setPDFView:(id)arg1;
 - (void)loadView;

 @end
 */

/*
 @private
 PDFViewPrivate* _private;
 Available in PDFView.h file
 */
id PDFViewPrivate = [self.pdfView valueForKey:@"_private"];
if (PDFViewPrivate)
{
    NSViewController *passwordViewController = [PDFViewPrivate valueForKey:@"passwordViewController"];
    NSView *passwordView = [passwordViewController valueForKey:@"_passwordView"];
    if (self.pdfView.document.isLocked)
    {
        NSTextField *passwordField = [passwordViewController valueForKey:@"_passwordField"];
        // Reset last password
        [passwordField setStringValue:@""];
        // Add password view
        passwordView.hidden = NO;
    }
    else
    {
        passwordView.hidden = YES;
    }
}

PDFPasswordViewController仅适用于10.12