Pasting an Image and Repositioning it with VBA

New Here ,
Feb 13, 2020 Feb 13, 2020

Copy link to clipboard

Copied

I have a problem that I've been stuck on all day and I would appreciate any help.

 I have a vba macro that I've written in excel that opens a pdf in Acrobat and pastes the contents of a cell into the PDF as an image.

My problem is at that point I want to be able to move the image to a different position within the PDF page.  I can select the annotation using like so:

 

PDFPage = doc.AquirePage(PDFview.GetPageNum)
Set annot = PDFPage.GetAnnot(0)

 

However, there doesn't appear to be any settings that can be used with this variable to determine position.

I cannot use the function jso.getAnnot to set a variable because I do not know the name of the annotation.  I have attempted to use the function jso.getAnnots() like so:

 

Private AcroApp As Acrobat.CAcroApp
Private doc As Acrobat.CAcroPDDoc
Dim jso As Object
Dim Annotations() As Variant

Set AcroApp = CreateObject("AcroExch.App")
Set doc = CreateObject("AcroExch.PDDoc")
Set AVDoc = CreateObject("AcroExch.AVDoc")
If AVDoc.Open(sPath, "") = True Then
  Set doc = AVDoc.GetPDDoc
End If
AcroApp.Show
ThisWorkbook.Sheets("table").Range("R1").Copy
AcroApp.MenuItemExecute("Paste")

Set jso = doc.GetJSObject
Annotations = jso.getAnnots()
debug.print UBound(Annotations)

 

  However, my debug print is returning a length of zero for Annotations, so I've clearly done something wrong there.

 

I would be grateful for any help.

TOPICS
Acrobat SDK and JavaScript

Views

364

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 , Feb 18, 2020 Feb 18, 2020
For the JSO: Using JavaScript from VBA is problematic in particular for objects. Because the JavaScript objects are not really compatible with VB objects. Especially for objects connected to the Acrobat DOM, such as annotations.  If you want to go this route it is better to write folder level JavaScript functions to do the heavy lifting so no complex operations or objects are handled on the VB side.   However, the PDAnnot object in VB has both setRect and getRect functions, so you already have...

Likes

Translate

Translate
New Here ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

Is there anyone who is able to help me with this?

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 ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

For the JSO: Using JavaScript from VBA is problematic in particular for objects. Because the JavaScript objects are not really compatible with VB objects. Especially for objects connected to the Acrobat DOM, such as annotations.  If you want to go this route it is better to write folder level JavaScript functions to do the heavy lifting so no complex operations or objects are handled on the VB side.  

 

However, the PDAnnot object in VB has both setRect and getRect functions, so you already have a way to set the stamp position. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Feb 20, 2020 Feb 20, 2020

Copy link to clipboard

Copied

LATEST

Thank you very much for your help.  I was able to use setRect to meet my needs.

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