Using JSF PrimeFaces text editor how to add text to PDF using iText

We use the text editor JSF PrimeFaces. When we get String from a text editor with bean support, it also includes HTML tags. The following image may help in understanding this problem.

Below we write:

enter image description here

Below we have received:

enter image description here

The next thing we want to do is write what was written in a text editor, as is, in PDF using iText. But we don’t know how to convert this string (with HTML tags) to data only.

Below is the code:

enter image description here

+3
source share
2 answers

You can go to XMLWorkeriText. Below code will provide you content in orange

document.open();
String finall=  "<style>h1{color:orange;} </style><body><h1>This is a Demo</h1></body>";
InputStream is = new ByteArrayInputStream(finall.getBytes());
XMLWorkerHelper.getInstance().parseXHtml(pdfWriter,document, is);
document.close(); 

HTML , , PDF. , , XHTML , . , HTML <br>, <br/> , .

+4

JSoup . Jsoup

code

Jsoup.parse(textRecievedFromEditor).text();

HTML-.

e.g.

For example, given HTML {@code <p>Hello <b>there</b> now!</p>}, 
{@code p.text()} returns {@code "Hello there now!"}
+1

All Articles