Hyperlink apply on one portion but apply on all portion error

Hi Team,
I’m apply the hyperlink on paragraph’s one portion based on condition and hyper link working correctly. But facing one issue, like after hyper link portion all coming portion in same paragraph apply the same hyper link rule. For more information please see the below code and output file as attachment.

` if (dicAnchorTagRules.Count > 0)
{
if (dicAnchorTagRules.Any(e => (e.Key.Contains(tf.Paragraphs[pIndex].Text) || tf.Paragraphs[pIndex].Text.Contains(e.Key)) && !string.IsNullOrEmpty(e.Key)))
{
for (int K = 0; K < tf.Paragraphs[pIndex].Portions.Count; K++)
{
var data = dicAnchorTagRules.FirstOrDefault(e => e.Key.Contains(tf.Paragraphs[pIndex].Portions[K].Text) || tf.Paragraphs[pIndex].Portions[K].Text.Contains(e.Key));
if (!string.IsNullOrWhiteSpace(data.Key) && !string.IsNullOrWhiteSpace(tf.Paragraphs[pIndex].Portions[K].Text))
{
Dictionary<string, string> dicAnchorData = dicAnchorTagRules[data.Key];
var keyValue = dicAnchorData.FirstOrDefault();
tf.Paragraphs[pIndex].Portions[K].Text = keyValue.Key;

                            tf.Paragraphs[pIndex].Portions[K].PortionFormat.HyperlinkManager.SetExternalHyperlinkClick(keyValue.Value);
                        }
                        else
                        {
                            tf.Paragraphs[pIndex].Portions[K].PortionFormat.HyperlinkManager.SetExternalHyperlinkClick(string.Empty);
                        }
                    }
                }
            }

`

There are two file which give the better clarity. If I’m break line after anchor link, then it will work but it not the good solution. I want this in the same line.
Please suggest asap.

@Satyjeet,

No sample files are attached. Please share the sample files with us along with details. We will look into it and update you about our findings. Which Aspose API are you using?

break new line output file.zip (138.4 KB)
break new line output file.zip (138.4 KB)

Currently I’m using apose.slide version 15.5
If you need more information, please let me know…
I’m simply doing looping on paragraph portion and apply the hyperlink. If I’m not apply hyper link then output come correct but it not behave like anchor tag but look like anchor tag.

Ikram.Haq,
Please share the comment if you found any work around related to this.
To reproduce this you can take one long string in which have one/two anchor link and try to apply href by looping on portion, then same thing will be come.

@Satyjeet,

I have observed that you are using a fairly old version on your end. Please try using latest Aspose.Slides for .NET 18.3 on your end first and if there is still an issue then please share a working sample project along with source presentation reproducing the issue so that we may investigate the issue on our end to help you. I regret to share that I am unable to assess the partial code shared by you.

Hi Mudassir,
I understand your point, but i have only 15.5 version licence and till now we have no plan to upgrade this, because their are lots of dependency.

For its reproduce, I mention to take any paragraph of string and parse it, and after that get the slide auto shapes, paragraph and portion and any of the portion apply below line

tf.Paragraphs[pIndex].Portions[K].PortionFormat.HyperlinkManager.SetExternalHyperlinkClick("www.test.com");

You will be found its apply on that portion as well as all upcoming portion of same paragraph.

@Satyjeet,

I have used following sample code to test hyperlink setting on my end using Aspose.Slides for .NET 18.3. I have generated the source presentation by copying the text from your generated presentation file. I have not been able to observe the issue on my end using following code with attached presentation file. Can you please verify the same on your end. Moreover, if there is still an issue then I request you to please provide a working sample project and actual source presentation reproducing issue using Aspose.Slides for .NET 18.3.

   public static void TestHyperlinkIssue()
    {
        String textTofInd = "W3Schools.com!";
        String path=@"C:\break new line output file\";
        Presentation pres = new Presentation(path + "test.pptx");

        ISlide slide = pres.Slides[0];

        IAutoShape ashp = (IAutoShape)slide.Shapes[0];

        if (ashp.TextFrame != null)
        {
            ITextFrame text = ashp.TextFrame;
            if (text.Text.Contains(textTofInd))
            {
                foreach (IParagraph para in text.Paragraphs)
                {
                    if (para.Text.Contains(textTofInd))
                    {
                        foreach (IPortion port in para.Portions)
                        {
                            if (port.Text.Contains(textTofInd))
                            {
                                port.PortionFormat.HyperlinkManager.SetExternalHyperlinkClick("www.test.com");
                            }
                        }
                    }
                }
            }
        }

        pres.Save(path + "Saved.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
    }

Presentations.zip (65.5 KB)

Thanks for response.
Can you please try with version 15.5, and have any work around to this.

@Satyjeet,

I like to share that as per Aspose policy the support is only available for the latest available version. Moreover, the Aspose.Slides 15.5 series is no longer supported. I request you to please try using the latest Aspose.Slides for 18.3 on your end for which we can offer support to you as well.

Find the solution by using below line:-

paragraph.JoinPortionsWithSameFormatting();

@Satyjeet,

We are glad to know that thing has been started working on your end.