【发布时间】:2015-11-19 06:18:41
【问题描述】:
我的 asp 绑定域:
<asp:BoundField DataField = "SiteUrl" HtmlEncode="false" HeaderText = "Team Site URL" SortExpression = "SiteUrl" ></asp:BoundField>
我的 itextsharpcode
for (int i = 0; i < dtUIExport.Rows.Count; i++)
{
for (int j = 0; j < dtUIExport.Columns.Count; j++)
{
if (j == 1)
{ continue; }
string cellText = Server.HtmlDecode(dtUIExport.Rows[i][j].ToString());
// cellText = Server.HtmlDecode((domainGridview.Rows[i][j].FindControl("link") as HyperLink).NavigateUrl);
// string cellText = Server.HtmlDecode((domainGridview.Rows[i].Cells[j].FindControl("hyperLinkId") as HyperLink).NavigateUrl);
iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL);
font.Color = new BaseColor(domainGridview.RowStyle.ForeColor);
iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(12, cellText, font));
pdfTable.AddCell(cell);
}
}
domainGridview 是网格名称。但是我正在使用数据表处理 pdf。 超链接是这样来的
http://dtsp2010vm:47707/sites/TS1>http://dtsp2010vm:47707/sites/TS1
如何撕掉附加链接? 编辑:我添加了pdf文件的截图
【问题讨论】:
-
你能显示使用
cellText的值吗? iText 没有理由重复文本,因此问题可能是由于文本在cellText字符串中出现两次。 -
(谢谢布鲁诺!终于有人注意到了这个问题,而且 itextsharp 的所有者也是如此!我觉得有特权。再次感谢。) cellText 在创建新的 pdf 单元格时作为参数传递.在这一行: iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(12, cellText, font));此外,仅在超链接列中观察到重复性。我还有其他几列文本呈现得很好。
-
屏幕截图清楚地表明您正在将 HTML 字符串添加到
PDFCell。你不应该对这个 HTML 字符串是按字面添加的感到惊讶:你没有将 HTML 解析为 iText 对象。