In this article, we will be learning Markdown file to PDF, PNG, JPG, and other image formats conversion programmatically using C# language. MD files are quite common over the web and you might have noticed that readme files of different software, as well as the documentation, are often created in Markdown format. Let us take a look over the following headings:
- Markdown (.md) to PDF and Images C# Converter – API Installation
- Convert Markdown (MD) to PDF in C#
- Convert Markdown (MD) to PNG or JPG Image in C#
Markdown (.md) to PDF and Images C# Converter – API Installation
You need to install Aspose.HTML for .NET API for converting Markdown format files to PDF or image formats in C#. You can configure the API by downloading it from the official Downloads section or via the NuGet gallery installation command, as under:
PM> Install-Package Aspose.Html
Convert Markdown (MD) to PDF in C#
You can easily convert Markdown Files (MD) to PDF using C# in your .NET applications. You need to follow the steps below for converting MD to PDF file:
- Prepare a simple Markdown example or load input MD file
- Call the ConvertMarkdown method
- Convert the input file to HTMLDocument instance
- Save the output PDF file using the ConvertHTML method
The following code shows how to convert markdown (MD) file to PDF using C#:
Convert Markdown (MD) to PNG or JPG Image in C#
Sometimes you might need to preview an MD file so rendering it to an image can be helpful. You can convert MD file to PNG or JPG image as per your requirements. This conversion is basically a two-step approach where, first of all, you will render it to HTML format and then to an image:
- Create or Load the input Markdown (MD) file
- Convert the Markdown to intermediary HTML format
- Render the results to PNG or JPG output Image in C#
These simple steps help you create an image of the MD file as a preview. You may utilize the output image further as per your use case. Moreover, the code below shows how to convert Markdown (MD) file to PNG or JPG Image in C#:
Conclusion
To put it in a nutshell, we have considered the conversion of Markdown (MD) files to PNG, JPG, and PDF using C# in .NET applications. These features can make your applications second to none. Furthermore, there are many other features offered by the API which you can explore by taking a look at Product Documentation. In case of any ambiguities or concerns, please feel free to write to us at Free Support Forum. We would love to have your feedback!