Programmatically determine whether the PDF is secured?  SOLVED

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

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

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 »

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: 17818
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Programmatically determine whether the PDF is secured?

Post by Tracker Supp-Stefan »

Hello Shaun,

I believe in the Viewer this was the way:
https://help.pdf-xchange.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 »

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.pdf-xchange.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: 17818
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Programmatically determine whether the PDF is secured?

Post by Tracker Supp-Stefan »

Lovely Shaun Luttin,

Thanks for sharing your solution!

Regards,
Stefan
Post Reply