I have a utility class that news up a HTMLDocument from a stream and then manipulates it to produce an updated HTMLDocument. With the same input stream the code works fine in a test application but when deployed and called from within a java servlet it throws this error:
com.aspose.html.utils.ahx: The given key was not present in the dictionary.
at com.aspose.html.utils.aho.E(Unknown Source) ~[aspose-html-23.8-jdk1.8.jar:?]
at com.aspose.html.utils.cw.bH(Unknown Source) ~[aspose-html-23.8-jdk1.8.jar:?]
at com.aspose.html.utils.Js.d(Unknown Source) ~[aspose-html-23.8-jdk1.8.jar:?]
at com.aspose.html.utils.IQ$c.a(Unknown Source) ~[aspose-html-23.8-jdk1.8.jar:?]
at com.aspose.html.utils.K.<init>(Unknown Source) ~[aspose-html-23.8-jdk1.8.jar:?]
at com.aspose.html.utils.K.<init>(Unknown Source) ~[aspose-html-23.8-jdk1.8.jar:?]
at com.aspose.html.HTMLDocument.<init>(Unknown Source) ~[aspose-html-23.8-jdk1.8.jar:?]
at com.aspose.html.HTMLDocument.<init>(Unknown Source) ~[aspose-html-23.8-jdk1.8.jar:?]
at com.aspose.html.HTMLDocument.<init>(Unknown Source) ~[aspose-html-23.8-jdk1.8.jar:?]
at com.bct.geodatafy.htmlpreview.HtmlPreviewUtility.addPreviewScriptToHtml(HtmlPreviewUtility.java:120) ~[htmlpreview-2.3.jar:?]
A fragment of my code shows how I am creating a HTMLDocument:
/**
* Add html elements , javascript and css to html to add a search bar to the
* html document Set the initial search terms to searchText. Buttons in the
* toolbar may be used to navigate between matches. Various search options
* may also be set in the toolbar.
*
* @param htmlStream
* A ByteArrayOutputStream containing the html document
* @param searchText
* The initial search terms to use. Matches will be highlighted
* @return a HTMLDocument
*/
public HTMLDocument addPreviewScriptToHtml(ByteArrayOutputStream htmlStream, String searchText)
{
byte[] bytes = htmlStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(htmlStream.toByteArray());
m_Doc = new HTMLDocument(inputStream, ".");
The last line is where the exception is thrown…
I am using the aspose-html-23.8-jdk1.8.jar library .
@clayharter
Can you please share your sample HTML in .zip format as well? We will log an investigation ticket and share the ID with you.
If I create an HTMLDocument from the attached file it works fine except when executed within a Jetty servlet. In this case I get this error:
2023-11-12 09:41:07,813 [qtp384294141-107] ERROR com.bct.geodatafy.FileServiceServlet [] - Error converting document to html preview: The given key was not present in the dictionary.
com.aspose.html.utils.ms.System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at com.aspose.html.utils.ms.System.Collections.Generic.Dictionary.get_Item(Unknown Source) ~[aspose-html-23.10.jar:?]
at com.aspose.html.utils.cw.get(Unknown Source) ~[aspose-html-23.10.jar:?]
at com.aspose.html.utils.EZ.d(Unknown Source) ~[aspose-html-23.10.jar:?]
at com.aspose.html.utils.Ex$c.a(Unknown Source) ~[aspose-html-23.10.jar:?]
at com.aspose.html.utils.K.<init>(Unknown Source) ~[aspose-html-23.10.jar:?]
at com.aspose.html.utils.K.<init>(Unknown Source) ~[aspose-html-23.10.jar:?]
at com.aspose.html.HTMLDocument.<init>(Unknown Source) ~[aspose-html-23.10.jar:?]
at com.aspose.html.HTMLDocument.<init>(Unknown Source) ~[aspose-html-23.10.jar:?]
at com.aspose.html.HTMLDocument.<init>(Unknown Source) ~[aspose-html-23.10.jar:?]
at com.aspose.html.HTMLDocument.<init>(Unknown Source) ~[aspose-html-23.10.jar:?]
at com.bct.geodatafy.htmlpreview.HtmlPreviewUtility.convertPdfToHtmlDoc(HtmlPreviewUtility.java:46) ~[htmlpreview-2.3.jar:?]
My code looks like this:
public HTMLDocument convertPdfToHtmlDoc(String pdfPath, String htmlPath) throws Exception {
Document pdfDoc = new Document(pdfPath);
HtmlSaveOptions options = new HtmlSaveOptions();
options.setDocumentType(HtmlDocumentType.Html5);
options.setPartsEmbeddingMode(PartsEmbeddingModes.EmbedAllIntoHtml);
options.setRasterImagesSavingMode(RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground);
options.setFontSavingMode(com.aspose.pdf.HtmlSaveOptions.FontSavingModes.SaveInAllFormats);
pdfDoc.save(htmlPath, options);
HTMLDocument doc = new HTMLDocument(htmlPath);
return doc;
}
This error occurs for any pdf file.
htmldoc_1699804373299.zip (138.1 KB)
I am wondering if there is a library conflict between the jar files that are included in my war file and what the Aspose class expects?
These are the jar files included in my war:
aspose-html-23.10.jar
aspose-pdf-23.10.jar
bcprov-jdk15on-1.70.jar
caffeine-2.7.0.jar
checker-qual-2.6.0.jar
commons-codec-1.11.jar
commons-io-2.8.0.jar
commons-lang-2.6.jar
commons-logging-1.2.jar
commons-math3-3.6.1.jar
error_prone_annotations-2.3.3.jar
gson-2.2.4.jar
htmlpreview-2.3.jar
http2-client-9.4.44.v20210927.jar
http2-common-9.4.44.v20210927.jar
http2-hpack-9.4.44.v20210927.jar
http2-http-client-transport-9.4.44.v20210927.jar
httpclient-4.5.13.jar
httpclient-win-4.5.13.jar
httpcore-4.4.14.jar
httpmime-4.5.13.jar
javax.json-1.1.jar
jcip-annotations-1.0-1.jar
jcl-over-slf4j-2.0.0-alpha1.jar
jettison-1.3.jar
jetty-alpn-client-9.4.44.v20210927.jar
jetty-alpn-java-client-9.4.44.v20210927.jar
jetty-alpn-openjdk8-client-9.4.44.v20210927.jar
jetty-client-9.4.46.v20220331.jar
jetty-continuation-9.4.46.v20220331.jar
jetty-http-9.4.46.v20220331.jar
jetty-io-9.4.46.v20220331.jar
jetty-proxy-9.4.46.v20220331.jar
jetty-security-9.4.46.v20220331.jar
jetty-server-9.4.46.v20220331.jar
jetty-servlet-9.4.46.v20220331.jar
jetty-servlets-9.4.46.v20220331.jar
jetty-util-9.4.46.v20220331.jar
jetty-util-ajax-9.4.46.v20220331.jar
jna-5.5.0.jar
jna-platform-5.5.0.jar
json-20190722.jar
list.txt
log4j-api-2.17.1.jar
log4j-core-2.17.1.jar
netty-buffer-4.1.68.Final.jar
netty-codec-4.1.68.Final.jar
netty-common-4.1.68.Final.jar
netty-handler-4.1.68.Final.jar
netty-resolver-4.1.68.Final.jar
netty-transport-4.1.68.Final.jar
netty-transport-native-epoll-4.1.68.Final.jar
netty-transport-native-unix-common-4.1.68.Final.jar
nimbus-jose-jwt-9.19.jar
slf4j-api-2.0.0-alpha1.jar
snappy-java-1.1.7.6.jar
solr-solrj-8.11.1.jar
stax-api-1.0.1.jar
stax2-api-4.2.1.jar
waffle-jna-2.2.1.jar
woodstox-core-6.2.4.jar
zookeeper-3.6.2.jar
zookeeper-jute-3.6.2.jar
@clayharter
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-1628
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.