Jvm crashes while HTML to PDF conversion

JVM is crashing while converting HTML to PDF.
Java Version - Open JDK 11.0.1
Java memory - MAX 1024 MB, Min - 256MB

Java Code to convert Html to PDF

    // Create a HTML LoadOptions
    HtmlLoadOptions options = new HtmlLoadOptions();

    // Set Print or Screen mode
   options.setHtmlMediaType(HtmlMediaType.Print);
   options.getPageInfo().getMargin().setLeft(30);
   options.getPageInfo().getMargin().setRight(30);
   options.getPageInfo().getMargin().setTop(40);
   options.getPageInfo().getMargin().setBottom(40);
   
    // Initialize document object

    InputStream is = new FileInputStream("D:/Test/Input_file.html")
    Document document = new Document(is, options);

    // Save output PDF document
    OutputStream out = new FileOutputStream("D:/Test/Converted_file.pdf");
    document.save(out);
    
    document.freeMemory();
    document.close();
    
    out.close();

JVM log is attached
hs_err_pid4788.zip (22.0 KB)

@dhawal

Please share your sample HTML file in .zip format as well. We will test the scenario in our environment and address it accordingly. Please also make sure to use the 21.7 version of the API before sharing the file.

Hi Asad,
Please find the sample html
SampleHtml.zip (9.4 KB)

JVM is crashing if running multiple threads.
30-50 threads simultaneously converting their own html file into pdf.

We are using latest Aspose 21.7.

@dhawal

Please check the below code snippet that we used to test the scenario at our end.

try{
 File folder = new File(dataDir + "testfiles\\");
 File[] listOfFiles = folder.listFiles();
 for (int i = 0; i < listOfFiles.length; i++){
  final int index = i;
  Thread t = new Thread(() -> {
  try {
   System.out.println("Processing " + dataDir + "testfiles\\" + listOfFiles[index].getName());
   HTMLtoPDF(dataDir + "testfiles\\" + listOfFiles[index].getName(), dataDir + "testfiles\\output" + index + ".pdf");
   System.out.println("Saved " + dataDir + "testfiles\\output" + index + ".pdf");
  } catch (Exception e) {
   e.printStackTrace();
  }
 });

 t.start();
}
}catch(Exception ex) {
 ex.printStackTrace();
}

public void HTMLtoPDF(String infile, String outfile)
{
 HtmlLoadOptions options = new HtmlLoadOptions();
 options.setHtmlMediaType(HtmlMediaType.Print);
 options.getPageInfo().getMargin().setLeft(30);
 options.getPageInfo().getMargin().setRight(30);
 options.getPageInfo().getMargin().setTop(40);
 options.getPageInfo().getMargin().setBottom(40);

 Document document = new com.aspose.pdf.Document(infile, options);
 document.save(outfile);
}

When we used JDK1.8, the code executed successfully and produced correct PDF files against every provided HTML file. However, the program kept running for more than 20 minutes and did not produce any output with JDK11. Can you please confirm if the same issue is occurring at your end as well? We will further proceed to assist you accordingly.

Hi Asad,

Is there any way… we can use OpenJDK 11.0.1
Because our production system supports OpenJDK 11.0.1 and above. We can NOT downgrade to java 8.

@dhawal

There should not be any issue in JDK 11 as API supports it. However, we need to investigate why this particular scenario is failing under this environment. For the purpose, we have logged an investigation ticket as PDFJAVA-40698 in our issue tracking system. We will further look into its details and keep you posted with the status of ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.