pdf - How to add a rich Textbox (HTML) to a table cell? -
i have rich text box named:”documentcontent” i’m going add content pdf using below code:
itextsharp.text.font font = fontfactory.getfont(@"c:\windows\fonts\arial.ttf", basefont.identity_h, basefont.embedded, 12f, font.normal, basecolor.black); documentcontent = system.web.httputility.htmldecode(documentcontent); chunk chunkcontent = new chunk(documentcontent); chunkcontent.font = font; phrase phrasecontent = new phrase(chunkcontent); phrasecontent.font = font; pdfptable table = new pdfptable(2); table.widthpercentage = 100; pdfpcell cell; cell = new pdfpcell(new phrase(phrasecontent)); cell.border = rectangle.no_border; table.addcell(cell);
the problem when open pdf file content appears html not text below:
<p>overview  line1 </p><p>overview  line2 </p><p>overview  line3 </p><p>overview  line4</p><p>overview  line4</p><p>overview  line5 </p>
but should below
overview line1 overview line2 overview line3 overview line4 overview line4 overview line5
what i'm going keep styling user apply rich text , change font family arial.
i can change font family need decode content html text.
could please advise? thanks
please take @ htmlcontentforcell example.
in example, have html mention:
public static final string html = "<p>overview line1</p>" + "<p>overview line2</p><p>overview line3</p>" + "<p>overview line4</p><p>overview line4</p>" + "<p>overview line5 </p>";
we create font <p>
tag:
public static final string css = "p { font-family: cardo; }";
in case, may want replace cardo
arial
.
note registered regular version of cardo
font:
fontfactory.register("resources/fonts/cardo-regular.ttf");
if need bold, italic , bold-italic, need register fonts of same cardo
family. (in case of arial, you'd register arial.ttf, arialbd.ttf, ariali.ttf , arialbi.ttf).
now can parse html , css list of element
objects parsetoelementlist()
method. can use these objects inside cell:
pdfptable table = new pdfptable(2); table.addcell("some rich text:"); pdfpcell cell = new pdfpcell(); (element e : xmlworkerhelper.parsetoelementlist(html, css)) { cell.addelement(e); } table.addcell(cell); document.add(table);
see html_in_cell.pdf resulting pdf.
i not have time/skills provide example in itextsharp, should easy port c#.
Comments
Post a Comment