Hyperlink in HtmlFragment Text

Hi,

I would like to know, how to enable hyperlinks in a HtmlFragment Text. The scenario is as below

I am having a HTML content coming from a different source, I have to display the content as it is, I am displaying the Same HTML content in PDF using HtmlFragment in a document. The hyperlinks in the text are getting enabled. Please suggest, how to proceed further. Attached is the output file generated from ASPOSE. Code for the same is as below:

var dataDir = AppDomain.CurrentDomain.BaseDirectory;
var lic = new Aspose.Pdf.License();
lic.SetLicense(“Aspose.Pdf.lic”);
Document doc = new Document();
var page = doc.Pages.Add();
TextStamp textStamp = new TextStamp(“Hello word”);
HtmlFragment title1 = new HtmlFragment(“Hello World, this is a link to go toGoogle Click here”);
title1.HtmlLoadOptionsOfInstance = new HtmlLoadOptions();
page.Paragraphs.Add(title1);
//title1.IsInNewPage = true;
// Add HTML Fragment to paragraphs collection of page
textStamp.TopMargin = 10;
textStamp.HorizontalAlignment = HorizontalAlignment.Center;
textStamp.VerticalAlignment = VerticalAlignment.Top;
string s3 = “
Raj
1
2
3
4
5
”;
HtmlFragment title2 = new HtmlFragment(s3);
page.Paragraphs.Add(title2);
doc.Save(dataDir + “abc.pdf”);
Document doc1 = new Document(dataDir + “abc.pdf”);
//Add header on all pages
foreach (Page tpage in doc.Pages)
{
tpage.AddStamp(textStamp);
}
doc.Save(dataDir + “abc.pdf”);

Regards,
Raj.

Hi Rajasekhar,


Thanks for contacting support.

I have tried to add a HTML string with Hyperlink inside PDF document by using the code snippet which you have shared. It seemed that the Hyperlink in the PDF document was not being honored correctly and it was not working.

Therefore for the sake of further investigation I have logged this issue as PDFNET-42272 in our issue tracking system and linked to this thread as well. We will further look into this and keep you updated on the status. Please be patient and spare us a little time. We are sorry for the inconvenience.

Best Regards,

I am also running into this problem, any idea when it will be fixed?

Hi Rajasekhar,


Thanks for your inquiry. I have checked the status of the logged issue and I am sorry that it is still pending and not resolved. Please note that we have just notified the development team about the earlier reported issue and I am sure they will investigate/fix the issue as per their development schedule. We will keep you updated about the status of resolution process. Please be patient and give us a little time.

We are sorry for the inconvenience.

Best Regards,

Hi,


Thanks for your reply. We have moved our code to production in an idea that this feature is available. There is a critical functionality, with out this the feature product will not be much useful. Kindly do the needful ASAP.

Regards,
Raj.

Hi Raj,


Thanks for your patience. We do realize the severity of the issue and we also hope that a fix to this issue will be made as soon as possible. There are also other reported issues in the queue as well and they have been scheduled for fixing on first come first serve basis. We really appreciate your patience in this regard. We will definitely let you know when we have some updates about the resolution process.

We are sorry for the inconvenience.

Best Regards,

Hi,


Any update the the request raised, its been a long time, we dont have any update on the Hyperlink disabling. Could you please suggest me, how to proceed further?

Regards,
Raj.

Hi Raj,

Thanks for contacting support.

I am sorry to inform you that the earlier logged issue is not yet resolved and still pending for review. As there are other high priority issues in the queue and development team is busy in resolving them. I am sure that they will soon plan to start investigation for your issue as per their development scheme.

However I have tried to add a link annotation over text so that it can give a feel of anchor text. You may try using following code snippet to achieve that. I have also attached an output file for your reference.

using System;
using Aspose.Pdf;
using Aspose.Pdf.Text;
using Aspose.Pdf.Text.TextOptions;

public class AddLinkToPDF
{
    public static void Main()
    {
        string dataDir = "your_data_directory/";

        Document doc = new Document();
        var page = doc.Pages.Add();

        HtmlFragment title1 = new HtmlFragment("Hello World, this is a link to go to Google Click here");
        title1.HtmlLoadOptionsOfInstance = new HtmlLoadOptions();
        page.Paragraphs.Add(title1);

        doc.Save(dataDir + "abc_out.pdf");

        doc = new Document(dataDir + "abc_out.pdf");

        TextFragmentAbsorber filter = new TextFragmentAbsorber("Google");
        filter.TextSearchOptions = new TextSearchOptions(false);
        doc.Pages.Accept(filter);

        foreach (TextFragment content in filter.TextFragments)
        {
            LinkAnnotation annot = new LinkAnnotation(content.Page, content.Rectangle);
            annot.Action = new GoToURIAction("http://www.google.com");
            annot.Border.Style = BorderStyle.Inset;
            content.Page.Annotations.Add(annot);

            // Make the text fragment invisible
            content.IsLink = true;
        }

        doc.Save(dataDir + "abc_out.pdf");
    }
}

For now you may do something like above to get the hyperlinks working inside the document. Whereas for the logged issue, we will definitely keep you updated once we have some certain information regarding its resolution. Please be patient and spare us a little time. We are sorry for the inconvenience.

Best Regards,

Hi,


Thanks for sharing a work around. This worked for me, but when I try to generate a link, the below statement is throwing exception. Also a box is appearing in the PDF. Could you please help me with the issue?

annot.Border.Style = BorderStyle.Inset;

Let me know if you need any information from me.

Regards,
Raj.

Hi,

Your workaround is not working reliably for us as the HTML content is dynamic and find/replace is not a good way as we are creating more hyperlinks than the original content is intended for.

This is not good that there is still no solution for this simple need. Even open source libraries like iTextSharp has working solutions for hyperlinks and commercial product like Aspose doen’t have a solution.

Not only the lack of solution but the response time for key features is astonishing. Why don’t you mention this shortcoming on your main page so that people like us don’t buy and stop being at your mercy?

Please provide a working solution, not a basic workaround.

Thanks,
Anil

Hi There,


Thanks for your inquiry.

anilphv:
This is not good that there is still no solution for this simple need. Even open source libraries like iTextSharp has working solutions for hyperlinks and commercial product like Aspose doen’t have a solution.

Not only the lack of solution but the response time for key features is astonishing. Why don’t you mention this shortcoming on your main page so that people like us don’t buy and stop being at your mercy?

Please accept my humble apologize for the inconvenience you are facing. We already have logged the issue in our issue tracking system for correction. I have also intimated the relevant team about your concerns. We really appreciate your patience and cooperation in this regard. Please spare us a little time. We will keep you posted on the status of resolution process.

rajasekharbatchu:
Thanks for sharing a work around. This worked for me, but when I try to generate a link, the below statement is throwing exception. Also a box is appearing in the PDF. Could you please help me with the issue?

annot.Border.Style = BorderStyle.Inset;

I am looking into a work around for the functionality and will update you in a while.

We are sorry for the inconvenience.


Best Regards,

Hi Raj,

Thanks for your patience. In order to remove the rectangle/border around the LinkAnnotation you need to set the Width property of the border to zero. Please check the following code snippet to set the Width property of the border.

LinkAnnotation annot = new LinkAnnotation(content.Page, content.Rectangle);
annot.Action = new GoToURIAction("http://www.google.com");
Border border = new Border(annot);
border.Width = 0;
annot.Border = border;

In case of any further assistance please feel free to contact us.

Best Regards,

@anilphv

Thanks for your patience.

We have again tested the scenario with latest version of the API (Aspose.Pdf for .NET 17.12) and noticed that the Hyperlink were working in the resultant PDF documents. We request you, please download latest version of the API and in case you experience any issue, please feel free to contact us.

@rajasekharbatchu

Thanks for your patience.

We are pleased to inform you that earlier reported issue PDFNET-42272 has been resolved in Aspose.PDF for .NET 18.1. Please download latest version of the API and in case of any further assistance, please feel free to let us know.