Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active September 17, 2024 20:42
Show Gist options
  • Save aspose-com-gists/71dba80e79fc2b8050ed053c865c2b64 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/71dba80e79fc2b8050ed053c865c2b64 to your computer and use it in GitHub Desktop.
Convert Markdown to PNG in Java using a Markdown Processor
package com.example;
import com.aspose.html.converters.Converter;
import com.aspose.html.rendering.image.ImageFormat;
import com.aspose.html.saving.ImageSaveOptions;
import com.aspose.html.HTMLDocument;
public class main {
// Convert MD to PNG in Java
public static void main(String[] args) {
String dir = "/Desktop/";
// Create an instance of the HTMLDocument class.
// Convert markdown to an HTML document by calling the Converter.convertMarkdown method.
HTMLDocument document = Converter.convertMarkdown(dir+"sample.md");
try {
// Initialize an instance of the ImageSaveOptions class with the PNG image format.
// Pass the object of the ImageSaveOptions class to the Converter.convertHTML method and convert HTML document to PNG in Java programmatically.
Converter.convertHTML(
document,
new ImageSaveOptions(
ImageFormat.Png
),
dir+"/output_md.png"
);
} finally {
if (document != null) {
document.dispose();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment