Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
If you need to preview a Markdown file, you can convert it to image formats. Using the Aspose.HTML for .NET library, you can easily convert Markdown into JPG, PNG, BMP, GIF or TIFF files with just a few lines of code!
This article provides information on how to convert Markdown to Image formats using the Aspose.HTML for .NET API. You will learn about the supported conversion scenarios and consider C# examples to illustrate them. Also, you can try an Online Markdown Converter to test the Aspose.HTML API functionality and convert Markdown on the fly.
You can convert Markdown to other formats with Aspose.HTML for .NET API in real time. Please load Markdown from the local file system, select the output format and run the example. The save options are set by default. You will immediately receive the conversion result as a separate file.
If you want to convert Markdown to Image formats programmatically, please see the following C# code examples.
Conversions from Markdown to other formats go through the Markdown to HTML conversion stage. If your scenario requires rendering Markdown document, for instance, to the JPG image file format, the following example demonstrates how that is simple:
sourcePath) method to save Markdown as an HTML document.If your case is to create a Markdown document from a user string directly in your code and convert it to a JPG file, the following example could help you:
1// Convert Markdown to JPG using C#
2
3// Prepare a path to a source Markdown file
4string sourcePath = Path.Combine(OutputDir, "document.md");
5
6// Prepare a simple Markdown example
7string code = "### Hello, World!" +
8 "\r\n" +
9 "[visit applications](https://products.aspose.app/html/family)";
10// Create a Markdown file
11File.WriteAllText(sourcePath, code);
12
13// Prepare a path to save the converted file
14string savePath = Path.Combine(OutputDir, "document-output.jpg");
15
16// Convert Markdown to HTML
17using HTMLDocument document = Converter.ConvertMarkdown(sourcePath);
18
19// Convert HTML document to JPG image file format
20Converter.ConvertHTML(document, new ImageSaveOptions(ImageFormat.Jpeg), savePath);If your case is to convert an existing Markdown document from a local file system, the following example could help you. You need to follow a few steps:
sourcePath) method of the Converter class to save Markdown as an HTML document.The following code snippet demonstrates how to convert Markdown to JPG using custom save options:
1// Convert Markdown to JPG in C# with custom settings
2
3// Prepare a path to a source Markdown file
4string sourcePath = Path.Combine(DataDir, "nature.md");
5
6// Prepare a path to save the converted file
7string savePath = Path.Combine(OutputDir, "nature-options.jpg");
8
9// Convert Markdown to HTML
10using HTMLDocument document = Converter.ConvertMarkdown(sourcePath);
11
12// Initialize ImageSaveOptions
13ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Jpeg)
14{
15 UseAntialiasing = true,
16 HorizontalResolution = 200,
17 VerticalResolution = 200,
18 BackgroundColor = System.Drawing.Color.AliceBlue
19};
20options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(600, 950), new Margin(30, 20, 10, 10));
21
22// Convert HTML to JPG
23Converter.ConvertHTML(document, options, savePath);The ImageSaveOptions class provides numerous properties that give you full control over a wide range of parameters and improve the process of converting Markdown to JPG format. To learn more about ImageSaveOptions, please read the Fine-Tuning Converters article.
In the above example, we use:
UseAntialiasing property that sets the rendering quality for this image. This example uses UseAntialiasing = true for quality rendering.HorizontalResolution and VerticalResolution properties that set horizontal/vertical resolution for output images in pixels per inch. By default, these properties are 300 dpi.BackgroundColor property that sets the color that will fill the background. The default BackgroundColor is Transparent.PageSetup property that specifies the
page size and
margins in pixels.Use UseAntialiasing = true when you want to improve the visual quality of rendered shapes, text, and images in your application, especially when clarity and smooth edges are essential. Enabling antialiasing smooths out jagged edges by blending the colors of pixels around the edges, resulting in a softer, more refined look.
While UseAntialiasing = true provides better visual quality, it can also increase processing time. For applications where rendering speed is a priority, it may be optimal to set UseAntialiasing = false.
The following code snippet demonstrates how to convert Markdown to PNG:
1// Convert Markdown to PNG using C#
2
3// Prepare a path to a source Markdown file
4string sourcePath = Path.Combine(DataDir, "document.md");
5
6// Prepare a path to save the converted file
7string savePath = Path.Combine(OutputDir, "output.png");
8
9// Convert Markdown to HTML
10using HTMLDocument document = Converter.ConvertMarkdown(sourcePath);
11
12// Convert HTML document to PNG image file format
13Converter.ConvertHTML(document, new ImageSaveOptions(), savePath);Aspose.HTML offers a free online MD to PNG Converter that converts Markdown to PNG image with high quality, easy and fast. Just upload, convert your files and get the result in a few seconds!
The following code snippet demonstrates how to convert Markdown to BMP:
1// Convert Markdown to BMP using C#
2
3// Prepare a path to a source Markdown file
4string sourcePath = Path.Combine(DataDir, "document.md");
5
6// Prepare a path to save the converted file
7string savePath = Path.Combine(OutputDir, "output.bmp");
8
9// Convert Markdown to HTML
10using HTMLDocument document = Converter.ConvertMarkdown(sourcePath);
11
12// Convert HTML document to BMP image file format
13Converter.ConvertHTML(document, new ImageSaveOptions(ImageFormat.Bmp), savePath);The following code snippet demonstrates how to convert Markdown to GIF:
1// Convert Markdown to GIF using C#
2
3// Prepare a path to a source Markdown file
4string sourcePath = Path.Combine(DataDir, "document.md");
5
6// Prepare a path to save the converted file
7string savePath = Path.Combine(OutputDir, "output.gif");
8
9// Convert Markdown to HTML
10using HTMLDocument document = Converter.ConvertMarkdown(sourcePath);
11
12// Convert HTML document to GIF image file format
13Converter.ConvertHTML(document, new ImageSaveOptions(ImageFormat.Gif), savePath);The following code snippet demonstrates how to convert Markdown to TIFF:
1// Convert Markdown to TIFF using C#
2
3// Prepare a path to a source Markdown file
4string sourcePath = Path.Combine(DataDir, "document.md");
5
6// Prepare a path to save the converted file
7string savePath = Path.Combine(OutputDir, "output.tiff");
8
9// Convert Markdown to HTML
10using HTMLDocument document = Converter.ConvertMarkdown(sourcePath);
11
12// Convert HTML document to TIFF image file format
13Converter.ConvertHTML(document, new ImageSaveOptions(ImageFormat.Tiff), savePath);Download the Aspose.HTML for .NET library, which allows you to successfully, quickly, and easily convert your HTML, MHTML, EPUB, SVG, and Markdown documents to the most popular formats.
You can check the quality of Markdown to JPG conversion with our online MD to JPG Converter. Upload, convert your files and get results in a few seconds. Try our forceful Markdown to JPG Converter for free now!
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.