Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Mar 01, 2017 1:44 am

Is it possible to add a hyperlink in a table?

Thanks!

nperezo
 
Posts: 3
Joined: Tue Feb 14, 2017 2:54 am

Wed Mar 01, 2017 3:38 am

Dear nperezo,

Thanks for your inquiry.
Yes, you only need to replace a data with the hyperlink you want in String[] data, and then follow below tutorial.
https://www.e-iceblue.com/Tutorials/Spi ... B.NET.html
If there is still issue, please describe it and provide us the code you were using.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Mar 02, 2017 4:32 pm

Hello,

Thanks for your reply, I did this, but it didn't work.

Code: Select all
foreach (var req in reqs)
{
    var rrc = string.IsNullOrWhiteSpace(req.URL) ? req.RiskReductionControl.Replace("-", " ") : string.Format("<a href='{0}' target='_blank'>{1}</a>", req.URL, req.RiskReductionControl.Replace("-", " "));

    data.Add(GetMitigationConditionsString(req.MitigationRequestId) + ";" + req.TaskActivity.Replace("-", " ") + ";" + req.RiskAssociated.Replace("-", " ") + ";" + req.CauseAspect.Replace("-", " ") + ";" + req.Severity + ";" + req.Probability + ";" + req.RPC + ";" + rrc + ";" + req.RiskMitigated + ";" + req.ContingencyPlan);
}

var dataSource = new string[data.Count][];

for (var i = 0; i < data.Count; i++)
{
    dataSource[i] = data[i].Split(';');
}

table.DataSource = dataSource;


Am I missing something?

Thanks!

nperezo
 
Posts: 3
Joined: Tue Feb 14, 2017 2:54 am

Fri Mar 03, 2017 3:09 am

Dear nperezo,

Thanks for your information.
In my understanding, you want to insert HTML(string.Format("<a href='{0}' target='_blank'>{1}</a>") as Hyperlink, sorry that at present it cannot achieve. But we will do investigation further, once there is any update, we will inform you.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Aug 04, 2017 7:23 pm

This would really be helpful for me. I'm dynamically creating a table and one of the columns contains a long URL. The URL text breaks to fit the column width and makes the URL itself unclickable since only the first line is seen as a URL. I'd much rather just be able to put a single file name (or even just the word "Link") with the title/word being a hyperlink.

cmpalmer
 
Posts: 1
Joined: Thu Apr 27, 2017 5:03 pm

Mon Aug 07, 2017 8:04 am

Hello nperezo,

Thanks for your reply.
After an initial test with the latest version( Spire.PDF Pack(Hot Fix) Version:3.9.266), I didn't encounter the issue you mentioned. The long url takes up several lines but I can link to it successfully when clicking. See my tesing code below.
Code: Select all
 String[] data = {
   "Hello;Description;www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Spire.PDF-Program-Guide-Content.html",
   "900;Dive kayak;www.e-iceblue.com/forum/insert-hyperlink-in-a-table-t6619.html"};
            String[][] dataSource = new String[data.Length][];
            for (int i = 0; i < data.Length; i++)
            {
                dataSource[i] = data[i].Split(';');
            }

            PdfDocument doc = new PdfDocument();
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4);
            PdfTable table = new PdfTable();

            table.Style.CellPadding = 2;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f));

            table.DataSource = dataSource;
            table.Draw(page, new PointF(0, 20));

            doc.SaveToFile("11301.pdf");

As the requirement of making a file name or some certain string as the display text for the link, sorry it is not available at present.
If I misunderstand your meaning, please share more details.


Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Fri Aug 11, 2017 10:18 am

Hello,

How is your issue now?
Could you please give us some feedback at your convenience?

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.PDF