Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
To convert Markdown to an image in Java, call
Converter.convertMarkdown() to obtain an HTMLDocument, create ImageSaveOptions with the required ImageFormat, and pass both to
Converter.convertHTML(). Supported output formats include PNG, JPG, BMP, GIF, and TIFF.
Markdown-to-image conversion creates a visual copy of Markdown content for documentation, presentations, previews, and sharing. Aspose.HTML for Java uses HTML as the intermediate document and ImageSaveOptions to select the image format and configure resolution, page setup, background color, rendering quality, and TIFF compression.
The parameterless ImageSaveOptions() constructor selects PNG by default. The example below specifies ImageFormat.Png explicitly:
HTMLDocument.ImageSaveOptions with ImageFormat.Png.The sample writes Markdown content to document.md and converts it to output_md.png.
1// Convert Markdown to PNG using Java
2
3// Prepare a simple Markdown example
4String code = "### Hello, World\n\n" +
5 "[visit applications](https://products.aspose.app/html/family)";
6
7// Create a Markdown file
8try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.md")) {
9 fileWriter.write(code);
10}
11
12// Convert Markdown to HTML document
13HTMLDocument document = Converter.convertMarkdown("document.md");
14
15// Convert HTML document to PNG image file format
16Converter.convertHTML(document, new ImageSaveOptions(ImageFormat.Png), "output_md.png");Use ImageSaveOptions to select the output format and control image rendering.
| Method | Use it to |
|---|---|
setFormat(value) | Select JPG, PNG, BMP, GIF, or TIFF. The default format is PNG. |
setBackgroundColor(value) | Set the color that fills each output page. The default is transparent. |
getPageSetup() | Access the page setup used to configure output page size and margins. |
setHorizontalResolution(value) | Set horizontal resolution in pixels per inch. The default is 300 dpi. |
setVerticalResolution(value) | Set vertical resolution in pixels per inch. The default is 300 dpi. |
setSmoothingMode(value) | Configure image rendering quality. |
setCompression(value) | Select TIFF compression. The default TIFF compression is LZW. |
getCss() | Access CSS processing options. |
getText() | Access text rendering options. |
For additional rendering controls, see Fine-Tuning Converters.
JPG uses lossy compression and is useful when file size is more important than transparency or lossless detail. To customize JPG output:
HTMLDocument with Converter.convertMarkdown().ImageSaveOptions with ImageFormat.Jpeg.Converter.convertHTML().The following example converts nature.md to nature-options.jpg. It uses 200 dpi horizontal and vertical resolution, an Alice Blue background, high-quality smoothing, and a 600 × 950 pixel page with custom margins.
1// Convert Markdown to JPG in Java with custom settings
2
3// Convert Markdown to HTML
4HTMLDocument document = Converter.convertMarkdown("nature.md");
5
6// Initialize ImageSaveOptions
7ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Jpeg);
8options.setSmoothingMode(SmoothingMode.HighQuality);
9options.setHorizontalResolution(Resolution.to_Resolution(200));
10options.setVerticalResolution(Resolution.to_Resolution(200));
11options.setBackgroundColor(Color.getAliceBlue());
12options.getPageSetup().setAnyPage(new Page(new Size(600, 950), new Margin(30, 20, 10, 10)));
13
14// Convert HTML to JPG
15Converter.convertHTML(document, options, "nature-options.jpg");Download complete Java examples and data files from GitHub.
Yes. Use the free online Markdown to Image Converter for a quick manual conversion. Aspose.HTML for Java is a commercial API for programmatic conversion and can be evaluated before licensing; see Licensing.
Choose PNG when text sharpness, lossless output, or transparency is important. Choose JPG when a smaller file is more important and transparency is not required. Use BMP when a simple bitmap format is required, TIFF for archival or configurable compression workflows, and GIF when that format is required by the target system. These outputs are static raster images.
Use the free online Markdown to Image Converter for quick manual conversion without writing Java code.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.