How can I change the html encoding to render the pdf correctly with openhtmltopdf?

635 Views Asked by At

I am using the code: https://github.com/danfickle/openhtmltopdf Did everything according to the example from here (created a maven project, created a main-class): https://www.netjstech.com/2021/02/convert-html-to-pdf-java-Openhtmltopdf-PDFBox.html I am feeding html as input, but I have two problems:

  1. Russian letters and some icons (for example, №) are not displayed, instead it writes ###. I tried to connect fonts. Downloaded from here: https://fonts.google.com/specimen/Open+Sans#standard-styles In the main class I wrote: builder.useFont (new File (" OpenSans-ExtraBold.ttf ")," OpenSans-ExtraBold "); But still the pdf displays ###.
  2. The pdf file is cropped (50% of the information on the right is not displayed). You need to change the scale or make it landscape. I tried to edit the html itself so that the program would process it correctly, but it didn't work either.
<html lang =" ru ">
<head>
<META http-equiv = "Content-Type" content = "text / html; charset = UTF-8" /> 

As I understand it, it's not about the fonts and orientation, but the html encoding. What should I change in it?

html: https://file.io/x8GCNFpgML7S pdf: https://file.io/VUJ3s1jZBux8

0

There are 0 best solutions below