0
votes

I am trying to convert html with some Chinese characters to pdf, and they are getting cut off. It's as if Chinese fonts require the space of 2 roman letters, but are only getting one. Text I'm trying to render: (周大鹏)įšėęčųū

See how it looks: enter image description here

I have tried using Noto Sans CJK SC font to render this, and Chinese glyphs looked fine, but then special baltic letters would get spaced badly. I tried specifying font family separated by commas like: font-family: 'Noto Sans', 'Noto Sans CJK SC', sans-serif; but then either letters were spaced, or Chinese characters would get clipped.

In web everything looks fine, it's only when generating PDF that this happens. I am using version 0.12.3 of wkhtmltopdf.

1

1 Answers

0
votes

I was having problems with Chinese characters rendering properly and fixed it using a .fonts.conf file.

On CentOS that meant adding a slightly amended version (below) of this xml file:

https://wiki.debian.org/Fonts#Subpixel-hinting_and_Font-smoothing

which I found out about here:

https://github.com/wkhtmltopdf/wkhtmltopdf/issues/45#issuecomment-34543222

to the /etc/fonts/conf.d/ folder. I named the file 10-wkhtmltopdf.conf so that it would be loaded first.

The xml file was changed to set 'hintstyle' to 'hintfull' instead of 'hintslight'.

This .fonts.conf file also helps to fix font kerning issues.

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
	<match target="font">
		<edit mode="assign" name="rgba">
			<const>rgb</const>
		</edit>
	</match>
	<match target="font">
		<edit mode="assign" name="hinting">
			<bool>true</bool>
		</edit>
	</match>
	<match target="font">
		<edit mode="assign" name="hintstyle">
			<const>hintfull</const>
		</edit>
	</match>
	<match target="font">
		<edit mode="assign" name="antialias">
			<bool>true</bool>
		</edit>
	</match>
	<match target="font">
		<edit mode="assign" name="lcdfilter">
			<const>lcddefault</const>
		</edit>
	</match>
</fontconfig>