Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/0d5b91259cc1afade1a10a77fb2330fc to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/0d5b91259cc1afade1a10a77fb2330fc to your computer and use it in GitHub Desktop.
Develop a Markdown to Word Converter in C#
using Aspose.Words;
// Load the Markdown document
Document doc = new Document("sample.md");
// Access the document's main body
DocumentBuilder builder = new DocumentBuilder(doc);
// Move the cursor to the end of the document
builder.MoveToDocumentEnd();
// Insert a new paragraph at the end with a custom style
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Writeln("Additional Notes");
// Insert a normal paragraph with some styled text
builder.Font.Size = 12;
builder.Font.Bold = true;
builder.Font.Color = System.Drawing.Color.DarkBlue;
builder.Writeln("This section was added programmatically using Aspose.Words.");
// Save the updated document
doc.Save("EditedDocument.docx");
using Aspose.Words;
// Load the Markdown document into Aspose.Words' Document object
// The Document class represents an in-memory model of the entire document
Document doc = new Document("sample.md");
// Save the document as a Word (.docx) file
doc.Save("output.docx");
using Aspose.Words;
string inputFolder = "D:\\Files\\";
string[] markdownFiles = Directory.GetFiles(inputFolder, "*.md");
foreach (string file in markdownFiles)
{
string outputFile = Path.ChangeExtension(file, ".docx");
Document doc = new Document(file);
doc.Save(outputFile);
Console.WriteLine($"Converted: {Path.GetFileName(file)}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment