Programmatically determine whether the PDF is secured?  SOLVED

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: Tracker Support, TrackerSupp-Daniel, Chris - Tracker Supp, Vasyl-Tracker Dev Team, Sean - Tracker, Tracker Supp-Stefan, Ivan - Tracker Software

Post Reply
User avatar
Shaun Luttin
User
Posts: 20
Joined: Tue Apr 17, 2018 12:13 am

Programmatically determine whether the PDF is secured?

Post by Shaun Luttin » Wed Apr 25, 2018 6:05 pm

How can we programmatically determine whether the PDF is secured?

We're looking for something like this:

Code: Select all

private bool IsDocumentSecured(int docId)
{
    _viewer.GetDocumentProperty(docId, "Document.Security", out var isSecured);
    return (int) isSecured == 1;
}

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13312
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Programmatically determine whether the PDF is secured?

Post by Tracker Supp-Stefan » Thu Apr 26, 2018 11:30 am

Hello Shaun,

I believe in the Viewer this was the way:
https://help.tracker-software.com/DEV/d ... iongranted

Regards,
Stefan

User avatar
Shaun Luttin
User
Posts: 20
Joined: Tue Apr 17, 2018 12:13 am

Re: Programmatically determine whether the PDF is secured?  SOLVED

Post by Shaun Luttin » Wed May 02, 2018 12:55 am

We ended up doing it like this:

Code: Select all

public bool IsDocumentSecured(int docId) {
    // For now we assume the document is secured if the Delete Page operation is not granted.
    // We asked a forum question here that might surface a better approach.
    // https://forum.tracker-software.com/viewtopic.php?f=36&t=30839&p=123742#p123742
    return !IsOperationGranted(docId, ObjectIdentifier.Page, OperationIdentifier.Delete);
}

public bool IsOperationGranted(int documentId, ObjectIdentifier objectId, OperationIdentifier operationId) {
    var dataIn = new object[] {
        (int) objectId,
        (int) operationId
    };

    _viewer.DoDocumentVerb(documentId, null, "IsOperationGranted", dataIn, out var isGranted);
    return (int) isGranted == 1;
}

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13312
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Programmatically determine whether the PDF is secured?

Post by Tracker Supp-Stefan » Wed May 02, 2018 11:19 am

Lovely Shaun Luttin,

Thanks for sharing your solution!

Regards,
Stefan

Post Reply