How do we enable a currently disabled command?  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

How do we enable a currently disabled command?

Post by Shaun Luttin » Tue Apr 24, 2018 6:41 pm

How do we enable the DeletePages command? Its current state is Disabled and when trying to run it we are receiving, "No permissions for current action".

Code: Select all

private void DeletePageFromDocument(int documentId, int pageIndex)
{
    try
    {
        axCoPDFXCview1.SetProperty("Operations.DeletePages.RangeType", "Exact");
        axCoPDFXCview1.SetProperty("Operations.DeletePages.RangeText", pageIndex);
        axCoPDFXCview1.DoDocumentVerb(documentId, null, "DeletePages", null, out _,
            (int) PXCVA_Flags.PXCVA_NoUI);
    }
    catch (Exception ex)
    {
        axCoPDFXCview1.GetTextFromResult(ex.HResult, out var text);
        System.Diagnostics.Debug.WriteLine(text); // No permission for current action
        System.Diagnostics.Debugger.Break();
    }
}
This is what we have tried.

Code: Select all

var propertyName = "Commands[\"DeletePages\"].State";
axCoPDFXCview1.SetProperty(propertyName, "Enabled");

// we also tried
// axCoPDFXCview1.SetProperty(propertyName, 0);

axCoPDFXCview1.GetProperty(propertyName, out var propertyValue);
System.Diagnostics.Debug.WriteLine($"{propertyName} {propertyValue}");
Also, we expected the following code to enable all commands that are currently not enabled. Unfortunately, it does not do that. Suggestions?

Code: Select all

private void EnableAndDisableCommands()
{
    axCoPDFXCview1.GetProperty("Commands.Count", out var commandsCount, 0);
    for (var i = 0; i < (int)commandsCount; ++i)
    {
        try
        {
            var cmdNameKey = "Commands[" + i.ToString() + "].Name";
            axCoPDFXCview1.GetProperty(cmdNameKey, out var cmdName, 0);

            if(string.IsNullOrWhiteSpace(cmdName.ToString())) continue;

            var cmdIdKey = "Commands[" + i.ToString() + "].ID";
            axCoPDFXCview1.GetProperty(cmdIdKey, out var cmdId, 0);

            var cmdStateKey = "Commands[" + i.ToString() + "].State";
            axCoPDFXCview1.GetProperty(cmdStateKey, out var cmdState, 0);

            if ((CommandState) cmdState != CommandState.Enabled)
            {
                axCoPDFXCview1.SetProperty(cmdStateKey, CommandState.Enabled.ToString());
                axCoPDFXCview1.GetProperty(cmdStateKey, out cmdState, 0);
            }
        }
        catch
        {
            break;
        }
    }
}

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

Re: How do we enable a currently disabled command?  SOLVED

Post by Tracker Supp-Stefan » Wed Apr 25, 2018 9:55 am

Hello Shaun Luttin,

Are there any security restrictions on the file you are testing with?
Or is there maybe a digital signature/XFA forms inside it?

Can you test with a different file and see if that helps?

Regards,
Stefan

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

Re: How do we enable a currently disabled command?

Post by Shaun Luttin » Wed Apr 25, 2018 5:10 pm

Hi Stefan,

Indeed the PDF is labeled as [Secured]. How can we work around that? For instance, can we simply create a copy of the PDF?

Best,
Shaun

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

Re: How do we enable a currently disabled command?

Post by Shaun Luttin » Wed Apr 25, 2018 5:57 pm

How can we programmatically determine whether the PDF is secured?

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

Re: How do we enable a currently disabled command?

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

Hello Shaun Luttin,

You will need to check is the operation is granted:
https://help.tracker-software.com/DEV/d ... iongranted

As for working around a document's security - you should not really do this and respect any security restrictions there are in a file.

Regards,
Stefan

Post Reply