We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Unable to create PDF from HTML

I need to convert Html to Pdf in my web application and I downloaded Aspose.html (Java) library (aspose-html-18.11.1.jar) for that purpose. I tried following code in my Play (Scala) web application:

  val document = new HTMLDocument("https://www.lipsum.com/feed/html")
  val options = new PdfRenderingOptions()
  val device = new PdfDevice(options, "/Users/nikhilm/Downloads/aspose.pdf");
  val renderer = new HtmlRenderer();
  renderer.render(device, document)   

But I get following run time error:

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[AssertionError: Cannot read a name from the name table in a font.]]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:293)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:220)
at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:100)
at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99)
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:346)
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:345)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:36)
at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:70)
at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:44)
at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:252)
Caused by: java.lang.AssertionError: Cannot read a name from the name table in a font.
at com.aspose.html.internal.ms.System.Diagnostics.Debug.fail(Unknown Source)
at com.aspose.html.internal.p31.z26.m306(Unknown Source)
at com.aspose.html.internal.p31.z26.m666(Unknown Source)
at com.aspose.html.internal.p31.z26.m2(Unknown Source)
at com.aspose.html.internal.p31.z11.m1(Unknown Source)
at com.aspose.html.internal.p31.z11.(Unknown Source)
at com.aspose.html.internal.p31.z8.m618(Unknown Source)
at com.aspose.html.internal.p31.z8.m617(Unknown Source)
at com.aspose.html.internal.p31.z8.m7(Unknown Source)
at com.aspose.html.internal.p31.z10.m2(Unknown Source)


Thank you for contacting support.

Would you please try to install attached fonts in your environment and then share your kind feedback with us. Moreover, the problem maybe environment specific so you may try to Download a Webpage in Java as explained here, to rule out any chances of it not being related to your environment but with Aspose.HTML for Java API. Fonts.zip

This is not an environment issue as I receive the same error if i use an html file from the file system. I am also attaching the input html file (template_ext.zip) for your reference. Only thing that will not work is the absolute paths to the resources such as images and fonts used in this input html file. The PDF generator should ignore that and instead generate an output pdf file without those resources. Just FYI: I tried a few open source and commercial html to pdf converters (itext, pdfbox, pdfreactor, wkhtmltopdf, sejda, headless chrome, etc.) and in all cases I am able to generate an output pdf file without having to config any extra setup. template_ext.zip (837.2 KB)
NOTE: I changed the extension of file name to .zip deliberately so that it could be uploaded. It’s just a html (text) file.


Thank you for elaborating it further.

We have logged a ticket with ID HTMLJAVA-227 in our issue managements system for further investigations. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.