Skip to main content
RestonsIT
Participant
December 5, 2017
Question

Can I add rich text to a richtext-enabled FormField using VB?

  • December 5, 2017
  • 2 replies
  • 1380 views

I want to populate a richtext form field with a formatted string compiled by a vb.net app.

Dim pdDoc As New Acrobat.AcroPDDoc

pdDoc.Open("my.PDF")

Dim jso = pdDoc.GetJSObject

Dim myFld = jso.getField("MyFld")

Dim mySpans = myFld.richValue

Assuming that myField.value is "This is MY field", with "MY" in bold,

I get back 5 spans: "This is"," ","MY"," ","field", the fontWeight on all is 400 except for "MY" which is 700

I change mySpans(2).text from "MY" to "YOUR", and write the spans back:

myFld.richVale = mySpans

expecting to see "This is YOUR field", but I don't

Am I missing something here, or can I just not do it this way?

Had lots of experience setting value, font and sizes on fields - which I managed to decipher from "JavaScript for Acrobat  API Reference", but not this...

The examples I've found all refer to Java - nothing for VB (or even C#, which might have helped).

Any help much appreciated.

Thanks

Dave

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
December 5, 2017

Besides the typo Try pointed out. Spans are a type of JavaScript Object. JS objects and VB objects are different things and don't translate well. This is one of the more restrictive issues with the JSO.  The best solution is to only transfer scalar, string, and simple array values between JS and VB. 

The solution to dealing with this issue is to develop a set of folder level functions that preform the heavy lifting on the JS side. Then call these functions from VB. This is also more efficient, because all the JS stuff is being done in the JS world

Another major advantage of this approach is that you can test your methodology for modifying rich text on Acrobat without the added complication of VB.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
RestonsIT
RestonsITAuthor
Participant
December 6, 2017

Suppose I need to get my head round Java then.

Thanks.

Bernd Alheit
Community Expert
Community Expert
December 6, 2017

Info: Acrobat uses JavaScript, not Java.

Legend
December 5, 2017

Is richVale a typo only in the post?

RestonsIT
RestonsITAuthor
Participant
December 6, 2017