In order to view MHT, we’ll use Aspose.PDF for Java API which is a feature-rich, powerful and easy to use conversion API for Java platform. You can download its latest version directly from Maven and install it within your Maven-based project by adding the following configurations to the pom.xml.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java AP</name>
<url>https://releases.aspose.com/java/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>version of aspose-pdf API</version>
</dependency>
View MHT files via Java
You need Aspose.PDF for Java to try the code in your environment.
- Load the MHT with an instance of Document.
- View resultant File.
Java - example code to view MHT file
MhtLoadOptions options= new MhtLoadOptions();
Resolution resolution = new Resolution(300);
BmpDevice imageDevice = new BmpDevice(resolution);
Document pdfDocument= new Document(_dataDir + "test.mhtm", options);
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
using (FileStream imageStream =
new FileStream($"{_dataDir}image{pageCount}_out.{ext}", FileMode.Create))
{
// Convert a particular page and save the image to stream
imageDevice.Process(pdfDocument.Pages[pageCount], imageStream);
// Close stream
imageStream.Close();
}
}