Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
To convert Markdown to image formats in C#, first use
Converter.ConvertMarkdown() to create an intermediate HTMLDocument, then render it with
Converter.ConvertHTML() and
ImageSaveOptions. Set the image format to JPG, PNG, BMP, GIF, or TIFF.
Markdown to image conversion is useful for previews, thumbnails, documentation snapshots, visual archives, and systems that need raster output instead of editable Markdown or HTML. In Aspose.HTML for .NET, Markdown is parsed to HTML first, then the intermediate HTMLDocument is rendered to the selected image format.
Before running the examples, install and configure Aspose.HTML for .NET in your project. The complete C# example project is available in the Aspose.HTML for .NET GitHub repository.
Use JPG output when you need compact previews or thumbnails and small file size matters more than transparency or lossless text edges. The example creates a Markdown source, converts it to an intermediate HTMLDocument, and renders it to JPG.
The workflow is:
HTMLDocument with Converter.ConvertMarkdown(sourcePath).ImageSaveOptions instance with the required image format, such as ImageFormat.Jpeg.Converter.ConvertHTML(document, options, savePath) to render the intermediate HTML document as an image file. 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);Use ImageSaveOptions when the generated image needs custom rendering settings. The example below converts an existing Markdown file and applies image save options before rendering to JPG.
To customize Markdown to image conversion:
HTMLDocument with Converter.ConvertMarkdown().ImageSaveOptions and choose the output format.PageSetup, BackgroundColor, HorizontalResolution, VerticalResolution, UseAntialiasing, or TIFF Compression.HTMLDocument, ImageSaveOptions, and output path to Converter.ConvertHTML(). 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);| Option | Use it to control |
|---|---|
Format | The output image format. The default value is PNG; use ImageFormat.Jpeg, ImageFormat.Bmp, ImageFormat.Gif, or ImageFormat.Tiff when another format is required. |
BackgroundColor | The color used to fill the image background. The default value is transparent. |
PageSetup | Page size, margins, and page layout settings. |
HorizontalResolution and VerticalResolution | Output resolution values used by the rendering process. The default value is 300 dpi for each property. |
UseAntialiasing | Image rendering quality. Antialiasing is enabled by default. |
Text | Text rendering configuration through TextOptions. |
Compression | TIFF compression. Use it only for TIFF output; the default value is LZW. |
Use UseAntialiasing = true when you want to improve the visual quality of rendered shapes, text, and images, especially when clarity and smooth edges are important. Antialiasing can also increase processing time, so applications focused on rendering speed may choose UseAntialiasing = false.
PNG is the default ImageSaveOptions.Format value and is often the best choice for sharp documentation previews. The following example converts 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);BMP can be useful for Windows-oriented or legacy image workflows. The following example converts 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);GIF can be useful for simple compatibility-focused output. The following example converts 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);TIFF can be useful for archival, printing, scanning, and document imaging workflows. The following example converts 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);Use the online MD to JPG Converter for quick manual conversion. Use Aspose.HTML for .NET when Markdown to image conversion must run inside a C# application, service, or documentation pipeline.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.