iText 7 html2pdf - Unicode checkbox not present in the generated PDF

Viewed 51

In the older implementation with iText 7.0.7 and html2pdf 1.0.4, unicode symbols from the HTML would display in the output PDF.

But after upgrading to iText 7.1.12 and html2pdf 3.0.1, the output does not show the unicode characters.

How do I get the older behavior back with new versions?

comparison of older and newer output

Sample input:

<html>
  <head>
  <title>STA Form</title>
  </head>
    <body>
      <table>
        <tbody>
          <tr>
            <td>Will today’s weather have a potential safety impact?</td>
            <td>
              &#x2611; Yes &nbsp; &nbsp;
              &#x2610; No
            </td>
          </tr>
        </tbody>
      </table>
  </body>
</html>
1 Answers

You just need to add a font that contains the characters/glyphs in question into the set of font that pdfHTML uses for conversion. By default pdfHTML's set of fonts does not guarantee the presence of each and every Unicode character.

In my case a font that has the desired symbols that I was able to locate on my Windows system is Segoe UI Symbol.

If I add this font into the Font Provider and pass the font provider into Converter Properties as follows, I get the desired result.

ConverterProperties properties = new ConverterProperties();
FontProvider fontProvider = new DefaultFontProvider();
fontProvider.addFont("C:/Windows/Fonts/seguisym.ttf");
properties.setFontProvider(fontProvider);
HtmlConverter.convertToPdf(new File("path/to/file.html"),
        new File("path/to/file.pdf"), properties);

result

Related