Free Support Forum - aspose.com

Remove All hyperlinks while saving word to pdf

Hi ,
Is there a way where I can remove all hyper links In word doc before converting to PDF

@TejKamal_Thotakuri

Thanks for your inquiry. Please use the following code example to remove the hyperlinks from the document.

Document doc = new Document(MyDir + "input.docx");
doc.Range.Fields.Cast<Field>().Where(f => f.Type == FieldType.FieldHyperlink).ToList().ForEach(f => f.Remove());

doc.Save(MyDir + "18.9.pdf");

Sorry for the confusion.
My requirement is not to Remove but to convert. .
Is there any way to convert all hyperlinks to static text

@TejKamal_Thotakuri

Thanks for your inquiry. Please use Field.Unlink method instead of Field.Remove as shown below.

Document doc = new Document(MyDir + "input.docx");
doc.Range.Fields.Cast<Field>().Where(f => f.Type == FieldType.FieldHyperlink).ToList().ForEach(f => f.Unlink());

doc.Save(MyDir + "18.9.pdf");

HI Tahir,

That worked like a charm. Thanks
But site links like “www.google.com” are still showing as hyperlinks.
Is there a way to remove those as well ?

–Cheers

@TejKamal_Thotakuri

Thanks for your inquiry. Please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

Source5 - Automation Twonas.zip (944.1 KB)
Please find the document attached

@TejKamal_Thotakuri

Thanks for sharing the document. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-17505. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@TejKamal_Thotakuri

Thanks for your patience. It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-17505) as ‘Not a Bug’.

Hyperlinks are not exported to the output PDF. Acrobat Reader creates hyperlink by itself from the text. This behavior is controlled by “Edit->Preferences->General->Create links from URLs” checkbox.