Markdown Converter for Java

Aspose.HTML for Java converts Markdown directly to HTML with Converter.convertMarkdown(). For PDF, XPS, DOCX, or image output, convert Markdown to an HTMLDocument first, then pass that document and the appropriate save options to Converter.convertHTML().

Markdown is a lightweight plain-text markup language widely used for documentation, README files, and web content. Aspose.HTML for Java supports programmatic Markdown conversion to HTML and, through an intermediate HTML document, to PDF, XPS, DOCX, JPG, PNG, BMP, TIFF, and GIF.

How Markdown Conversion Works

  1. Prepare a Markdown source as a file or supported input stream.
  2. Call a convertMarkdown() overload to convert Markdown to HTML or obtain an HTMLDocument.
  3. For PDF, XPS, DOCX, or image output, create the save options for the required format.
  4. Call Converter.convertHTML() with the intermediate document, save options, and output path.

The following example creates a Markdown file, converts it to an HTMLDocument, and then converts the document to PDF with default PdfSaveOptions. The sample uses document.md as input and saves document-output.pdf.

 1// Convert Markdown to PDF using Aspose.HTML for Java
 2
 3// Prepare a simple Markdown example
 4String code = "### Hello, World! \n\n" +
 5        "[visit applications](https://products.aspose.app/html/applications)";
 6
 7// Create a Markdown file
 8FileHelper.writeAllText("document.md", code);
 9
10// Convert Markdown to HTML
11HTMLDocument document = Converter.convertMarkdown("document.md");
12
13// Convert the HTML document to PDF file format
14Converter.convertHTML(document, new PdfSaveOptions(), "document-output.pdf");

Download complete Java examples and data files from GitHub.

Markdown Conversion Guides

Related Markdown Workflows

Other Platforms

Try Online Markdown Conversion

Use the free online Markdown Converter for quick manual conversion to HTML, PDF, XPS, DOCX, or image formats without writing Java code. Use Aspose.HTML for Java when conversion must run programmatically in a Java application.