我的ASP的BoundField導出爲PDF:鏈接過來的兩倍,而使用iTextSharp的
<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 /網站/ TS1>http://dtsp2010vm:47707/sites/TS1
如何撕開addtional鏈接? 編輯:我已添加pdf文件的屏幕截圖
你可以顯示使用'cellText'的值? iText沒有理由重複文本,因此問題可能是由於文本在'cellText'字符串中出現了兩次。 –
(感謝布魯諾!最後有人注意到了這個問題,這也是itextsharp的擁有者!我感到Privilidged。再次感謝。)cellText是beng作爲參數傳遞,同時創建新的pdf單元格。在這一行中:iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(12,cellText,font));此外,僅在超鏈接列中才能觀察到重複。我有幾個其他專欄文本渲染就好了。 – Deepika
屏幕截圖清楚地表明您正在將HTML字符串添加到「PDFCell」。您不應該對這個HTML字符串按字面添加感到驚訝:您不會將HTML解析爲iText對象。 –