Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Markdown is a markup language with a plain-text-formatting syntax. Markdown is often used as a format for documentation and readme files since it allows writing in an easy-to-read and easy-to-write style. Its design allows it to be easily converted to many output formats, but initially, it was created to convert only to HTML. Using the Aspose.HTML for .NET library in your C# application, you can easily convert Markdown into a PDF file with just a few lines of code!
This article provides information on how to convert Markdown to PDF using the Aspose.HTML for .NET API. You will learn about the supported Markdown to PDF 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 a Markdown file 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 PDF programmatically, please see the following C# code examples.
Note: Conversions from Markdown to formats such as PDF, XPS, DOCX, and image formats go through the Markdown to HTML conversion stage.
If your scenario requires rendering Markdown document, for instance, to the PDF 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 PDF file, the following example could help you:
1// Convert Markdown to PDF 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/applications)";
10// Create a Markdown file
11File.WriteAllText(sourcePath, code);
12
13// Convert Markdown to HTML
14using HTMLDocument document = Converter.ConvertMarkdown(sourcePath);
15
16// Prepare a path for converted PDF file saving
17string savePath = Path.Combine(OutputDir, "document-output.pdf");
18
19// Convert the HTML document to PDF file format
20Converter.ConvertHTML(document, new PdfSaveOptions(), 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 shows how to convert Markdown to PDF using Aspose.HTML for .NET.
1// Convert Markdown to PDF 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-output.pdf");
8
9// Convert Markdown to HTML
10using HTMLDocument document = Converter.ConvertMarkdown(sourcePath);
11
12// Initialize PdfSaveOptions. Set up the resolutions, JpegQuality and change the background color to AliceBlue
13PdfSaveOptions options = new PdfSaveOptions()
14{
15 HorizontalResolution = 200,
16 VerticalResolution = 200,
17 BackgroundColor = System.Drawing.Color.AliceBlue,
18 JpegQuality = 100
19};
20
21// Convert the HTML document to PDF file format
22Converter.ConvertHTML(document, options, savePath);The PdfSaveOptions class provides numerous properties that give you full control over a wide range of parameters and improve the process of converting Markdown to PDF format. To learn more about PdfSaveOptions, please read the Fine-Tuning Converters article.
In the above example, we use:
JpegQuality property that enables you to specify the quality of JPEG compression for images. The default value is 95.BackgroundColor property that sets the color that will fill the background. The default BackgroundColor is Transparent.HorizontalResolution and VerticalResolution properties that set horizontal/vertical resolution for output images in pixels per inch. By default, these properties are 300 dpi.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 PDF conversion with our online MD to PDF Converter. Upload, convert your files and get results in a few seconds. Try our forceful Markdown to PDF Converter for free now!
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.