Hello!
I convert HTML to PDF
import com.aspose.pdf.*;
import com.aspose.pdf.HtmlSaveOptions.PartsEmbeddingModes;
import com.aspose.pdf.HtmlSaveOptions.RasterImagesSavingModes;
...
public byte[] createDocumentFromHtml(File htmlFile) {
HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions();
htmlLoadOptions.setHtmlMediaType(HtmlMediaType.Print);
OptimizedMemoryStream optimizedMemoryStream;
try (Document document = new Document(htmlFile.getAbsolutePath(), htmlLoadOptions)) {
optimizedMemoryStream = new OptimizedMemoryStream();
document.save(optimizedMemoryStream.toOutputStream(), SaveFormat.Pdf);
}
return optimizedMemoryStream.toArray().clone();
}
but but I got the NPE
java.lang.NullPointerException
at com.aspose.pdf.internal.l32f.l8t.lI(Unknown Source)
at com.aspose.pdf.internal.l33h.lu.lI(Unknown Source)
at com.aspose.pdf.internal.l33h.lu.lI(Unknown Source)
at com.aspose.pdf.internal.l33h.lu.lI(Unknown Source)
at com.aspose.pdf.internal.l33h.lu.lj(Unknown Source)
at com.aspose.pdf.internal.l32h.lb.lI(Unknown Source)
at com.aspose.pdf.internal.html.HTMLElement.getStyle(Unknown Source)
at com.aspose.pdf.internal.l32h.lb.lI(Unknown Source)
at com.aspose.pdf.internal.l32h.l0n.lf(Unknown Source)
at com.aspose.pdf.internal.l32h.l0u.lj(Unknown Source)
at com.aspose.pdf.internal.l32h.lb.lI(Unknown Source)
at com.aspose.pdf.internal.l32h.lb.lI(Unknown Source)
at com.aspose.pdf.internal.l51f.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l42n.lt.lI(Unknown Source)
at com.aspose.pdf.internal.l42n.lf.lj(Unknown Source)
at com.aspose.pdf.internal.html.collections.lj.lj(Unknown Source)
at com.aspose.pdf.internal.html.collections.lj.hasNext(Unknown Source)
at com.aspose.pdf.internal.l50k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.html.rendering.l0if.lI(Unknown Source)
at com.aspose.pdf.internal.html.rendering.l0if.lI(Unknown Source)
at com.aspose.pdf.internal.html.rendering.l1t.lI(Unknown Source)
at com.aspose.pdf.internal.html.rendering.l1t.lI(Unknown Source)
at com.aspose.pdf.l7n.lf(Unknown Source)
at com.aspose.pdf.l7n.lI(Unknown Source)
at com.aspose.pdf.l7n.lI(Unknown Source)
at com.aspose.pdf.ADocument.lI(Unknown Source)
at com.aspose.pdf.ADocument.<init>(Unknown Source)
at com.aspose.pdf.Document.<init>(Unknown Source)
at hr.resume.logic.document.PdfConverter.createDocumentFromHtml(PdfConverter.java:44)
But when I convert via the aspose website or to the docx format (aspose-words), there are no problems
file_with_problem.zip (65,2 КБ)
Aspose ver 22.10, but the latest version (24.7) has this bug
Please tell me, is there any way to avoid the error?