Get has User/Owner password, what document permissions are allowed/disallowed  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

Get has User/Owner password, what document permissions are allowed/disallowed

Post by zarkogajic »

Hi support,

Having an IPXC document open, how do I get if it has a user (open) password, if it has an Owner password, what security permissions are set, and alike...

That is, this:

image.png

And also this:

image.png

p.s.
Smells like PXC_PermsFlags but I do not see what method reads them.


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

Re: Get has User/Owner password, what document permissions are allowed/disallowed

Post by zarkogajic »

Hi support,

ping...

Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Get has User/Owner password, what document permissions are allowed/disallowed

Post by Sasha - Tracker Dev Team »

Hello žarko,

As for the password, I've redirected this question to the appropriate developer.
To check the permissions, you will have to use the https://sdkhelp.pdf-xchange.com/vi ... Permission method.
Maybe the reason why do you need this can ease up the answer to your requirements.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Get has User/Owner password, what document permissions are allowed/disallowed

Post by zarkogajic »

Hi Alex,

Thanks, I've figured out this has to do with Perm_ObjDoc and then checking for various PXC_RequestOper's.

The thing is I have to go one by one and check what each returns - and then go back to my PDF to re-set some permissions and re-check again - so I was hoping for a "matrix" between those enum values and how they map to various permissions.

Say I can figure what Perm_OperCopy is for ("Content copying"), but "Perm_OperSecure" - I have no idea what would that be (even in PDF specs)

Why: because I need to know what is restricted in a document and if there is an open (and/or owner) password.

-žarko
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Get has User/Owner password, what document permissions are allowed/disallowed

Post by Sasha - Tracker Dev Team »

Hello žarko,

Here's what's available.
To check whether the document is password protected, you should get the IPXC_SecurityHandler and then get the type of it by using the GetSecurityHandlerType method. If it's 0 - then there is no protection. If the returned type is equal to the Standard atom, then the document is password protected.
To get the permission flags, you should use this simple code:

Code: Select all

ULONG_T GetPermFlags(IPXC_Document* pRDoc)
{
    ULONG_T nRes = (ULONG_T)-1;
    CComPtr<IPXC_SecurityHandler> pHandler;
    pRDoc->GetSecurityHandler(VARIANT_TRUE, &pHandler);
    if (pHandler)
        pHandler->GetSecurityInfo(pRDoc, &nRes);
    return nRes;
}
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Get has User/Owner password, what document permissions are allowed/disallowed

Post by zarkogajic »

Hi Alex,

Thanks., will try...

Btw, the result of GetSecurityInfo is "nSecInfo" - what does it hold / return actually (I mean: what do to with that long value)? You said "permission flags" - so to compare the nSecInfo with what?


-žarko
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Get has User/Owner password, what document permissions are allowed/disallowed

Post by Sasha - Tracker Dev Team »

Hello žarko,

It returns flags. Here's the logic:
1) If the user password was specified for the document, the PXC_PermsFlags.PermF_Open flag will be present.
2) If the owner password was specified, the PXC_PermsFlags.
3) All of the other flags are used from the PXC_PermsFlags enumeration (also, many of them are equal to their PXC_SecurityPermissions representations:

Code: Select all

enum PXC_PermsFlags
{
	PermF_Open					= 0x01,					// The user can open and decrypt the document.
	PermF_Secure				= 0x02,					// The user can change the document's security settings

	PermF_Print					= Permit_Printing,		// 0x04
														// The user can print the document. Page Setup access is unaffected
														// by this permission, since that affects Acrobat's preferences - not
														// the document's. In the Document Security dialog, this corresponds
														// to the Printing entry.

	PermF_Edit					= Permit_Modification,	// 0x08
														// The user can edit the document more than adding or modifying
														// text notes (see also pdPermEditNotes). In the Document Security
														// dialog, this corresponds to the Changing the Document entry.

	PermF_Copy					= Permit_Copying_And_TextGraphicsExtractions,	// 0x10,
														// The user can copy information from the document to the clipboard.
														// In the document restrictions, this corresponds to the
														// Content Copying or Extraction entry.

	PermF_EditNotes				= Permit_Add_And_Modify_Annotations,	// 0x20,
														// The user can add, modify, and delete text notes (see also pdPermEdit).
														// In the document restrictions, this corresponds to the Authoring Comments and Form Fields entry.

	PermF_SaveAs				= 0x40,					// The user can perform a Save As.... If both pdPermEdit and pdPermEditNotes are disallowed,
														// Save will be disabled but Save As... will be enabled. The Save As... menu item is not
														// necessarily disabled even if the user is not permitted to perform a Save As....
														// note: This cannot be set by clients.

	PermF_Ext					= 0x80,

	// Added perm bits (PV2) used for standard security handler
	// These bits only applies to standard security handler and they are
	// used only when kenLength > 5 (40bits)
	// Note: When keyLength > 5 is specified, standard security handler willl
	// Encrypt Dict with Revision 3.  Rev 3 is support by Acrobat 5.0 and up.

	PrivPermF_FillandSign		= Permit_FormFilling,	// 0x100,
														// Overrides other PDPerm bits. It allows the user to fill in
														// or sign existing form or signature fields.

	PrivPermF_Accessible		= Permit_TextGraphicsExtractions,	// 0x200,
														// Overrides pdPermCopy to enable the Accessibility API.
														// If a document is saved in Rev2 format (Acrobat 4.0 compatible),
														// only the pdPermCopy bit is checked to determine the Accessibility API state.

	PrivPermF_DocAssembly		= Permit_Assemble,		// 0x400,
														// Overrides various pdPermEdit bits and allows the following
														// operations: page insert/delete/rotate and create bookmark and thumbnail.

	PrivPermF_HighPrint			= Permit_HighQualityPrinting,	// 0x800,
														// This bit is a supplement to pdPermPrint. If it is clear
														// (disabled) only low quality printing (Print As Image) is allowed. On UNIX
														// platforms where Print As Image doesn't exist, printing is disabled.

	// Added perm bit (PV3) used for standard security handler
	// These bits only apply to standard security handler Revision 4
	// R4 is support by Acrobat 6.0 and up.
	PermF_Owner					= 0x8000,				// The user is permitted to perform all operations, regardless of
														// the permissions specified by the document. Unless this
														// permission is set, the document's permissions will be reset to
														// those in the document after a full save.

	PrivPermF_FormSubmit		= 0x10000,				// This should be set if the user can submit forms outside of the browser.
														// This bit is a supplement to pdPrivPermFillandSign.

	PrivPermF_FormSpawnTempl	= 0x20000,				// This should be set if the user can spawn template pages. This bit will allow
														// page template spawning even if pdPermEdit and pdPermEditNotes are clear.

	PermF_All					= 0xFFFFFFFF,			// All permissions.

	PermF_Settable				= (PermF_Print + PermF_Edit + PermF_Copy + PermF_EditNotes),
														// The OR of all operations that can be set by the user in the
														// security restrictions (pdPermPrint + pdPermEdit + pdPermCopy + pdPermEditNotes).

	PermF_User					= (PermF_All - PermF_Open - PermF_Secure),
}
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Get has User/Owner password, what document permissions are allowed/disallowed

Post by zarkogajic »

Hi Alex,

I would need additional help here.

I have a document with no security and a document with an open password ("Standard" security).

For both the GetSecurityInfo returns $FFFFFFFF (that's PermF_All).


p.s.
What's the meaning of "true" value in a call to GetSecurityHandler for a CoreDoc (I've tried with both false and true and have same results)?

p.s.
I'm getting the CoreDoc from the ipxv_document - so loaded in the pxv_Control - open pwd specified while opening - if that makes any relevance.


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

Re: Get has User/Owner password, what document permissions are allowed/disallowed

Post by zarkogajic »

Hi support,

I'm completely lost here :(

I've (also) tried using CoreDoc's RequestPermission and GetOperationRestriction feeding both with values from PXC_RequestOper and PXC_SecurityPermissions enums.

Please note that while PXC_SecurityPermissions enum is defined, it is actually not used as a parameter in any of the above methods. Both accept PXC_RequestOper.

Whatever I try I'm receiving false results for my test document.

The only luck so far was to check if there's any security set on a document by the means of GetSecurityHandlerType.

Again: I simply need to know if there's an open/user password or if there's an owner password - and if it is what restirctions are set for a document. So, what is listed (for the start) here:

image.png

Here's what the GetOperationRestriction(Perm_ObjDoc, Permit_Printing) and the rest returns:

Code: Select all

Permit_Printing: True
Permit_Modification: True //expecting FALSE
Permit_Copying_And_TextGraphicsExtractions: True //IS THIS "Content Copying" and "Page Extraction" ?
Permit_Add_And_Modify_Annotations: False
Permit_FormFilling: False
Permit_TextGraphicsExtractions: False
Permit_Assemble: False
Permit_HighQualityPrinting: False
Permit_Nothing: False
Permit_All: False
Here's what RequestPermission(Perm_ObjDoc, Permit_Printing, nil) and the rest return:

Code: Select all

Permit_Printing: 0 //Perm_ReqDenied
Permit_Modification: 0
Permit_Copying_And_TextGraphicsExtractions: 0
Permit_Add_And_Modify_Annotations: 0
Permit_FormFilling: 3
Permit_TextGraphicsExtractions: 3 // Perm_ReqUnknownOperation !!?
Permit_Assemble: 3
Permit_HighQualityPrinting: 3
Permit_Nothing: 3
Permit_All: 3
p.s.
If needed I can send a few documents with some restrictions set ...

EU Editor displays Document Permissions under Security for Document Properties correctly - so I'm hoping I can get the same results from the SDK...

image.png

-žarko
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Get has User/Owner password, what document permissions are allowed/disallowed

Post by Sasha - Tracker Dev Team »

Hello žarko,

Forwarded this to one of my colleagues - probably he can tell more.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Get has User/Owner password, what document permissions are allowed/disallowed

Post by zarkogajic »

Hi support,

Any new info here?

Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Get has User/Owner password, what document permissions are allowed/disallowed

Post by Sasha - Tracker Dev Team »

Hello žarko,

Got a reply. My colleague is asking why exactly do you need this logic? Do you want to display your own likewise dialog or something?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Get has User/Owner password, what document permissions are allowed/disallowed

Post by zarkogajic »

Hi Alex,

Let's say "yes".

(I only need to "read" security settings / not "write")

Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Get has User/Owner password, what document permissions are allowed/disallowed  SOLVED

Post by Sasha - Tracker Dev Team »

Hello žarko,

I'm afraid that the API does not have the needed functionality to get all of the displayed info.
This is what you can use though and hopefully this will be enough for your needs (I will write in pseudo code):

Code: Select all

//For printing
if ((Perm_ObjDoc, Perm_OperPrintHigh) == Perm_ReqGranted)
	//HighRes
else if ((Perm_ObjDoc, Perm_OperPrintLow) == Perm_ReqGranted)
	//LowRes
else
	//Not Allowed
//All of the next data by index in list
(1, Perm_ObjDoc, Perm_OperModify);
(2, Perm_ObjPage, Perm_OperCreate);
(3, Perm_ObjDoc, Perm_OperCopy);
(4, Perm_ObjDoc, Perm_OperAccessible);
(5, Perm_ObjPage, Perm_OperExport);
(6, Perm_ObjAnnot, Perm_OperCreate);
(7, Perm_ObjForm, Perm_OperFillIn);
(8, Perm_ObjSignature, Perm_OperFillIn);
(9, Perm_ObjForm, Perm_OperSpawnTemplate);
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Get has User/Owner password, what document permissions are allowed/disallowed

Post by zarkogajic »

Hi Alex,

Thanks. This seems to be enough for the "document restrictions summary". So far, for a few tests, this suffices. :)

Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Get has User/Owner password, what document permissions are allowed/disallowed

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply