These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Creating FreeText Annotation by Visual Basic

steff
Registered: Jan 4 2010
Posts: 2

Hi,

I try to create an OLE Connection between MS Access an Adobe Acrobat 8 to place a free text annotation to a PDF sheet that comes originally from a CAD application. I studied a lot of Acrobat references and SDK examples, but did not come to a solution at a certain point.
Have a look at my code example:

Set acroApp = CreateObject("Acroexch.App")
Set pdDoc = CreateObject("AcroExch.PDDoc")

Set Document = pdDoc.Open ("c:\Temp\Test.pdf")

set jso = Document.getJSObject

If Not jso Is Nothing Then
...
annot = jso.AddAnnot
props = annot.getProps
props.Type = "FreeText"
annot.setProps props

props = annot.getProps
props.page = 0
props.Rect = Rect
props.Contents = "I added this comment from Visual Basic!"
...
annot.setProps props

>> Free Text RTF Content <<

End If
pdDoc.Close

The Section between >> and << is the Problem. By Reading the JS-Reference I see that I have to transfer an array of RichText Objects to the annotation object like it is described in the "Java Script Reference Guide" (the array is named "spans" in the following example):

var annot = this.addAnnot({
page: 0,
type: "Text",
point: [72,500],
popupRect: [72, 500,6*72,500-2*72],
popupOpen: true,
noteIcon: "Help"
});
var spans = new Array();
spans[0] = new Object();
spans[0].text = "Attention:\r";
spans[0].textColor = color.blue;
spans[0].textSize = 18;

spans[1] = new Object();
spans[1].text = "Adobe Acrobat 6.0\r";
spans[1].textColor = color.red;
spans[1].textSize = 20;
spans[1].alignment = "center";
spans[2] = new Object();
spans[2].text = "will soon be here!";
spans[2].textColor = color.green;
spans[2].fontStyle = "italic";
spans[2].underline = true;
spans[2].alignment = "right";
// Now give the rich field a rich value
annot.richContents = spans;

My Problem is now that I don't have any idea how to construct and pass this Array of Objects in Visual Basic respectively in VBA. I even have found a note in the IAC Guide that the construction of objects within Acrobat's Java Script might be impossible from foreign programming.

Can anyone tell me more (maybe with example) how to pass a rich text content to an Free Text Annotation ? My favourite would be to do this all from VBA - if possible.

Thanks in advance
Steff

My Product Information:
Acrobat Standard 8.0, Windows
gwaddell
Registered: Jan 8 2010
Posts: 9
Hi
I was looking at this as well, as I wanted to put in OMR markings (lines that tell an OMR printer how to fold up pages and place them in envelopes) into Adobe documents for posting to clients

Please note, I was doing this in VB.Net not VB but is should be easy enough to transfer the code.

I couldn't get rich text just plain text and I did not use the JSObject but stuck with OLE.

Public Sub CreateOMR(byRef sfile as String) dim AVDoc, PDDoc, thePage, PageSize, Annot, Rect as  Objectdim destFile as stringdim destPageNum, intPage, PageHeight as integer AVDoc = CreateObject("AcroExch.AVDoc")PDDoc = CreateObject("AcroExch.PDDoc")destFile = Replace(sFile, ".pdf", "_OMR.pdf")If File.Exists(destFile) Then File.Delete(destFile)File.Copy(sFile, destFile)AVDoc.open(destFile, Dir(destFile))PDDoc = AcroAVDoc.GetPDDocdestPageNum = AcroPDDoc.GetNumPages - 1 'Number of pages in our doc (-1 as zero based index used for navigating pages) for intPage = 0 to destPageNum

thePage = PDDoc.AcquirePage(intPage)

'
Need to find page height as acrobat grid starts in bottom left cornerPageSize = thePage.GetSize()PageHeight = PageSize.y 'The Height of the page in points PageSize.x will give width'Assume 72 pt per inch - (from adobe example)Annot = CreateObject("AcroExch.PDAnnot")thePage.AddAnnot(-2, Annot)Annot = thePage.GetAnnot(0) 'adding Content as String of plain textAnnot.SetContent("My Text") Rect = Annot.GetRectWith Rect.Left = 3.3.right = 54If PageHeight > 253.85 Then.bottom = PageHeight - 253.85 'remember 0,0 is bottom left of adobe doc.Top = PageHeight - 163.75End IfEnd WithAnnot.SetRect(Rect)Annot.SetOpen(1) 'annotation is opened in rectangle when printingnextPDDoc.Save(PDSaveFlags.PDSaveFull, destFile)AVDoc.PrintPagesSilent(0, destPageNum, 2, False, False)

I hope this helps you