Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open password protected PDFs #6

Open
mahirekici opened this issue Jun 11, 2015 · 2 comments
Open

Open password protected PDFs #6

mahirekici opened this issue Jun 11, 2015 · 2 comments

Comments

@mahirekici
Copy link

Hi, i have protected pdf. i want open , possible?

@semweb
Copy link
Owner

semweb commented Jun 11, 2015

GreatReader doesn't support protected pdf. But you can unlock with CGPDFDocumentUnlockWithPassword.

@mahirekici
Copy link
Author

Thanks.

  • (instancetype)initWithPath:(NSString *)path
    {

    self = [super initWithPath:path];
    if (self) {
    //burada şifrele

    NSURL *URL = [NSURL fileURLWithPath:path];
    _CGPDFDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef)URL);
    
    //PDFファイルがパスワード付きか調べる
    BOOL isEncrypted = CGPDFDocumentIsEncrypted(_CGPDFDocument);
    
    if(isEncrypted){
        NSLog(@"isEncrypted YES");
    }else{
        NSLog(@"isEncrypted NO");
    }
    
    
    NSString *password = @"!XI5u2ri3Ar?.";
    BOOL isUnlocked = CGPDFDocumentUnlockWithPassword(_CGPDFDocument, [password UTF8String]);
    
    
    if(isUnlocked){
    
        if (_CGPDFDocument) {
            _numberOfPages = CGPDFDocumentGetNumberOfPages(_CGPDFDocument);
        } else {
            self.fileNotExist = YES;
            return self;
        }
        _currentPage = 1;
        _brightness = 1.0;
    
        [self loadThumbnailImageAsync];
    
        _kvoController = [FBKVOController controllerWithObserver:self];
    
    }else{
        NSLog(@"isUnlocked NO");
    }
    

    }
    return self;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants