How do we enable a currently disabled command?
Posted: 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".
This is what we have tried.
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 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();
}
}
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}");
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;
}
}
}