Hi Support,
Is there a way to disable executing JavaScript, at document opening, for a document via CreateOpenDocParams (or any other means)?
More info: I'm opening a document in "read-only" mode using SecPermMask.PermF_All - all works as expected - the user cannot alter the document in any way.
However if a document has some JS which gets executed during opening of document - and that JS alters the document - the document would be marked as "changed" - and trying to close the document would bring up "document was changed" - and I do not want that.
What I can do, is the following: just after a call to IPXV_MainFrame.OpenDocFrom I can:
if IPXV_Document.CoreDoc.SrcInfo.IsDirty then IPXV_Document.SetModified(false, IPXV_Document.ModificationLevel);
The result is kind of ok as the document is no longer treated as "Dirty" by UI (even though the CoreDoc.SrcInfo.IsDirty still returns true) and closing the document will not bring the "document changed" dialog.
I would be more happy with a more specific event: JS_executed_at_document_open -> mark document as not modified ...
To make it more clear: I'm ok with the JS being executed as this is what the creator of the PDF wanted - but I do not want the UI to treat the document as changed and ask to save changes (as the idea is "read only opening")..
p.s.
[edit] I know I can do "Inst.Settings[JavaScript.Enable] = false" - but I do not want to disable JS in general. I need to disable it per document upon document opening....
-žarko
CreateOpenDocParams - how to disable JavaScript ?
Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange
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.
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.
-
- User
- Posts: 1473
- Joined: Thu Sep 05, 2019 12:35 pm
-
- Site Admin
- Posts: 2445
- Joined: Thu Jun 30, 2005 4:11 pm
Re: CreateOpenDocParams - how to disable JavaScript ?
You may try to handle the 'e.document.beforeRunAction' event from the doc you are opening:
Code: Select all
private void OnEvent(int id, IEvent e, object from)
{
if (id == id_e_document_beforeRunAction)
{
IPXV_DocActionEvent de = (IPXV_DocActionEvent)e;
if (de != null && de.TriggerClass == PXV_ActionTriggerClass.PAEC_Doc && de.TriggerSubclass == PXV_ActionTriggerSubclass.PAESC_Open)
{
if (de.Action.Type == (uint)pxsInst.StrToAtom("JavaScript"))
{
// prevent action
e.Handled = true;
e.Result = 1;
}
}
}
}
PDF-XChange Co. LTD (Project Developer)
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
-
- User
- Posts: 1473
- Joined: Thu Sep 05, 2019 12:35 pm
Re: CreateOpenDocParams - how to disable JavaScript ?
Hi Vasyl,
That's it, thanks.
Edit: Ill actually be using e_document_afterRunAction (not e_document_beforeRunAction) and allow those JS scripts to run. Then if doc.Modified -> setting to false.
Please confirm: PAEC_Doc AND PAESC_Open "only maps to" JavaScript done at opening the document? That is "IPXV_DocActionEvent.Action.Type == JavaScript" only possible.
Or are some other actions types also possible when PAEC_Doc AND PAESC_Open?
Also: e.document.[before|after]RunOpenScripts is for this (?):
-žarko
That's it, thanks.
Edit: Ill actually be using e_document_afterRunAction (not e_document_beforeRunAction) and allow those JS scripts to run. Then if doc.Modified -> setting to false.
Please confirm: PAEC_Doc AND PAESC_Open "only maps to" JavaScript done at opening the document? That is "IPXV_DocActionEvent.Action.Type == JavaScript" only possible.
Or are some other actions types also possible when PAEC_Doc AND PAESC_Open?
Also: e.document.[before|after]RunOpenScripts is for this (?):
-žarko
You do not have the required permissions to view the files attached to this post.