开发者

Using an ampersand in flying saucer

开发者 https://www.devze.com 2023-01-08 09:45 出处:网络
I get the error below when converting to PDF with flying saucer. I\'ve removed the ampersand charector and it worked, so this seems to be the problem. How do I include ampersand\'s in my PDF documents

I get the error below when converting to PDF with flying saucer. I've removed the ampersand charector and it worked, so this seems to be the problem. How do I include ampersand's in my PDF documents? Thanks in advance.

ER开发者_JAVA技巧ROR: 'The entity name must immediately follow the '&' in the entity reference.'


Just replace & with &

NOTE:That won't work for filenames, just content.


Flying saucer parses only valid xhtml. With XML you would have to define your & entity. However, I've stopped trying to use & and have started using:

&

That is your ampersand that will work with xhtml, and it will work with Flying saucer to get the ampersand into the PDF.

Useful Reference: http://www.elizabethcastro.com/html/extras/entities.html


You need to escape any XML entities (gt, lt, quot, amp, apos). An easy and effective way to do this is by using the Apache Commons Lang library function StringEscapeUtils.escapeXML.


I had also this problem, but I solved it by surrounding the conflict characters (like &) with the

<![CDATA['&']]>

notation. Hope it helps as well, because the previous answers did not work for me.

0

精彩评论

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

关注公众号