Pending Review
Last Updated: 20 Jun 2025 12:56 by Kris
Kris
Created on: 20 Jun 2025 12:56
Category: Telerik Document Processing
Type: Bug Report
0
Minified HTML Ignores Margins

When converting HTML to DOCX, margins set on an HTML element are ignored. These styles are exported correctly when the HTML passed to the converter is formatted with indents. The following XUnit test demonstrates this behavior with a simplified example.

using Telerik.Windows.Documents.Flow.FormatProviders.Docx;
using Telerik.Windows.Documents.Flow.FormatProviders.Html;

namespace MSPI.Tests.Unit;

public class WordExportTest
{
    [Fact]
    public async Task TextExport()
    {
        const string formattedDocumentSavePath = @"C:\Testing\export-test-formatted.docx";
        const string formattedContent = """"
            <p>Test paragraph</p>
            <ol style="margin-left: 100px;">
                <li>Item 1</li>
                <li>Item 2</li>
            </ol>
        """";

        const string minifiedDocumentSavePath = @"C:\Testing\export-test-minified.docx";
        const string minifiedContent = """"<p>Test paragraph</p><ol style="margin-left: 100px;"><li>Item 1</li><li>Item 2</li></ol>"""";

        var htmlFormatProvider = new HtmlFormatProvider();
        var docxFormatProvider = new DocxFormatProvider();

        await using var minifiedDocumentMemoryStream = new MemoryStream();
        var minifiedRadFlowDocument = htmlFormatProvider.Import(minifiedContent, TimeSpan.FromSeconds(30));
        docxFormatProvider.Export(minifiedRadFlowDocument, minifiedDocumentMemoryStream, TimeSpan.FromSeconds(30));
        var minifiedBytes = minifiedDocumentMemoryStream.ToArray();
        await File.WriteAllBytesAsync(minifiedDocumentSavePath, minifiedBytes);

        await using var formattedDocumentMemoryStream = new MemoryStream();
        var formattedRadFlowDocument = htmlFormatProvider.Import(formattedContent, TimeSpan.FromSeconds(30));
        docxFormatProvider.Export(formattedRadFlowDocument, formattedDocumentMemoryStream, TimeSpan.FromSeconds(30));
        var formattedBytes = formattedDocumentMemoryStream.ToArray();
        await File.WriteAllBytesAsync(formattedDocumentSavePath, formattedBytes);
    }
}

The minified HTML produces the following document:

The formatted HTML produces the following document:

 

0 comments