Mirek
Mirek

Reputation: 391

iText - formatting the substring

Can I format the substring of some string (for example string for Paragraph - new Paragraph(someString) ) using any markers in Itext? Is something like that enabled?

For example: new Paragraph("Congrats, you've [formatMarker]gained[/formatMarker] the privilege") ?

Upvotes: 1

Views: 765

Answers (1)

Sean
Sean

Reputation: 7737

You can have iText parse HTML tags in order to format your text. Here is an example

Reader reader = new StringReader("<b>Here is Some HTML<b><h1>Hello World</h1>");
HTMLWorker worker = new HTMLWorker(document);
worker.parse(reader);

When you parse it adds your contents to the document. No need to store them in a Paragraph. If you want more functionality and control over the individual elements of the html, you can try using the static method HTMLWorker.parseList()

The API for iText is here http://api.itextpdf.com/itext/ and it has lots of details on both methods used above

Upvotes: 1

Related Questions