Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Dec 05, 2017 Dec 05, 2017

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

TOPICS
Acrobat SDK and JavaScript
1.3K
Translate
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 ,
Dec 05, 2017 Dec 05, 2017

Is richVale a typo only in the post?

Translate
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 ,
Dec 06, 2017 Dec 06, 2017

Translate
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
Community Expert ,
Dec 05, 2017 Dec 05, 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
Dec 06, 2017 Dec 06, 2017

Suppose I need to get my head round Java then.

Thanks.

Translate
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
Community Expert ,
Dec 06, 2017 Dec 06, 2017

Info: Acrobat uses JavaScript, not Java.

Translate
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
Community Expert ,
Dec 06, 2017 Dec 06, 2017
LATEST

As far as programming languages go, JavaScript is much better than VB. Do all your initial development in Acrobat Using JavaScript. When you have the functionality you want worked out, then go back to VB.

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

Translate
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