language java 21
library
aspose-html 25.2.2
During conversion from mht to pdf, exception is thrown
Mar 03, 2025 1:12:47 PM sun.rmi.transport.tcp.TCPTransport$AcceptLoop run
WARNING: RMI TCP Accept-0: accept loop for ServerSocket[addr=0.0.0.0/0.0.0.0,localport=54181] throws
java.lang.OutOfMemoryError: Java heap space
at java.base/sun.nio.ch.Net.accept(Native Method)
at java.base/sun.nio.ch.NioSocketImpl.accept(NioSocketImpl.java:748)
at java.base/java.net.ServerSocket.implAccept(ServerSocket.java:698)
at java.base/java.net.ServerSocket.platformImplAccept(ServerSocket.java:663)
at java.base/java.net.ServerSocket.implAccept(ServerSocket.java:639)
at java.base/java.net.ServerSocket.implAccept(ServerSocket.java:585)
at java.base/java.net.ServerSocket.accept(ServerSocket.java:543)
at jdk.management.agent/sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:52)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:424)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:388)
at java.base/java.lang.Thread.runWith(Thread.java:1596)
at java.base/java.lang.Thread.run(Thread.java:1583)
Incompatible unit types.
input file
Welcome!.zip (21.2 KB)
output file
Welcome!_html.pdf (109.6 KB)
@divine1
The java.lang.OutOfMemoryError: Java heap space
exception you are encountering during the conversion from MHT to PDF using Aspose.HTML typically indicates that the Java Virtual Machine (JVM) has run out of memory. This can happen if the MHT file you are trying to convert is too large or if the memory allocated to the JVM is insufficient for the operation.
Here are some steps you can take to resolve this issue:
-
Increase Java Heap Size: You can increase the maximum heap size allocated to the JVM. This can be done by setting the -Xmx
option when starting your Java application. For example, you can set it to 512MB or more depending on your needs:
java -Xmx512m -jar your-application.jar
-
Optimize MHT File: If possible, try to reduce the size of the MHT file. This can include removing unnecessary images or content that may not be needed for the PDF conversion.
-
Use Streaming: If your application allows, consider processing the MHT file in smaller chunks or using streaming to handle large files more efficiently.
-
Check for Memory Leaks: Ensure that your application does not have memory leaks that could be consuming memory unnecessarily.
-
Monitor Memory Usage: Use tools like VisualVM or JConsole to monitor the memory usage of your application while it runs. This can help you identify if there are specific points in your code that are consuming excessive memory.
If you continue to experience issues after trying these solutions, consider reaching out to the Aspose support forum for further assistance, as they may have additional insights or updates regarding memory management in their library.
For more detailed guidance on converting MHT files to PDF, you can refer to the official Aspose documentation, which provides step-by-step instructions and examples for using their library effectively.
Sources:
[1]: MHT To PDF | Aspose.PDF for .NET API Reference
[2]: MHTML Converter - Convert MHTML in Python - Aspose Documentation
when i tested with aspose-html 25.3 , i receive “Incompatible unit types.” message. but output got generated.
please fix this new issue.
the issue reported in original question doesnot appear in 25.3 . it showed up in 25.2
@divine1
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): HTMLJAVA-2023
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.