Search code examples
javascriptformattingadobeacrobat

How to set rich text indentation via Acrobat JS?


I'm attempting to create a text box in Acrobat that includes hanging indents at the start of each paragraph in order to follow the style of the preceding (fixed) text. I want to be able to use Javascript to make this happen, but I can't figure out how exactly this is stored.

It appears that Acrobat stores rich text in an array of Aggregate objects (which are not mentioned explicitly in the documentation), but there doesn't seem to be anything in the objects or in the field itself that would store such a value. Exporting to an XFDF file does reveal tags containing a text-indent attribute, but there's nothing showing up on the debugger that corresponds to that.

Example:

<field name="Facts">
    <value-richtext>
    <body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acroform:2.7.0.0" xfa:spec="2.1">
    <p dir="ltr" style="margin-top:0pt;margin-bottom:0pt;text-indent:-18pt;font-family:Arial;font-size:10.9pt">
    5.<span style="xfa-spacerun:yes">   </span><span style="font-size:11pt">(insert long text here)<span style="xfa-spacerun:yes"> </span></span>
</p></body>
</value-richtext></field>

I would love to show the output of object.entries() for each Aggregate object, but that doesn't seem to work in Acrobat. At any rate, object.text-indent returns undefined.


Solution

  • You can't... at least not programmatically in Acrobat JavaScript. The Span object has a more restrictive set of properties to set than what is available via the Properties toolbar. The only properties you can set via JavaScript on a particular Span are alignment, fontStyle, subscript, textColor, fontFamily, fontWeight, superscript, textSize, fontStretch, strikethrough, text, underline

    See documentation for more info: https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_API_AcroJS%2FSpan_properties.htm