2017-02-28 64 views
0

我收到的PDF鏈接,但強調和藍色是使用相同的iTextSharp的缺少下劃線和藍色錨同時使用iTextSharp的生成PDF文件

引用列所需的超鏈接引用中缺失領域錨標記。引用字符串具有錨標籤。

請讓我知道我可以申請自己的格式爲

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

任何代碼去解決這個問題?我們無法看到屏幕上顯示的內容。 – Filburt

回答

1

據說here是iText的錨不是默認(彩色/下劃線)風格的錨標記(下劃線和藍色)。你將不得不應用你自己的造型。

它們不應該是,因爲它們不一定是超鏈接。

希望它有幫助。