Markdown and HTML are the two most popular mark-up languages used on the web. Markdown is an easy, lightweight language to format text using symbols. Whereas, HTML lets users design complex web structures with the help of pre-defined and custom tags. In some cases, users prefer Markdown over HTML due to its robustness and simplicity. Therefore, in this article, we will convert HTML to Markdown or HTML to PNG in Java programmatically using API methods offered by Aspose.HTML for Java.
We will cover the following sections in this blog post:
- Convert HTML to Markdown or HTML to PNG in Java - API installation
- Java library to convert HTML to Markdown programmatically
- HTML to PNG conversion library in Java
Convert HTML to Markdown or HTML to PNG in Java - API installation
Aspose.HTML for Java offers a rich stack of file manipulation and conversion methods. It allows users to perform these actions with simple configurations. Therefore, the installation procedure of this HTML to Markdown or HTML to PNG conversion library is quite easy. You can either download the jar files or follow the following Maven configurations.
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>https://repository.aspose.com/repo/</url> </repository>
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose-html</artifactId> <version>21.12</version> <classifier>jdk1.8</classifier> </dependency>
Java library to convert HTML to Markdown
The following steps will be performed to convert HTML to .md file in a Java application.
- Create an object of HTMLDocument class and load the source HTML file.
- Initialize an object of MarkdownSaveOptions() class.
- Invoke this method convertHTML(HTMLDocument document, MarkdownSaveOptions options, java.lang.String outputPath) to convert a web page to Markdown file. This method will save the converted file at the mentioned path.
Now, copy and paste the following code snippet in your Java file:
HTML to PNG conversion library in Java
This section will demonstrate the steps and the code snippet to convert an HTML file to PNG file programmatically in Java.
Lets go through the following steps:
- Initiate an instance of HTMLDocument class and load the source HTML file.
- Create an object of ImageSaveOptions class to access the image attributes.
- Make a call to this convertHTML(HTMLDocument document, ImageSaveOptions options, java.lang.String outputPath) method to convert a HTML to PNG.
Get a Free License
You can avail a free temporary license to try the API without evaluation limitations.
In this blog post, we have learned how to convert HTML to Markdown or HTML to PNG in Java programmatically. We have noted down the steps and the code examples to test the HTML to .md & HTML to PNG conversion APIs. In addition, you can explore the documentation to learn about the other features. Moreover, conholdate.com is continuously writing new blog posts. Therefore, please stay in touch for the latest updates.
Ask a question
In case of any queries please feel free to write to us at the forum.