开发者

How to show the special characters like & in the pdf report generated by iTextSharp?

开发者 https://www.devze.com 2023-02-18 17:50 出处:网络
While generating pdf reports programatically by using iTextSharp, I have to print the & in the report. But when i type this(&) in the pdf templates used by ItextSharp it is marked as an error.

While generating pdf reports programatically by using iTextSharp, I have to print the & in the report. But when i type this(&) in the pdf templates used by ItextSharp it is marked as an error. The error shows on mouse hover is "Character '', hexadecimal value 0x20 is illegal in an XML name.".

Can anyone let me know how to开发者_开发问答 achieve this???

thanks in advance.


I'd imagine that you need to HTML encode any literal text you're trying to insert - & would generally be interpreted as the start of an entity, and should normally be encoded as &. There's support for HTML encoding in HttpServerUtility.HtmlEncode.

However, we do need to be careful here, since the reported error concerns an XML error, and the list of named entities differs between HTML and XML. I've just been looking in the System.Xml namespace, and can't find any class that specifically helps you produce valid XML data - you might alternatively choose to place your text literals inside a CDATA (<![CDATA[, ]]>) section.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号