Flatten hyperlink

Hi,

Could you help me with code to 'flatten' hyperlinks?

I need to replace all hyperlinks in a document with regular text while keeping the hyperlink style, so it looks like a hyperlink but has no functionality


Thanks


3 Replies 1 reply marked as answer

SR Sindhu Ramesh Syncfusion Team March 3, 2025 04:50 PM UTC

Hi Branislav,
Based on the details provided, we understand that your requirement is to replace all hyperlinks in a document with regular text while retaining the hyperlink style. To achieve this, we have prepared a sample. Kindly refer to the working sample along with the input and output documents.

In this sample, we have done the following things:
   1. Open DOCX document.
   2. Find all hyperlinks using FindAllItemsByProperty()
   3. Iterate through all hyperlinks.
   4. Create text range with TextToDisplay of the hyperlink.
   5. Apply hyperlink style to the text range.
   6. Remove the hyperlink from the document and insert the formatted text range at the same index.
   7. Save modified DOCX document.

If your requirement is different, kindly share the input and expected output documents. This will help us provide a solution at the earliest.

For more details, kindly refer the following UG:
Find item in Word document in .NET Word library | Syncfusion

Regards,
Sindhu Ramesh.


Attachment: ReplaceHyperlinkwithtext_aee8a1d0.zip

Marked as answer

BV Branislav Vucetic March 3, 2025 06:19 PM UTC

Hi Sindhu,

Thank you for your fast and clear response. This is exactly what I needed.





CA Chrispine Agunja Imbo Syncfusion Team March 4, 2025 07:21 AM UTC

Hi Branislav,

You are welcome. Please reach us if you need any other assistance.

Regards,

Chris


Loader.
Up arrow icon