How to remove hyperlinks from html

HI there ,

I have got a html file which contains hyperlinks in it. following are the operations I want to perform on it -

  1. remove hyperlinks from it.
  2. also remove the text containing the hyperlink.
  3. save the html file as pdf.

I am able to remove the hyperlink from the text containing the link.
But I am not able to remove that text.

I am using Aspose.words version 17.4
and .net framework 4.6.2
This ismage is a screenshot of my code -
Kindly have a look and tell where am I mistaken .!!
image.png (18.7 KB)

@harsh1691

Thanks for your inquiry. As per your code screenshot you are using Aspose.Pdf. Please share your sample input and output documents along with complete code here. We will test the scenario and will guide you accordingly.

Hi Tilala

Attached are the

  • complete code
  • input file (html file for which I want to remove the text containing the link )
  • output pdf file
    input_output_code.zip (49.5 KB)

i am using Asose.Pdf ver -17.4.0 downloaded from nuget.
.net framework 4.6.2
visual studio 2015
and trying to perform the conversion on OS Windows Server 2012 R2

Sincerely

Hi Tilal ,

Any updates on the above issue ?

Regards
Harshit

@harsh1691,
Aspose.Pdf.Generator namespace is an old legacy approach and we recommend our clients to migrate from Aspose.Pdf.Generator approach to Aspose.Pdf for .NET DOM approach. Kindly see developer’s guide section about the DOM approach: Working with Aspose.Pdf.

We have tested your scenario with the latest version 17.7 of Aspose.Pdf for .NET API. Please try the following code. This is the output PDF file: Output17.7.pdf (22.3 KB)

[C#]

HtmlLoadOptions opts = new HtmlLoadOptions();
// Load the PDF file
Document document = new Document(@"C:\Pdf\test182\input_output_code\" + "abcd.html", opts);
// get first page
Aspose.Pdf.Page page = document.Pages[1];
// get the first link annotation
LinkAnnotation linkAnnot = (LinkAnnotation)page.Annotations[1];
linkAnnot.Hyperlink = null;

// Create RedactionAnnotation instance for specific page region
RedactionAnnotation annot = new RedactionAnnotation(document.Pages[1], linkAnnot.Rect);
annot.FillColor = Aspose.Pdf.Color.White;
annot.Color = Aspose.Pdf.Color.Black;
annot.Redact();
// save in the PDF format            
document.Save(@"C:\Pdf\test182\input_output_code\Output17.7.pdf");

Best Regards,
Imran Rafique