使用ItextSharp生成Pdf文件时缺少锚点的下划线和蓝色

时间:2017-02-28 10:23:09

标签: c# html asp.net itext

我在pdf中获取链接但使用相同的iTextSharp下划线并且锚色标签缺少蓝色

引文栏需要引文字段中的超链接。引文字符串有锚标记。

请告诉我如何为锚标记(下划线和蓝色)应用自己的格式

 protected void GeneratePdfReport(DataTable RRDT)
{
   // DataRow dr = GetData("SELECT * FROM Employees where EmployeeId = " + ddlEmployees.SelectedItem.Value).Rows[0]; ;
   // DataRow dr = RRDT.Rows[0];

    try
    {
        Document document = new Document(PageSize.A4, 40f, 88f, 30f, 10f);
        Font NormalFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, Color.BLACK);
        using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
        {
            PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
            Phrase phrase = null;
            PdfPCell cell = null;
            PdfPTable table = null;
            Color color = null;

            document.Open();

            //Header Table
            table = new PdfPTable(1);
            table.TotalWidth = 500f;
            table.LockedWidth = true;
            //    table.SetWidths(new float[] { 1f });
            table.SpacingBefore = 20f;
            table.HorizontalAlignment = Element.ALIGN_LEFT;

            string TempCollege = "";
            string TempDepartment = "";
            string TempPublication = "";



            foreach (DataRow dr in RRDT.Rows)
            {

                if (dr["College"].ToString() != TempCollege || TempCollege == "")
                {

                //Citation
                phrase = new Phrase();
                phrase.Add(new Chunk(HttpUtility.HtmlDecode(dr["Citation"].ToString()) + "\n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
                cell.PaddingBottom = 3f;
                cell.PaddingTop = 3f;

                table.AddCell(cell);
            }

            document.Add(table);

            document.Close();


                byte[] bytes = memoryStream.ToArray();
                memoryStream.Close();
                Response.Clear();
                Response.ContentType = "application/pdf";
                Response.AddHeader("Content-Disposition", "attachment; filename=ResearchReport.pdf");
                Response.Buffer = true;
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.BinaryWrite(bytes);
                Response.ContentEncoding = Encoding.UTF8;
                HttpContext.Current.Response.Flush(); 
                HttpContext.Current.Response.SuppressContent = true;  
                HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
    }
    catch (ThreadAbortException ex)
    {
        String errorString = "Something went wrong:";
        UCSparkCommon.SendExceptionEmail(errorString, ex);
    }
    catch (Exception ex)
    {
        String errorString = "Something went wrong:";
        UCSparkCommon.SendExceptionEmail(errorString, ex);
    }
}

1 个答案:

答案 0 :(得分:1)

声明here默认情况下没有设置样式(颜色/下划线)。你必须使用自己的造型。

它们不应该是,因为它们不一定是超链接。

希望它有所帮助。