EncodeForHTML & HTMLEditFormat: Formatting is different when exporting to pdf

Explorer ,
Apr 26, 2016 Apr 26, 2016

Copy link to clipboard

Copied

I am using ColdFusion 11 and have just started using the EncodeForHTML function instead of HTMLEditFormat whenever I need to display text that the user has entered, usually via a textarea.  We need to save the formatting so that information the user has entered remains understandable.  Users have a choice of whether to display the info to the screen or export to a pdf.  We are using EncodeForHTML to make the displayed info safer and we are using <pre> to retain the required formatting.

My problem is that when I need to export the data to a pdf, then EncodeForHTML acts differently than HTMLEditFormat does.  For some reason, I get extra lines inserted.

Here's some sample code.  Just save to a cfm and run:

-------------------------------------------------------

<cfsavecontent variable="f">This is my sample data.
Value 1  20%
Value 2  30%
Value 3  50%

Here's my summary of this data.
</cfsavecontent>

<cfhtmltopdf saveasname="MyTest.pdf">
<cfoutput>With EncodeForHTML: <pre>#encodeForHTML(f)#</pre></cfoutput>
<cfoutput>With HTMLEditFormat: <pre>#HTMLEditFormat(f)#</pre></cfoutput>
</cfhtmltopdf>

----------------------------------------------------------

The HTMLEditFormat version shows up correctly.  Any idea how to work around this problem?

TOPICS
Advanced techniques

Views

988

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Apr 27, 2016 Apr 27, 2016
If you temporarily comment out the cfhtmltopdf tag and run the page, you will see the reason for the difference. The function encodeForHTML outputs extra encodings, like &#xd;, &#xa; and so on. One way to solve the problem is to use the canonicalize function, for example,<cfhtmltopdf saveasname="MyTest.pdf"><cfoutput>With EncodeForHTML: <pre>#canonicalize(encodeForHTML(f),false,false)#</pre>With HTMLEditFormat: <pre>#HTMLEditFormat(f)#</pre></cfoutput></cfhtmltopdf>

Likes

Translate

Translate
Adobe Community Professional ,
Apr 27, 2016 Apr 27, 2016

Copy link to clipboard

Copied

If you temporarily comment out the cfhtmltopdf tag and run the page, you will see the reason for the difference. The function encodeForHTML outputs extra encodings, like &#xd;, &#xa; and so on.

One way to solve the problem is to use the canonicalize function, for example,

<cfhtmltopdf saveasname="MyTest.pdf">

<cfoutput>With EncodeForHTML: <pre>#canonicalize(encodeForHTML(f),false,false)#</pre>

With HTMLEditFormat: <pre>#HTMLEditFormat(f)#</pre></cfoutput>

</cfhtmltopdf>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 27, 2016 Apr 27, 2016

Copy link to clipboard

Copied

Combining functions can be overkill. Looking again at this, it could be simpler.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 27, 2016 Apr 27, 2016

Copy link to clipboard

Copied

So...what would be the simpler way to do it?  We just upgraded from CF8 to CF11, so I'm new to these functions and am just figuring out all their ramifications.  I tried your canonicalize suggestion and it worked.  However, if there's a simpler way, I'd like to try that before changing everything.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 27, 2016 Apr 27, 2016

Copy link to clipboard

Copied

I would suggest you go with just one function, for example, the simpler one, HTMLEditFormat.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 27, 2016 Apr 27, 2016

Copy link to clipboard

Copied

LATEST

Except that according to ColdFusion Help | Deprecated Features HTMLEditFormat is deprecated.  So that'll just be a short term solution.  Thanks for your help though.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines