How to Convert Markdown to PDF

by Chaknith Bin

Markdown is a lightweight markup language for text formatting, commonly used in readme files and online forums. It's easy to read and write and is often used with a .md or .markdown file extension. IronPDF has the feature to convert both Markdown files and strings to PDF documents.

Get started with IronPDF

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer



Convert Markdown String to PDF Example

Use the RenderMarkdownStringAsPdf method to convert a string in Markdown format to a PDF document. All the features available in RenderingOptions, including the addition of text and HTML headers, footers, text overlays, image stamping, and page numbering, as well as setting custom page dimensions and orientations, can also be used with this rendering method. Once the PDF is created, you have the ability to modify pages through actions like merging, splitting, and rotating, and you can also add annotations and bookmarks.

:path=/static-assets/pdf/content-code-examples/how-to/md-to-pdf-from-string.cs
using IronPdf;

// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Markdown string
string md = "This is some **bold** and *italic* text.";

// Render from markdown string
PdfDocument pdf = renderer.RenderMarkdownStringAsPdf(md);

// Save the PDF
pdf.SaveAs("pdfFromMarkdownString.pdf");
Imports IronPdf

' Instantiate Renderer
Private renderer As New ChromePdfRenderer()

' Markdown string
Private md As String = "This is some **bold** and *italic* text."

' Render from markdown string
Private pdf As PdfDocument = renderer.RenderMarkdownStringAsPdf(md)

' Save the PDF
pdf.SaveAs("pdfFromMarkdownString.pdf")
VB   C#

Convert Markdown File to PDF Example

Utilize the RenderMarkdownFileAsPdf method to convert a Markdown file into a PDF document. You can download a sample Markdown file for conversion. Let's convert this sample file into a PDF.

Code Sample

:path=/static-assets/pdf/content-code-examples/how-to/md-to-pdf-from-file.cs
using IronPdf;

// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render from markdown file
PdfDocument pdf = renderer.RenderMarkdownFileAsPdf("sample.md");

// Save the PDF
pdf.SaveAs("pdfFromMarkdownFile.pdf");
Imports IronPdf

' Instantiate Renderer
Private renderer As New ChromePdfRenderer()

' Render from markdown file
Private pdf As PdfDocument = renderer.RenderMarkdownFileAsPdf("sample.md")

' Save the PDF
pdf.SaveAs("pdfFromMarkdownFile.pdf")
VB   C#

Output PDF

As you can see from the resulting PDF document, the Markdown functionalities for Code, Code Block, Blockquote, Tables, and Checkbox are not working. This is a current limitation of the method.

Chaknith related to Output PDF

Chaknith Bin

Software Engineer

Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.