How to support multiple language in openhtmltopdf

Open HTML to PDF is a pure-Java library for rendering a reasonable subset of well-formed XML/XHTML (and even some HTML5) using CSS 2.1 (and later standards) for layout and formatting, outputting to PDF or images.

https://github.com/danfickle/openhtmltopdf

By default this library supports (serif, sans-serif, monospace). The fonts only support a basic Western European character set and it is now usually recommended that you embed fonts that you wish to use.

If no glyph is found for a character in any of the specified fonts (plus serif) the behavior is as follows. Control character codes will be ignored, whitespace characters will be replaced with the space character and any other character will be replaced with the replacement character (# by default).

So to support different languages we need to add font which have these glyph to avoid # problem. I found Notos -Sans from https://fonts.google.com/ download the font in TrueType (ttf) format

Upload this font to your CDN or CMS, S3 where you generally put your static files. Then use that url to download that font-family

Import the font in your html

@font-face {
          font-family: 'Noto Sans';
          font-style: normal;
          font-weight: 400;
          font-display: swap;
          src: url(https://cdn.yourwebsite.io/fonts/NotoSans-Regular.ttf);
        }
      body {
        font-family: Arial, sans-serif;
        font-family: Arial, sans-serif, 'Noto Sans';
        font-size: 10px;
      }

Voila!! Now you can view language

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *