Hello,
Thanks for your inquiry.
Please don't mind that I add the answers after your questions.
1) Enumerate all Hyperlinks and get the URL of the Hyperlink (i guess as the Text is seperate form the Link Annotation, it would be difficult to get the text)
Please refer to the code snippet below to get all Hyperlinks and the URL of the specific Hyperlink. Sorry that our Spire.Pdf doesn't support to get the text of the Hyperlink at present. But we have added the feature into our schedule. Once Spire.Pdf supports the feature, we will tell you.
- Code: Select all
PdfDocument pdfdoc = new PdfDocument();
pdfdoc.LoadFromFile(string filename);
PdfPageBase page = pdfdoc.Pages[0];
// The code page.AnnotationsWidget gets all Hyperlinks in every page of PDF file
foreach(PdfTextWebLinkAnnotationWidget link in page.AnnotationsWidget)
{
// Get the URL of the Hyperlink
string url=link.Url;
}
2) Delete a Hyperlink within the PDF
We provide you two solutions to delete a Hyperlink. Please try the following code.
- Code: Select all
// solution 1
PdfTextWebLinkAnnotationWidget hyperL = page.AnnotationsWidget[0] as PdfTextWebLinkAnnotationWidget;
page.AnnotationsWidget.Remove(hyperL);
//solution 2
page.AnnotationsWidget.RemoveAt(index);
3) Change the URL of the Hyperlink to something else (i.e. link to google.com changed to bing.com, without affecting the Text in PDF)
Please refer to the code as below to change the original url of the Hyperlink.
- Code: Select all
PdfTextWebLinkAnnotationWidget link = page.AnnotationsWidget[index] as PdfTextWebLinkAnnotationWidget;
link.url="http://www.bing.com";
Sincerely,
Gary
E-iceblue support team