openhtmltopdf icon indicating copy to clipboard operation
openhtmltopdf copied to clipboard

Handsontable - NPE

Open ricardomaleixo opened this issue 6 years ago • 3 comments

When have i a Handsontable inside my HTML and use openHtmlToPdf, at the point when builder.run(); i have a NPE.

com.openhtmltopdf.pdfboxout.PdfBoxFontResolver.resolveFont(PdfBoxFontResolver.java:85) ~[openhtmltopdf-pdfbox-1.0.4.jar:na] com.openhtmltopdf.layout.SharedContext.getFont(SharedContext.java:353) ~[openhtmltopdf-core-1.0.4.jar:na]

ricardomaleixo avatar Oct 28 '20 14:10 ricardomaleixo

Hi @ricardomaleixo,

I think Handsontable requires JavaScript? which we don't evaluate. However, we shouldn't be crashing here regardless so if you can show the HTML, I'll have a look.

danfickle avatar Oct 28 '20 14:10 danfickle

hi, @danfickle, thanks for responding fast! this HTML is built dynamically according to some business rules. we build different pages with different configurations, which allows the user to build customized pages. in the end, we merged all these pages. the result is a HUGE html, and using openHTMLtoPDF solves the most serious problems, but not with the handsontable that breaks.

I also used 'https://sandbox.openhtmltopdf.com/' for testing. but it is not successful.

the file it's below. out.zip

ricardomaleixo avatar Oct 28 '20 14:10 ricardomaleixo

I ran it with this throwaway code. No NPE was raised:

package com.example;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;

public class App8 {
    public static void main(String... args) throws IOException {
        PdfRendererBuilder builder = new PdfRendererBuilder();

        builder.toStream(new FileOutputStream("C://Users//dan//Desktop//out.pdf"));
        builder.useFastMode();
        builder.withFile(new File("C://Users//dan//Desktop//out.html"));
        builder.run();
    }
}

However, I had to alter line 287 from: display: inline !important; to min-width: 100%; to get Chrome equivalent output.

Are you perhaps running in PDF/UA compliant mode? In that case, you must make sure a font is defined for all content (including running elements and body tag) because the PDF built-in fall-back fonts are not used in that mode.

PS: I would be wary of using a Google Fonts remote stylesheet in production. The contents are basically undocumented and we don't cache remote stylesheets so may upset Google if running frequently.

If the builder code you are using and getting NPE with is succinct, you can post it here.

danfickle avatar Oct 30 '20 11:10 danfickle