0

I have to create a pdf by using itextpdf api. I also have jsoup api in the project. I've managed to create a pdf meeting all the requirements for it except one thing. One column of cells in the pdf have to get their content text from the web-application UI from html-content. So, I get all the tags and all with them to the pdf. Like this:

enter image description here

Now I found a way to get rid of the tags by using Jsoup.parse(cellContentText).text();

However, there's no line changes or anything now. Would it be possible to get some of the html formatting to show in the pdf? If so, how?

Steve Waters
  • 3,348
  • 9
  • 54
  • 94
  • It's a rather nasty workaround, but maybe you should consider running over the text/input before the Jsoup.parse activity, replace
  • and/or
    tags with something else (special character or alike), and then, after Jsoup.parse - use that "something" to insert line break into your PDF.
  • – Ofer Lando Mar 04 '15 at 07:57
  • 1
    Please read the chapter "Parsing XML and XHTML" from the free ebook [The Best iText Questions on StackOverflow](http://pages.itextpdf.com/ebook-stackoverflow-questions.html). You have some HTML snippets and you want to convert these snippets into iText objects such as `Paragraph`, `List`, etc. If so, your question is a duplicate of [Add a rich Textbox to PDF using iTextSharp](http://stackoverflow.com/questions/27015644/add-a-rich-textbox-to-pdf-using-itextsharp) where we use XML Worker to parse an HTML snippet and some CSS into an `ElementList`. – Bruno Lowagie Mar 04 '15 at 14:14
  • Thanks a ton! Actually your HtmlContentForCell-example was perfect for me. Yesterday I went through examples that didn't quite fit my situation. http://itextpdf.com/sandbox/htmlworker/HtmlContentForCell – Steve Waters Mar 05 '15 at 06:40
  • @BrunoLowagie Well, actually I followed that example which seemed exactly to solve my problem but in the for loop for parsing the html snippet to element list I bumped into an exception: http://stackoverflow.com/questions/28871767/nonewlineparagraph-cannot-be-cast-to-element – Steve Waters Mar 05 '15 at 08:10
  • @BrunoLowagie Nevermind, I managed to solve that problem and ALL the different problems related to XMLWorker, by **updating the itextpdf and xmlworker to be the exact same version. ** This should be stressed somewhere :) – Steve Waters Mar 05 '15 at 12:23