i'm using itextsharp create pdf using html page example. trying put border around text highlight items. using methods these posts (draw rect @ curr position, , add text on image ) have used ongenerictag events create rectangle each chunk matches criteria. event fires correctly , rectangles drawn on correct elements. problem occurs when add background tablecell, appears on top of chunk rectangles. there way make rectangle drawn ongenerictag
event drawn above table cell background?
ongenerictags method:
public class generictags : pdfpageeventhelper { public override void ongenerictag(pdfwriter writer, document pdfdocument, itextsharp.text.rectangle rect, string text) { if ("ellipse".equals(text)) //i know it's not needed. ellipse(writer.directcontent, rect); } public void ellipse(pdfcontentbyte content, itextsharp.text.rectangle rect) { content.savestate(); content.setrgbcolorstroke(0x00, 0x00, 0xff); content.setlinewidth(2); content.rectangle(rect.left - 2f, rect.bottom - 3f, rect.width, rect.height + 3f); content.stroke(); content.restorestate(); } }
each pdfpcell
defined as:
pdfpcell med = new pdfpcell(ph[4]) { horizontalalignment = element.align_center, verticalalignment = element.align_center, backgroundcolor = hm_yellow //this draws above rect ongenerictag() };
the chunks
created , assign via foreach
loop:
ph[j] = new phrase(); foreach (var x in p.risks) { c[i] = new chunk("r" + x.app_risk_id.tostring() + ", "); if (x.risk_status_cd == "57") { //c[i].setbackground(hm_top_tier); // still shows behind table cell background c[i].setgenerictag("ellipse"); } ph[j].add(c[i]); }
this html page i'm trying turn pdf. shows table cell background colors , values need have rectangle around them highlight them.
this result when rendering pdf. highlighted r#'s match, however, when apply background color pdfpcell
drawn on rectangle chunk
draw table using layer writer.directcontentunder
make sure rectangle stays on top (writer.directcontent
).