language java 21
library
aspose-html 25.2.2
During conversion from mht to pdf, exception is thrown
Cannot invoke "java.lang.Long.longValue()" because the return value of "com.aspose.html.HTMLCanvasElement.a(java.lang.Class, String, Object, String)" is null
input file
Palm (PalmDevs).zip (33.1 KB)
@divine1
The exception you’re encountering during the conversion from MHT to PDF, specifically Cannot invoke "java.lang.Long.longValue()"
, suggests that there might be an issue with the input MHT file or the way the conversion is being handled.
To troubleshoot this issue, you can follow these steps:
-
Check the Input File: Ensure that the MHT file you are trying to convert is not corrupted and is properly formatted. Sometimes, malformed HTML content can lead to unexpected exceptions during conversion.
-
Use Sample Code: You can refer to the following sample code for converting MHT to PDF using Aspose.HTML. This code initializes the necessary options and handles the conversion process:
package com.aspose.html.examples;
public class MHTMLToPDFConversion {
@org.junit.jupiter.api.Test
public void execute() throws Exception {
// Open the MHTML file for reading
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("path/to/your/sample.mht")) {
// Create an instance of PdfSaveOptions
com.aspose.html.saving.PdfSaveOptions options = new com.aspose.html.saving.PdfSaveOptions();
options.setJpegQuality(100); // Set JPEG quality if needed
// Specify the output file path
String outputFile = "path/to/your/output.pdf";
// Convert MHTML to PDF
com.aspose.html.converters.Converter.convertMHTML(fileInputStream, options, outputFile);
}
}
}
-
Update Library: Ensure that you are using the latest version of the Aspose.HTML library. Sometimes, bugs are fixed in newer releases, so updating to the latest version might resolve the issue.
-
Check for Known Issues: Review the Aspose forums or documentation for any known issues related to MHT to PDF conversion. There might be specific cases or bugs that have been documented.
If the problem persists after trying these steps, consider reaching out to Aspose support with details about your input file and the exact code you are using for further assistance.
Feel free to ask if you need more help!
@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-2002
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.
same issue exists in aspose-html 25.3
@divine1
The issue still exists because it hasn’t been yet resolved. We are working on it and as soon as it is fixed, we will inform you. Please be patient and spare us some time.