Skip to main content
sylvainmi
Inspiring
November 27, 2018
Answered

OLE : remove security to addScript

  • November 27, 2018
  • 8 replies
  • 1909 views

Hi,

I am processing a collection of PDF files in which I execute a script for each 3D annotation found. However, some PDFs are secured and addScript method on Doc is throwing an exception : "NotAllowedError: Security settings prevent access to this property or method.".

Is it possible to remove the security to be able to call addScript?
The PDF file won't be saved at the end. Is there a way to open the PDF as a non-secured one, just the time to do the treatment?

Thank you in advance.

This topic has been closed for replies.
Correct answer sylvainmi

It seems to work fine except for PDFs that have no AcroForm/Fields.
It is strange that this method is put on Fields object instead of CAcroPDDoc.

Well, I guess I gonna go for a mix and hope there is no secured PDF with this case.

8 replies

Legend
November 28, 2018

ExecuteThisJavaScript is one of the IAC methods in the Acrobat IAC Reference. I saw it there, I never used it.

sylvainmi
sylvainmiAuthorCorrect answer
Inspiring
November 29, 2018

It seems to work fine except for PDFs that have no AcroForm/Fields.
It is strange that this method is put on Fields object instead of CAcroPDDoc.

Well, I guess I gonna go for a mix and hope there is no secured PDF with this case.

Legend
November 28, 2018

If addScript is viable, you should probably update your working practices to ensure that nobody is permitted to set document security - which has no value except as a nuisance to you.

sylvainmi
sylvainmiAuthor
Inspiring
November 28, 2018

addScript is viable only because we won't save the PDF after the tests. And it is a nuisance still.
The PDF are given to us by other companies, we don't and can't have control on the context or the security on those.ExecuteThisJavaScript'.

You were mentionning 'ExecuteThisJavaScript'. Where can I find this method?

Legend
November 28, 2018

Except for the startup scripts read once when Acrobat starts there is no provision to run a file in Acrobat JavaScript. But there's nothing to stop you reading a file and using ExecuteThisJavaScript from an external app (except the poor debugging).

Legend
November 28, 2018

Yes, GetJSObject is the bridge. No idea if it checks document security, sorry.

sylvainmi
sylvainmiAuthor
Inspiring
November 28, 2018

However, I can't execute a script right from a file. I could try to decypher the script file and "execute it" with bridge objects but I encounter another issue described there : https://forums.adobe.com/message/10776324#10776324

But I would rather have a script file used as-is to be executed since the script file returns data that is used for testing procedures. We will compare those results in the Acrobat context with results in another context. Using the same javascript file would guarantee the same input and avoid synchronization error between a script file and its C# equivalent of bridge objects.
I am not a native english speaker so I hope this makes sense to you.

lrosenth
Adobe Employee
Adobe Employee
November 28, 2018

Since you are building an application that a user must install, why not also install an application level script in Acrobat & call that via the bridge?

Legend
November 28, 2018

No, that's not the VB:JavaScript bridge.

sylvainmi
sylvainmiAuthor
Inspiring
November 28, 2018

No, it's a C#:Javascript bridge

Legend
November 28, 2018

Do you use the VB: JavaScript bridge?

sylvainmi
sylvainmiAuthor
Inspiring
November 28, 2018

C# :

AcroAVDoc document = new AcroAVDoc();

if (document.Open(a_pdfPath, ""))

{
    CAcroPDDoc pdDocument = (CAcroPDDoc)document.GetPDDoc();
    Object jsObject = pdDocument.GetJSObject();
    ...

Legend
November 28, 2018

Not if the PDF security forbids it.

sylvainmi
sylvainmiAuthor
Inspiring
November 28, 2018

The PDF does not forbid it since we can manually execute "Run a javascript" by using the contextual menu over a 3D annotation. We can also execute script commands inside the Javascript console.

However addScript method is forbidden. But we won't need it, if we can execute a javascript from an OLE program ordering the Javascript console or simulating a click on "Run a javascript".

Legend
November 27, 2018

1. Security belongs to the file as a whole rather than just the open document, so however you remove security you need to save the file before it takes effect.

2. There is no way for OLE to use the password to remove security, anyway. 

sylvainmi
sylvainmiAuthor
Inspiring
November 28, 2018

Is there a possibility to execute a script as if the user clicked "Run a javascript" on the 3D annotation in an OLE application ?

We were trying to make addScript works because it was the easiest access point, but maybe we can use another way to do it, either by this access, or the Javascript Debug console. Do you know if either of these ways are possible from an OLE application?