Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / Convert HTML to normal...
Finance forum
Suggested answer

Convert HTML to normal text

Posted on by 4
Hi All,
 
Created one string field in parameter form. user will enter inputs in HTML format.
Need to display same field in SSRS report footer.
 
have followed below link (Written code in report DP class) and able to get text in SSRS report. but alignment is not proper. (Bold letter, Capital letter, next line are not coming properly)
 
Kindly help.
Thank you.
  • Suggested answer
    Khan zain Profile Picture
    Khan zain 1 on at
    Convert HTML to normal text
    To ensure proper alignment and formatting when displaying HTML content from a string field in the SSRS report footer in Dynamics AX 2012, you can use a combination of methods to parse HTML and convert it into plain text. Here's a step-by-step approach to achieve this:
    1. **HTML to Plain Text Conversion**: Use X++ code in the report DP class to convert HTML content into plain text. You can utilize regular expressions or custom parsing logic to strip HTML tags and convert special characters.
    2. **Formatting Preservation**: Retain formatting such as bold letters, capital letters, and line breaks while converting HTML to plain text. Ensure that the conversion logic handles these elements appropriately.
    3. **Alignment**: Once the HTML content is converted to plain text, ensure proper alignment within the SSRS report footer. You may need to adjust the alignment settings in the SSRS report layout to accommodate the content correctly.
    Here's a sample code snippet demonstrating how you can achieve this in the report DP class:
    ```csharp
    public str convertHtmlToPlainText(str _html)
    {
        System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("<[^>]+>|&nbsp;");
        str plainText = regex.Replace(_html, "");
        return plainText;
    }
    public void fetchReportData()
    {
        YourTable yourTable;
        str htmlContent;
        // Fetch HTML content from the table or data source
        select firstOnly yourTable;
        htmlContent = yourTable.HTMLField;
        // Convert HTML to plain text
        str plainText = convertHtmlToPlainText(htmlContent);
        // Set plain text content to the report footer field
        this.ReportFooterField = plainText;
    }
    ```
    Replace `"HTMLField"` and `"ReportFooterField"` with the appropriate field names in your context. This code snippet will convert HTML content stored in the `HTMLField` of your table to plain text and then assign it to the report footer field for proper alignment in the SSRS report.
    By following these steps, you can ensure that HTML content is correctly displayed in the SSRS report footer with proper alignment and formatting preservation. Adjust the code as needed to fit your specific requirements and data structures.
  • Martin Dráb Profile Picture
    Martin Dráb 225,000 Super User on at
    Convert HTML to normal text
    Plain text doesn't have formatting such as bold text; that's why it's called plain. You either want plain text or formatted text; it can't be both at the same time.
  • Convert HTML to normal text
    Currently i am using D365 finance and operations.

Helpful resources

Quick Links

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,682 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,000 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans