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.

Mon Nov 30, 2015 1:51 pm

Hello Support,

I want to update text of the Hyperlink using Spire.Pdf. Can you please help me?

I have code for updating URL. but if I set link.Text then its not working.
if (obj is PdfTextWebLinkAnnotationWidget)
{
PdfTextWebLinkAnnotationWidget link = obj as PdfTextWebLinkAnnotationWidget;
link.Url = "#";
//link.Text = "Click Here";//This is not working
}

Thank you,
Kiran

kiranpatel
 
Posts: 2
Joined: Thu Nov 05, 2015 2:03 pm

Tue Dec 01, 2015 3:39 am

Dear Kiran,

Thanks for your inquiry.
Sorry that at present Spire.PDF doesn’t support to update text of the Hyperlink. But there is a method covering new text on it to achieve your target, simple code for your reference:
Code: Select all
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"F:\testing\pdf form testing\original document\6363.pdf");
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 10, FontStyle.Underline));
            PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);
            //find the text you want to change and then cover new text on it
            foreach (PdfPageBase page in doc.Pages)
            {
                PdfTextFindCollection loFinds = page.FindText("Hello world");
                foreach (PdfTextFind lofind in loFinds.Finds)
                {
                    page.Canvas.DrawRectangle(new PdfSolidBrush(Color.White), lofind.Bounds);
                    page.Canvas.DrawString("updated text", font, brush, new PointF(lofind.Bounds.X, lofind.Bounds.Y));
                }
            }
            doc.SaveToFile("6363res.pdf");

If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Dec 01, 2015 9:07 am

Hello Support,

Thanks for your quick response.

Your code is working fine. But it will not help to me.
Because I have to replace URL and Text of hyperlink.

I can't be able to place covering new text exactly on hyperlink because of
1> link.Text returns = "" (So can't find link based on text)
2> link.Location returns {X = 0.0 Y = 0.0}. (location returns 0)

Also what is the use of (PdfTextWebLinkAnnotationWidget) link.SetText()?

Thank you,
Kiran

kiranpatel
 
Posts: 2
Joined: Thu Nov 05, 2015 2:03 pm

Tue Dec 01, 2015 9:49 am

Dear Kiran,

You need to know hyperlink text in advance, and then find it and cover it. Sorry that at present there is no way to find hyperlink text programmatically. The link.SetText() is used to set the name of the filed. It is not used to update the hyperlink text.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.PDF