Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

HTML to PDF <pre> tag not converting well

Avatar

Level 2

Hi,

I am converting emails to PDF.  Sometimes it comes in as text, and i need to convert to HTML first.

So to avoid losing the formatting,I surround it with <pre></pre>.

But that means if they didn’t have word-wrap  on when they wrote the email, it will be one long line, causing the font to  scale down, sometimes to size 1 or 2.

I've tried a lot of HTML that adds wordwrapping as a style, and it works for web browsers, but it either gets cut off or the text shrinks.  It seems to be an Adobe bug, because no amount of CSS wizardry fixes it.

<html>
<body style="font-family: Trebuchet MS, Arial, Helvetica, sans-serif;font-size: 14px;color: #000;white-space: normal;">

<pre style="overflow-x: auto;white-space: pre-wrap;white-space: -moz-pre-wrap !important;white-space: -pre-wrap;white-space: -o-pre-wrap;width: 99%;word-wrap: break-word;font-family: Trebuchet MS, Arial, Helvetica, sans-serif; font-size: 14px;color: #000;">

Good day

BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH


Kind regards
John Smith


</pre>

</body>

</html>

1 Reply

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