How to Convert Markdown to PDF
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.
How to Convert Markdown to PDF
- Download the C# library to convert Markdown to PDF
- Prepare the Markdown file or string to be converted
- Convert a Markdown string to PDF using the
RenderMarkdownStringAsPdf
method - Convert a Markdown file to PDF using the
RenderMarkdownFileAsPdf
method - Review the generated PDF document
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")
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")
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.