Unplanned
Last Updated: 13 May 2022 13:09 by ADMIN
Øyvind
Created on: 12 May 2022 12:11
Category: RichTextBox
Type: Bug Report
0
RichTextBox: Exporting hyperlinks that include symbols such as a Section sign (§) to a PDF file breaks the link
RichTextBox: Exporting hyperlinks that include symbols such as a Section sign (§) to a PDF file breaks the link
1 comment
ADMIN
Svilen
Posted on: 13 May 2022 13:09

One workaround is to Escape the special symbols using the System.Uri.EscapeDataString() method. Following is a code snippet, which adds a link with a special symbol and then escapes all symbols above the 128 in the ASCII table in all links in the RadDocument:

string webAddress = "https://lovdata.no/lov/2005-06-17-62/§14-5";  // Hyperlink with special symbol §
HyperlinkInfo info = new HyperlinkInfo()
{
    NavigateUri = webAddress,
    Target = HyperlinkTargets.Blank,
    IsAnchor = false
};
this.radRichTextBox.InsertHyperlink(info, webAddress); // Add hyperlink with special symbol

IEnumerable<HyperlinkRangeStart> links = this.radRichTextBox.Document.EnumerateChildrenOfType<HyperlinkRangeStart>();  // Get all HyperlinkRangeStart elements for iteration
foreach (HyperlinkRangeStart link in links)
{
    HyperlinkInfo hyperlinkInfo = link.HyperlinkInfo;
    string originalUri = hyperlinkInfo.NavigateUri;
    string modifiedUri = originalUri;

    for (int i = 0; i < originalUri.Length; i++)
    {
        char character = originalUri[i];

        if ((int)character > 127)
        {
            string escapedChar = Uri.EscapeDataString(webAddress[i].ToString()); // Escapes symbol
            string escapedUri = originalUri.Replace(character.ToString(), escapedChar); // Replaces symbol
            modifiedUri = escapedUri;
        }
    }

    hyperlinkInfo.NavigateUri = modifiedUri; // Replaces modified URI in HyperlinkInfo element

 

Regards,
Svilen
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.