Page 1 of 1

How do we enable a currently disabled command?

Posted: Tue Apr 24, 2018 6:41 pm
by Shaun Luttin
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;
        }
    }
}

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

Posted: Wed Apr 25, 2018 9:55 am
by Tracker Supp-Stefan
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

Re: How do we enable a currently disabled command?

Posted: Wed Apr 25, 2018 5:10 pm
by Shaun Luttin
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

Re: How do we enable a currently disabled command?

Posted: Wed Apr 25, 2018 5:57 pm
by Shaun Luttin
How can we programmatically determine whether the PDF is secured?

Re: How do we enable a currently disabled command?

Posted: Thu Apr 26, 2018 11:21 am
by Tracker Supp-Stefan
Hello Shaun Luttin,

You will need to check is the operation is granted:
https://help.pdf-xchange.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