Convert Markdown to Docx using Aspose.Words Display Problems

I used Aspose.Word to convert Markdown to Docx format according to the official Aspose tutorial, but there were some display problems.

  1. When the content contains html tags, it is not rendered after conversion.
  2. When the content contains images, Image is too wide on page and cannot be resized.
  3. When the content contains a table, the text in the table will have a title style.

Please refer to the file Output file.

Aspose tutorial URL

https://products.aspose.com/words/net/conversion/markdown-to-word/

Version Info

Aspose.Words for Net 24.1.0

Sample Code

void Main()
{
	var doc = new Aspose.Words.Document(@"C:\Users\54390\Desktop\demo.md");
	doc.Save(@"C:\Users\54390\Desktop\output.docx");
}

Input file

demo.zip (384.2 KB)

Output file

output.docx (775.6 KB)

@sullivan

  1. I have logged the issue as WORDSNET-26445. We will keep you informed and let you know once the issue is resolved.

  2. The behavior is expected. If you need to to resize the image to fit the page, you can postprocess the document after loading using code like the following:

Document doc = new Document("C:\\Temp\\in.md");

// Get shapes in the document.
foreach (Shape s in doc.GetChildNodes(NodeType.Shape, true))
{
    // Process only top level shapes.
    if (!s.IsTopLevel)
        continue;

    // Get shape parent section.
    Section parentSection = (Section)s.GetAncestor(NodeType.Section);
    PageSetup ps = parentSection.PageSetup;
    double pageWidth = ps.PageWidth - ps.LeftMargin - ps.RightMargin;
    double pageHeight = ps.PageHeight - ps.TopMargin - ps.BottomMargin;

    s.AspectRatioLocked = true;

    if (s.Width > pageWidth)
        s.Width = pageWidth;
    if (s.Height > pageHeight)
        s.Height = pageHeight;
}

doc.Save("C:\\Temp\\out.docx");
  1. The behavior is expected. If it is required to fit the table to content you can use the following code:
Document doc = new Document("C:\\Temp\\in.md");

foreach (Table t in doc.GetChildNodes(NodeType.Table, true))
    t.AutoFit(AutoFitBehavior.AutoFitToContents);

doc.Save("C:\\Temp\\out.docx");

@alexey.noskov
Thanks for your reply. I don’t think the third question is as expected.

Please refer to the screenshot below.

void Main()
{
	InitCoreComponent();
	var doc = new Aspose.Words.Document(@"C:\Users\54390\Desktop\demo.md");

	foreach (Aspose.Words.Tables.Table t in doc.GetChildNodes(NodeType.Table, true))
	{
		foreach (Aspose.Words.Tables.Row r in t.Rows)
		{
			foreach (Aspose.Words.Tables.Cell c in r.Cells)
			{
				foreach (Aspose.Words.Paragraph p in c.Paragraphs)
				{
					p.ParagraphFormat.StyleName.Dump();//Why not outputting "Normal"?
					//p.ParagraphFormat.StyleName = "Normal";
				}
			}
		}
	}
	doc.Save(@"C:\Users\54390\Desktop\demo.docx");
}

@sullivan
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-26451

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The issues you have found earlier (filed as WORDSNET-26451) have been fixed in this Aspose.Words for .NET 24.3 update also available on NuGet.