Disable Save As / Save Copy As via CreateOpenDocParams  SOLVED

PDF-XChange Editor SDK for Developers

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

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Disable Save As / Save Copy As via CreateOpenDocParams

Post by zarkogajic »

Hi Support,

I'm trying to disable "Save As" (and "Save Copy As" commands) *per* document.

Using:

Code: Select all

//piece from FullDemo

ICab openCab = pdfCtl.Inst.CreateOpenDocParams();
openCab.Root.SetInt("SecPermMask", (int)PDFXEdit.PXC_PermsFlags.PermF_All);

pdfCtl.OpenDocFromPath(tSrcToOpen.Text,openCab);
Nicely opens the document having all editing to it disabled.

Printing also gets disabled.

If, for example, I use "PermF_All - PermF_Print" for "SecPerMask" -> all editing is disabled, but printing is enabled - as expected.

However, the "Save As" and "Save Copy As" are enabled in UI - even if "PermF_SaveAs" should be covered by "PermF_All".

I've also tried with (after opening the document):

Code: Select all

pdfCtl.Doc.CoreDoc.SetOperationRestriction(Perm_ObjDoc, Perm_OperUIsave, true);
pdfCtl.Doc.CoreDoc.SetOperationRestriction(Perm_ObjDoc, Perm_OperFullSave, true);
But, still, saving is allowed in UI.

Question: is this a bug and (if not) how to disable saving ?

p.s.
No, I do not want to disable/hide/make_offline the "saveAs" command for the entire Instance, as in: https://forum.pdf-xchange.com/viewtopic.php?f=66&t=32598&p=133593

I need to disable saving per document.

p.s.2
Yes, using the latest version 9.1.356.

-žarko
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Disable Save As / Save Copy As via CreateOpenDocParams

Post by zarkogajic »

Hi Support,

I've managed to have this working by:

1. Open document in pdfCtl
2. pdfCtl.Doc.CoreDoc.SetOperationRestriction(Perm_ObjDoc, Perm_OperUIsave, true);
3. implemented custom IUIX_CmdHandler for "saveAs" command.
3.1. Inside OnGetItemState :
3.1 Get to IPXV_DocumentView via Inst.GetDocViewFromUIObj(pOwner, true)
3.3 Return UIX_CmdItemState_Disabled if IPXV_DocumentView.Doc.CoreDoc.GetOperationRestriction(Perm_ObjDoc, Perm_OperUIsave)

This does the trick.

Still, I'd like to know if there's a more straight forward approach - without needing to custom handle command via IUIX_CmdHandler (that is via "SecPermMask" in CreateOpenDocParams)?

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

Re: Disable Save As / Save Copy As via CreateOpenDocParams

Post by Tracker Supp-Stefan »

Hello zarkogajic,

Glad to hear you've found a solution - and I will pass your question to our devs for further clarification!

Kind regards,
Stefan
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2351
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Disable Save As / Save Copy As via CreateOpenDocParams

Post by Vasyl-Tracker Dev Team »

Hi Zarko.

I guess the better way in your case is to just override the cmd-handler for cmd.save, cmd.saveAs, cmd.saveCopyAs commands like this(pseudocode):

Code: Select all

class myCmdHandler : IUIX_CmdHandler
{
	public IUIX_CmdHandler  original;

	void OnCreateNewCtl(IUIX_Cmd pCmd, IUIX_CmdBar pParent, out IUIX_Obj pCtl)
	{
		original.OnCreateNewCtl(pCmd, pParent, pCtl);
	}
	void OnGetCtlSizes(IUIX_CmdItem pItem, ref tagSIZE nSize, ref tagSIZE nMinSize, ref tagSIZE nMaxSize)
	{
		original.OnCreateNewCtl(pItem, nSize, nMinSize, nMaxSize);
	}
	void OnGetItemSubMenu(IUIX_CmdItem pItem, out IUIX_CmdMenu pSubMenu)
	{
		original.OnGetItemSubMenu(pItem, pSubMenu);
	}
	void OnNotify(int nCode, IUIX_Cmd pCmd, IUIX_CmdItem pItem, IUIX_Obj pOwner, PARAM_T nNotifyData);
	{
		original.OnNotify(nCode, pCmd, pItem, pOwner, nNotifyData);
	}
	void OnDrawItemIcon(IUIX_RenderContext pRC, IUIX_CmdItem pItem, ref tagRECT stIconRect, ref tagRECT stClip)
	{
		original.OnDrawItemIcon(pRC, pItem, stIconRect, stClip);
	}
	void OnGetItemState(IUIX_Cmd pCmd, IUIX_CmdItem pItem, IUIX_Obj pOwner, out int nState)
	{
		original.OnCreateNewCtl(pCmd, pItem, pOwner, nState);
		if (nState != UIX_CmdItemState_Disabled)
		{
			IPXV_DocumentView docView;
			pxvInst.GetDocViewFromUIObj(pOwner, false, out docView);
			if (docView != null)
			{
				if (!CanSaveDoc(docView.Doc))
					nState = UIX_CmdItemState_Disabled;
			}
		}
	}
}
..................
string cmdNames[] = { "cmd.save", "cmd.saveAs", "cmd.saveCopyAs" };

myCmdHandler myCmdHandler = null;

for (cmdName : cmdNames)
{
	cmd = uiInst.CmdManager.Cmds.Find(cmdName);
	if (cmd != null)
	{
		if (myCmdHandler == null)
		{
			myCmdHandler = new myCmdHandler;
			myCmdHandler.original = cmd.Handler;
		}
		cmd.Handler = myCmdHandler;
	}
}
Cheers.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Disable Save As / Save Copy As via CreateOpenDocParams  SOLVED

Post by zarkogajic »

Hi Vasyl,

Thanks. This *is* what I am doing atm - check my second post in this topic :)

-žarko
User avatar
TrackerSupp-Daniel
Site Admin
Posts: 8371
Joined: Wed Jan 03, 2018 6:52 pm

Disable Save As / Save Copy As via CreateOpenDocParams

Post by TrackerSupp-Daniel »

:)
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Post Reply