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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |