java - Parsing HTML snippets and adding to PdfPTable -
i creating pdf made of several pdfptables pdfcell's consist of simple phrases , others need parsed html snippets. create sure parsed html added needed styling , in right place have been storing in paragraph adding pdfpcell. doing causes me run issues when dealing html tags lists , quotes. below rough illustration of doing, can handle html lists, quotes, etc. ?
for example: itext handles html list , knows convert itext list/listitem. need add together list pdftable. know putting list element in paragraph cancels out proper styling (the entire list ends beingness on 1 line no numbering) , know proper way of handling
pdfptable table = new pdfptable(1); table.addcell(parsehtmltoparagraph(htmlstring)); table.addcell(new phrase("name" + user.getname()));
public paragraph parsehtmltoparagraph(string str) throws ioexception { stringreader body = new stringreader(str); final paragraph para = new paragraph(); xmlworkerhelper.getinstance().parsexhtml(new elementhandler() { @override public void add(writable w) { if (w instanceof writableelement) { list<element> elements = ((writableelement) w).elements(); (element e : elements) { para.add(e); } } } }, body); homecoming para; }
the reply simple: throwing away construction (such list structure), creating cell in text mode instead of creating cell in composite mode.
create cell this:
pdfpcell cell = new pdfpcell(); list<element> elements = ((writableelement) w).elements(); (element e : elements) { cell.addelement(e); }
you implicitly creating pdfpcell
instance using addcell()
method. passing paragraph
method, paragraph
casted phrase
. when implicitly create pdfpcell
phrase
, content nowadays in phrase
downgraded mere text elements.
java itext xmlworker
No comments:
Post a Comment