Free Support Forum - aspose.com

Incorrect HTML to PDF conversion result using Java API compared to the online HTML to PDF conversion

Tried to convert the HTML file included here: test_aspose.zip (1.5 KB) using the following Java code:

public StreamingResponseBody asposePdf(@RequestParam(name="html") final String htmlInput) throws Exception {
    final var license = new com.aspose.html.License();
    license.setLicense(TestController.class.getResourceAsStream("/Aspose.HTML.Java.lic"));
    final var pdfSaveOptions = new com.aspose.html.saving.PdfSaveOptions();
    pdfSaveOptions.setJpegQuality(100);
    pdfSaveOptions.getCss().setMediaType(com.aspose.pdf.internal.html.rendering.MediaType.Screen);
    final var document = new com.aspose.html.HTMLDocument(htmlInput, ".");
    try {
        final var out = new ByteArrayOutputStream();
        final var device = new com.aspose.html.rendering.pdf.PdfDevice(pdfSaveOptions, out);
        document.renderTo(device);
        return streamResponse(out.toByteArray());
    } finally {
        document.dispose();
    }
}

and the result is different (wrong alignment and formatting, table does not render) compared to the same input begin used in: https://products.aspose.app/html/en/conversion/html-to-pdf.

Any idea why this happens ?

I am using a temporary license for Aspose.HTML with Aspose Java v 21.4 running on a Spring Boot 2.4.4 application.

For comparison
Online tool result: test_aspose.pdf (67.1 KB)
Java API result: response.pdf (80.1 KB)

@alin.treznai

We would like to share with you that Aspose.HTML for .NET has been implemented behind the online utility of HTML to PDF conversion. We are in process to port all .NET features and improvement in Java version of the API and as soon as it is done, the results of conversion will be better.

We have further log a ticket as HTMLJAVA-803 in our issue tracking system for this case. We will look into its details and let you know as soon as it is fixed. Please be patient and spare us some time.

We apologize for the inconvenience.