Password field not visible on password protected pdf

限于喜欢 提交于 2019-12-13 17:14:46

问题


I am using PDF kit framework to display/Edit pdf files. Its broken badly on macOS 10.12. Sometimes password protected files do not display password field and sometimes password field is visible in normal file.


回答1:


I am able to fix this using undocumented APIs. Its issue related to hide/unhide password view.

/*
 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 is only available on 10.12



来源:https://stackoverflow.com/questions/42173471/password-field-not-visible-on-password-protected-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!