Avatar

Level 1

Hello,

 

I was running into the same issue with displaying text and HTML based emails in the same rich text field. I could not get a CSS/HTML solution, but replacing all newline characters worked to preserve the spacing.

 

Here is the function I use to properly process and display HTML in a rich text field.

function formatRichTextField(field) {
    var rawText = field.rawValue;
    rawText = rawText.replace(/\n/g, '<br />');
    var envelope = "<?xml version='1.0' encoding='UTF-8'?>" +
        "<exData contentType='text/html' xmlns='http://www.xfa.org/schema/xfa-template/2.8/'" +
        "><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'><div><pre>" + rawText + "</pre></div></body></exData>";

    field.value.exData.loadXML(envelope, 1, 1);
}

 

Credit here for the HTML to XHTML piece.

https://blogs.sap.com/2016/05/12/adobe-form-using-javascirpt/

 

Dominick