Skip to Content
Author's profile photo Former Member

Render HTML/Rich Text in Adobe form

Rendering HTML/Rich Text in Adobe Form is one of the common requirements people often have.

So here is the step by step process to achieve it. 

Do this in ABAP
1) Convert html to xstring – lv_html is your html string

DATA: lv_html TYPE string.
DATA(lv_len) = strlen( lv_html ).
DATA(lr_conv) = cl_abap_conv_out_ce=>create( ).
lr_conv->write( data = lv_html n = lv_len ).
DATA(lv_xstr) = lr_conv->get_buffer( ).

2) XFA doesn’t support most of the HTML tags so do the XSLT transformation for the tags you need

TRY.
     CALL TRANSFORMATION zhtml_xslt
          SOURCE XML lv_xstr
          RESULT XML lv_xstr.
   CATCH cx_transformation_error INTO DATA(lr_transformation_error).
ENDTRY.

3) Encode xstring to base64

CONSTANTS: lc_op_enc TYPE x VALUE 36.
DATA: lv_base64 TYPE string.
CALL ‘SSF_ABA_SERVICE’
      ID ‘OPCODE’ FIELD lc_op_enc
      ID ‘BINDATA’ FIELD lv_xstr
      ID ‘B64DATA’ FIELD lv_base64.

4) Example XSLT


<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
  <xsl:output encoding="UTF-8" indent="yes" method="xhtml" standalone="0" version="1.0"/>
  <xsl:strip-space elements="*"/>
  <xsl:variable name="vDelims" select="'- • # '"/>
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>
  <xsl:template match="h2">
    <b>
      <xsl:apply-templates select="@*|node()"/>
    </b>
  </xsl:template>
  <xsl:template match="ul">
    <p style="text-decoration:none;letter-spacing:0in">
      <xsl:apply-templates select="@*|node()"/>
    </p>
  </xsl:template>
  <xsl:template match="p">
    <p>
      <xsl:apply-templates select="@*|node()"/>
    </p>
  </xsl:template>
  <xsl:template match="li">
    <br/>
    <span style="xfa-tab-count:1">         </span>
    <xsl:text>
    </xsl:text>
    <xsl:for-each select="ancestor::ul">
      <xsl:text>  </xsl:text>
    </xsl:for-each>
    <xsl:value-of select="substring($vDelims,
              2*(1+count(ancestor::ul) mod 3) -1,
              2)"/>
    <xsl:value-of select="."/>
  </xsl:template>
</xsl:transform>

Do this in Adobe Form field’s javascript

1) Create a global variable “Base64” and paste the script from below link

     http://www.webtoolkit.info/javascript-base64.html

2) Write below code in the field’s javascript to decode base64


var b64 = this.rawValue;
var xhtml = base64.Base64.decode(b64);
this.value.exData.loadXML(xhtml);

3) Make sure the script is set to Run At Server, if it’s an interactive form

4) Make sure the field is rich text enabled

Regards,

Arshid

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Very innovative and good job. Thanks for sharing, this is really helpful, it would have been good if u had an image of the output also, and bit explanation on XSLT as to what tags are not compatible and replaced with what.

      regards,

      raghavendra

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Raghavendra,

      HTML tags available in XFA depends on the version of it, for example XFA 3.3 supports the HTML/XHTML tags only as mentioned on page 1187 of the below document

      https://partners.adobe.com/public/developer/en/xml/xfa_spec_3_3.pdf

      Example XSLT is for below tags only

      <h2>

      <p>

      <li>

      <ul>

      Thanks,

      Arshid