How to check if a PDF Page has no annotations like comments or Fill and Sign

New Here ,
Jul 02, 2019 Jul 02, 2019

Copy link to clipboard

Copied

Hello,

is it possible to check if a PDF page has no annotations like comments of Fill and Sign. I'm working with Adobe Acrobat and VBA.

I need a function with result =  false if there is no Comment or Fill and Sign on a page of a PDF document. I hope someone can help me with a little bit code.

Best Regards from Germany

Josua

TOPICS
Acrobat SDK and JavaScript

Views

884

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Jul 04, 2019 Jul 04, 2019
You can use the VB Javascript bridge. Documentation is in the Acrobat SDK.

Likes

Translate

Translate
Adobe Community Professional ,
Jul 04, 2019 Jul 04, 2019

Copy link to clipboard

Copied

With Acrobat Javascript you can test/check the annotations.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 04, 2019 Jul 04, 2019

Copy link to clipboard

Copied

Hello Bernd,

thanks for your answer. How can I implement it in VBA?

Best Regards

Josua

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 04, 2019 Jul 04, 2019

Copy link to clipboard

Copied

You can use the VB Javascript bridge. Documentation is in the Acrobat SDK.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 05, 2019 Jul 05, 2019

Copy link to clipboard

Copied

Is it really possible to use Acrobat javasript Bridge with VBA or only with VB?

Best Regards

Josua

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 05, 2019 Jul 05, 2019

Copy link to clipboard

Copied

It should work with VBA.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 06, 2019 Jul 06, 2019

Copy link to clipboard

Copied

Hi Bernd,

I use reference in Excel VBE to Adobe Acrobat 10.0 Type Library. Is this enough or do I need a reference to

Microsoft Script Control 1.0, too?  Perhaps you have a little bit code for me to check if a PDF Page has no comments/annotations.

Best Regards

Josua

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 06, 2019 Jul 06, 2019

Copy link to clipboard

Copied

The JavaScript code is very simple. Let's say you want to check it for page 1 of the file. You can use this code to do it:

this.syncAnnotScan();

var annots = this.getAnnots({nPage: 0});

if (annots==null || annots.length==0) app.alert("There are NO annotations on this page.");

else app.alert("There are annotations on this page.");

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

Thank you so much for this JavaScript Code.  I'm looking exactly for this.

But how can I execute or call this JavaSripct Code in my VBA Code? And the second question is I would like

to set my boolean variable blnAnnotaions to false or true regarding from the result of the variable annots from your JavaScript Code.

Sub CheckPDFAnnotations()

Dim App As Acrobat.CAcroApp
Dim PDDoc As Acrobat.CAcroPDDoc
Dim i As Long

Dim blnAnnotations as Boolean

Set App = CreateObject("AcroExch.App")
Set PDDoc = CreateObject("AcroExch.PDDoc")
PDDoc.Open ("C:\Users\Josua\Documents\Test01.pdf")

End Sub

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

Use a folder level function with the Javascript code and call the function.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

Does it mean I put the 4 lines of javasript code

this.syncAnnotScan(); 

var annots = this.getAnnots({nPage: 0}); 

if (annots==null || annots.length==0) app.alert("There are NO annotations on this page."); 

else app.alert("There are annotations on this page.");

in a plain text editor and save the file for instance as  CheckAnnot.js    (javasript file).

Can I save this file in some Directory or in a Special Directory? Or what do you mean exactly with Folder Level function?

How Looks then the call in VBA for my example?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

If you put it in a folder-level script it needs to be inside a function, which you then call from your code.

The function could be something like this:

function CheckAnnots(doc, nPage) {

    doc.syncAnnotScan();

    var annots = doc.getAnnots({nPage: nPage});

    if (annots==null || annots.length==0) return false;

    else return true;

}

You then can call it like this:

var bAnnotations = CheckAnnots(this, 0);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

Now I have a file  CheckAnnots.js with the following code in C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts

function CheckAnnots(doc, nPage)

doc.syncAnnotScan();  

var annots = doc.getAnnots({nPage: nPage});  

if (annots==null || annots.length==0) return false; 

else return true; 

app.addMenuItem({cName: "check", cParent: "File", cExec: "CheckAnnots()"});

I hope this is correct?

My VBA Code is

Sub CheckPDFAnnotations()

Dim App As Acrobat.CAcroApp
Dim PDDoc As Acrobat.CAcroPDDoc
Dim i As Long
Dim jso As Object

Dim blnAnnotations As Boolean

Set App = CreateObject("AcroExch.App")
Set PDDoc = CreateObject("AcroExch.PDDoc")
PDDoc.Open ("C:\Users\Josua\Documents\Test01.pdf")

Set jso = PDDoc.GetJSObject

blnAnnotations = CheckAnnots(this, 0)

End Sub

But something must be wrong with Syntax   CheckAnnots(this,0)   ?

I think this is not correct or I Need   jso.CheckAnnots, too?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

I can't help you with the VBA code, I'm afraid, but my guess is that the "this" keyword is the issue.

In JS it refers to the document, but probably not in VBA. I think you should replace it with the reference to your document (possibly PDDoc). You probably should also refer the jso object when calling the CheckAnnots function, yes. But again, I can't help with the exact syntax.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

PS. You don't need to use the addMenuItem command. You're not going to access it that way, and even if you did, it has no output, so it wouldn't matter anyway.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

I deleted the addMenuItem command in my  CheckAnnots.js [in C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts]

Thanks for this tipp. That's my js function:

function CheckAnnots(doc, nPage)

doc.syncAnnotScan();  

var annots = doc.getAnnots({nPage: nPage});  

if (annots==null || annots.length==0) return false; 

else return true; 

My VBA Code is

Sub CheckPDFAnnotations()

Dim App As Acrobat.CAcroApp
Dim PDDoc As Acrobat.CAcroPDDoc
Dim i As Long
Dim jso As Object

Dim blnAnnotations As Boolean

Set App = CreateObject("AcroExch.App")
Set PDDoc = CreateObject("AcroExch.PDDoc")
PDDoc.Open ("C:\Users\Josua\Documents\Test01.pdf")

Set jso = PDDoc.GetJSObject

blnAnnotations = jso.CheckAnnots("C:\Users\Josua\Documents\Test01.pdf", 0)

End Sub

But the last row     jso.CheckAnnots("C:\Users\Josua\Documents\Test01.pdf", 0)    does not work.

The Call of the js function from VBA hat to be changed? Perhaps someone can help me?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

The first parameter needs to be a Document object, not the path to one.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

I change the last line to

blnAnnotations = jso.CheckAnnots(PDDoc, 0)

but I get a error message  "types incompatible   run time error 13".

The call of CheckAnnots doesn't work. I need something other for the call of the js function. I hope someone can help me?

I hope the js function is correct from syntax, too.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

Or do I need a reference to Microsoft Script Control 1.0, too for a call of CheckAnnots?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

I can't help you further, I'm afraid.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

The JS code seems correct and should work just fine. You can test it from the JS Console in Acrobat, by running this code, for example:

CheckAnnots(this, 0);

It should return either "true" or "false".

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

We have a correct js function and the directory is correct, too. Now we need the last step: The call

of this js function in VBA.

Perhaps this is one way: If you look at this small code example. It works without js file. the js code is inside vba.

Public Sub x()

     Dim jsObj As New ScriptControl

     jsObj.Language = "JScript"

     With jsObj

         .AddCode "function x(a,b) {return 'the answer is:' +(a+b);}"

         Debug.Print .Run("x", 1, 2)

     End With

End Sub

I hope I can put our js function in a smilar way like this:

Sub CheckPDFAnnotations2()

Dim App As Acrobat.CAcroApp
Dim PDDoc As Acrobat.CAcroPDDoc
Dim i As Long
Dim jso As Object
Dim blnAnnotations As Boolean

Set App = CreateObject("AcroExch.App")
Set PDDoc = CreateObject("AcroExch.PDDoc")
PDDoc.Open ("C:\Users\Josua\Documents\Testen\Test01.pdf")

Dim jsObj As New ScriptControl
jsObj.Language = "JScript"


jsObj.AddCode "Function CheckAnnots(doc, nPage) {doc.syncAnnotScan();var annots = doc.getAnnots({nPage: nPage});if (annots==null || annots.length==0) return false;else return true;}"

blnAnnotations = jsObj.Run("CheckAnnots", PDDoc, 0)

End Sub

But in the line  jsObj,AddCode are Syntax Errors (forget ; )

Perhaps someone in this Forum has experience and can help me. I would be so nice.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

Why do you use jsObj.Language?

Where is AddCode defined?

These two look like they belong to Microsoft JScript scripting, not Acrobat. Don't program Acrobat with Google! Use only the SDK!

Why is there a capital F on Function?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

ok, I learnt I don't Need  script control v1 in VBE, only acrobat.  Then I need a solution

for the call

blnAnnotations = jso.CheckAnnots(PDDoc, 0)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines