Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 23, 2021 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/5fdd0ccec10356ff52d256a5d14db5fa to your computer and use it in GitHub Desktop.
Save aspose-com-gists/5fdd0ccec10356ff52d256a5d14db5fa to your computer and use it in GitHub Desktop.
Convert Markdown .md file to Word Document DOCX/DOC or XPS File
// Prepare a path to a source Markdown file
string sourcePath = dataDir + "nature.md";
// Prepare a path for converted DOCX file saving
string savePath = dataDir + "nature-output.docx";
// Convert Markdown to HTML document
HTMLDocument document = Converter.ConvertMarkdown(sourcePath);
// Initialize DocSaveOptions. Set up the page-size and margins
DocSaveOptions options = new DocSaveOptions();
options.PageSetup.AnyPage = new Page(new Size(500, 1000), new Margin(20, 20, 10, 10));
// Convert HTML document, created from Markdown file to DOCX file format
Converter.ConvertHTML(document, options, savePath);
// Prepare a path to a source Markdown file
string sourcePath = dataDir + "nature.md";
// Prepare a path for converted PDF file saving
string savePath = dataDir + "nature-output.xps";
// Convert Markdown to HTML
var document = Converter.ConvertMarkdown(sourcePath);
// Initialize XpsSaveOptions. Set up the resilutions, page-size, margins and change the background color to AntiqueWhite
var options = new Aspose.Html.Saving.XpsSaveOptions()
{
HorizontalResolution = 200,
VerticalResolution = 200,
BackgroundColor = System.Drawing.Color.AntiqueWhite
};
options.PageSetup.AnyPage = new Page(new Size(Length.FromInches(5.0f), Length.FromInches(10.0f)), new Margin(30, 20, 10, 10));
// Convert the Markdown MD file to XPS file format
Converter.ConvertHTML(document, options, savePath);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment