We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Conversion to html margins not displahing properly

When we convert docx to html the spacing after a bullet point gets replaced by non breakable spaces ( ) but it is different for each item. Sometimes it is 7 spaces, sometimes it can go up to 14, which makes it off when rendered on a rich text editor that shows html. Can you help me converting those to a span margin or something that makes it look good when it comes to margin?

@diegogravipwc

Could you please ZIP and attach your input and problematic output HTML here for testing? We will investigate the issue and provide you more information on it.

//This is the method I created:
///


/// Document to html
///

/// document stream
/// html string
public byte[] DocToHtml(Stream inputdocstrem)
{
using (var memoryStream = new MemoryStream())
{
HtmlSaveOptions htmlOptions = new HtmlSaveOptions(SaveFormat.Html)
{
UseHighQualityRendering = true,
PrettyFormat = true,
CssStyleSheetType = CssStyleSheetType.Inline,
ExportRoundtripInformation = true,
Encoding = System.Text.Encoding.UTF8,
ExportImagesAsBase64 = true,
ExportPageSetup = true,
ExportFontResources = true,
ExportFontsAsBase64 = true,
ExportTocPageNumbers = true,
ExportOriginalUrlForLinkedImages = true,
ExportLanguageInformation = true,
ExportRelativeFontSize = true,
ExportTextBoxAsSvg = true,
ScaleImageToShapeSize = true,
AllowNegativeIndent = true,
ExportDocumentProperties = true,
ExportListLabels = ExportListLabels.Auto,
ExportHeadersFootersMode = ExportHeadersFootersMode.FirstPageHeaderFooterPerSection
};
            var doc =new Document(inputdocstrem);

            if (doc.PageCount > 0 && doc.FirstSection.HeadersFooters.Count > 0)
            {
                var firstPageHeader = false;
                foreach (HeaderFooter item in doc.FirstSection.HeadersFooters)
                {
                    if (item.HeaderFooterType == HeaderFooterType.HeaderFirst)
                    {
                        firstPageHeader = true;
                    }
                }
                if (firstPageHeader == false)
                {
                    htmlOptions.ExportHeadersFootersMode = ExportHeadersFootersMode.FirstSectionHeaderLastSectionFooter;
                }
            }

            // Create blank template from OG document
            Document cloneDoc = doc.Clone();
            for (int i = 0; i < cloneDoc.Sections.Count; i++)
            {
                cloneDoc.Sections[i].Body.RemoveAllChildren();
                cloneDoc.Sections[i].Body.EnsureMinimum();
            }
            // Create a new memory stream.
            MemoryStream outStream = new MemoryStream();
            // Save the document to stream.
            cloneDoc.Save(outStream, SaveFormat.Docx);
            outStream.Seek(0, SeekOrigin.Begin);  
            byte[] buffer = new byte[outStream.Length];
            buffer = outStream.ToArray();
            string utfString = Convert.ToBase64String(buffer);

            // Save blank template with header in document custom property called "TemplateDoc"
            doc.CustomDocumentProperties.Add("TemplateDoc",utfString);
            
            doc.Save(memoryStream, htmlOptions);
            var validateStringForDebugging = System.Text.Encoding.Default.GetString(memoryStream.ToArray());
            return memoryStream.ToArray();
        }               
    }

@diegogravipwc

Unfortunately, we have not found the input and output documents with your post. Please ZIP and attach these documents for testing.