Markdown Converter – Java
Markdown is a web page archive format that allows embedding multiple resources, such as images, CSS styles, audio, and video files, into a single file, typically with a .mht file extension. Markdown format allows a web page to be saved and sent as a single file, preserving its appearance and interactivity. It can be opened by most web browsers. But sometimes you want to Convert Markdown to get the advantages of other formats.
Aspose.HTML for Java provides a wide range of Markdown conversions to popular formats, such as PDF, XPS, JPG, PNG, BMP, TIFF, and GIF.
This section provides information on the list of supported Markdown conversions and how to perform them using convertMarkdown()
methods of the
Converter class. It can be different scenarios, but any Markdown conversion can be made with a few required steps:
- Load an existing Markdown file. You can load Markdown from a file or stream.
- Create a Save Options object. You may customize the rendering process to get the desired result.
- Use one of the
convertMarkdown()
methods to convert Markown to HTML and pass the required parameters to it. - Call one of the
convertHTML()
methods of the Converter class to convert the HTML to the required output format.
Note: Any conversion from Markdown to other formats goes through the Markdown to HTML conversion stage.
Let’s consider the following code snippet that shows how to convert Markdown to PDF using our Java library:
1 // Prepare a path to a source Markdown file
2 String sourcePath = Path.combine(getDataDir(), "nature.md");
3
4 // Prepare a path for converted PDF file saving
5 String savePath = Path.combine(getOutputDir(), "nature-output.pdf");
6
7 // Convert Markdown to HTML
8 HTMLDocument document = Converter.convertMarkdown(sourcePath);
9 try {
10 // Initialize PdfSaveOptions
11 PdfSaveOptions options = new PdfSaveOptions();
12
13 // Convert the HTML document to PDF file format
14 com.aspose.html.converters.Converter.convertHTML(document, options, savePath);
15 }
16 finally { if (document != null) document.dispose(); }
Popular Markdown Conversions
- Convert Markdown to HTML – Consider various Markdown to HTML conversion scenarios in Java code. Converting Markdown to HTML is an important basic operation because all conversions to other formats go through the Markdown to HTML conversion step.
- Convert Markdown to PDF – Learn how to convert Markdown to PDF using Java library. You can easily use the Java code described here to convert Markdown to PDF, or Markdown to XPS.
- Convert Markdown to Image – Learn how to convert Markdown to Image with Aspose.HTML for Java, and you can easily use the Java code described here to convert Markdown to PNG, JPG, BMP, GIF, and TIFF.
You can download the complete examples and data files from GitHub.
Aspose.HTML provides a free online Markdown Converter that enables you to convert Markdown files to various popular formats. This tool can easily convert Markdown to PDF, XPS, DOCX, JPG, PNG, BMP, TIFF, and GIF. The conversion process is simple and fast. You don’t need any additional software. The best part is that it’s completely free!