Unable to see and print Chinese in PDF
-
Customer entered Chinese character in the name and address fields. I am not able to see it on the PDF invoice. It doesn’t display properly. How to solve this?
-
Hey @ezekielion,
Some languages (Japanese, Chinese, etc.) are not supported by the default font included with the plugin, so a custom font is required. See Using Custom Fonts
For our paying users we also have a Chinese language pack available that is just a “plug-and-play” solution, no coding required. WordPress does not allow for support of paid software here in the forums, so email us at [email protected] if you are interested in the language pack.
I copied all the files from wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/Simple to the child theme. I tried the custom fonts. It didn’t work. Added to the style.css
/* Load font */
@font-face {
font-family: 'NotoSansTC-Regular';
font-style: normal;
font-weight: normal;
src: local('NotoSansTC-Regular'), local('NotoSansTC-Regular'), url(get_template_path(); ?>/fonts/NotoSansTC-Regular.ttf) format('truetype');
}
@font-face {
font-family: 'NotoSansTC-Regular';
font-style: normal;
font-weight: bold;
src: local('NotoSansTC-Regular Bold'), local('NotoSansTC-Regular-Bold'), url(get_template_path(); ?>/fonts/NotoSansTC-Regular-bold.ttf) format('truetype');
} body {
background: #fff;
color: #000;
margin: 0cm;
font-family: ‘NotoSansTC-Regular’;
/* want to use custom fonts? https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/using-custom-fonts/ / font-size: 9pt; line-height: 100%; / fixes inherit dompdf bug */
overflow-wrap: anywhere;
}and Enabled font subsetting.
Chose “chinese” under Choose a Template.
PDF still shows squares wherever there is Chinese characters.
Your URL path in the
scr
property have incomplete syntax. They are missing theecho
action. Try this:src: local('NotoSansTC-Regular'), local('NotoSansTC-Regular'), url(<?php echo get_template_path(); ?>/fonts/NotoSansTC-Regular.ttf) format('truetype');
src: local('NotoSansTC-Regular Bold'), local('NotoSansTC-Regular-Bold'), url(<?php echo get_template_path(); ?>/fonts/NotoSansTC-Regular-bold.ttf) format('truetype');
Got 200: parsererror
/* Load font */
@font-face {
font-family: 'NotoSansTC-Regular';
font-style: normal;
font-weight: normal;
src: local('NotoSansTC-Regular'), local('NotoSansTC-Regular'), url(/fonts/NotoSansTC-Regular.ttf) format('truetype'); }
@font-face {
font-family: 'NotoSansTC-Regular';
font-style: normal;
font-weight: bold;
src: local('NotoSansTC-Regular Bold'), local('NotoSansTC-Regular-Bold'), url(/fonts/NotoSansTC-Regular-bold.ttf) format('truetype');
} body {
background: #fff;
color: #000;
margin: 0cm;
font-family: ‘NotoSansTC-Regular’;
/* want to use custom fonts? https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/using-custom-fonts/ / font-size: 9pt; line-height: 100%; / fixes inherit dompdf bug */
overflow-wrap: anywhere;
}The
src
property seems to be missing the code that gets the template path. Could you add it like I had show before and let us know if it works?Yes, this was the same code I entered. When I pasted it, this comment area removed the echo line when I pasted the whole thing. This is the individual line
src: local('NotoSansTC-Regular'), local('NotoSansTC-Regular'), url(<?php echo get_template_path(); ?>/fonts/NotoSansTC-Regular.ttf) format('truetype');
The second one
src: local('NotoSansTC-Regular Bold'), local('NotoSansTC-Regular-Bold'), url(<?php echo get_template_path(); ?>/fonts/NotoSansTC-Regular-bold.ttf) format('truetype');
and got 200: parsererror
Could you share a link to download the fonts, so that I can try them on my setup, please?
Thanks for the link. I’ve been able to load the font in a custom template without issue: https://ibb.co/zs7dvg0
My CSS code:
@font-face { font-family: "NotoSansTC"; font-style: normal; font-weight: normal; src: local("NotoSansTC Regular"), local("NotoSansTC-Regular"), url(<?php echo $this->get_template_path(); ?>/fonts/NotoSansTC-Regular.ttf ) format("truetype"); } @font-face { font-family: "NotoSansTC"; font-style: lighter; font-weight: lighter; src: local("NotoSansTC Lighter"), local("NotoSansTC-Lighter"), url(<?php echo $this->get_template_path(); ?>/fonts/NotoSansTC-Light.ttf) format("truetype"); } @font-face { font-family: "NotoSansTC"; font-style: bold; font-weight: bold; src: local("NotoSansTC Bold"), local("NotoSansTC-Bold"), url(<?php echo $this->get_template_path(); ?>/fonts/NotoSansTC-Bold.ttf) format("truetype"); } body { background: #fff; color: #000; margin: 0cm; font-family: "NotoSansTC"; /* want to use custom fonts? https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/using-custom-fonts/ */ font-size: 9pt; line-height: 100%; /* fixes inherit dompdf bug */ overflow-wrap: anywhere; }
Perhaps the error you have is related to some other issue in your template? Do you find any errors in your logs as outlined here? You’re looking for logs prefixed with wpo-wcpdf or fatal_error
@font-face { font-family: 'NotoSansTC'; font-style: normal; font-weight: normal; src: local('NotoSansTC Regular'), local('NotoSansTC-Regular'), url(<?php echo get_template_path(); ?>/fonts/NotoSansTC-Regular.ttf) format('truetype'); } @font-face { font-family: 'NotoSansTC'; font-style: normal; font-weight: bold; src: local('NotoSansTC Regular Bold'), local('NotoSansTC-Regular-Bold'), url(<?php echo get_template_path(); ?>/fonts/NotoSansTC-Regular-bold.ttf) format('truetype'); } body { background: #fff; color: #000; margin: 0cm; font-family: ‘NotoSansTC’; /* want to use custom fonts? https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/using-custom-fonts/ */ font-size: 9pt; line-height: 100%; /* fixes inherit dompdf bug */ overflow-wrap: anywhere; }
What is wrong with this code?
I had an error log when I copied style.css to the original folder. I have since reversed it.
2023-12-26T15:33:43+00:00 CRITICAL Fatal error: Call to undefined function get_template_path() (/var/www/vhosts/ezekiel-ion.com/httpdocs/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/Simple/style.css:13)
Line 13 is
src: local('NotoSansTC Regular'), local('NotoSansTC-Regular'), url(<?php echo get_template_path(); ?>/fonts/NotoSansTC-Regular.ttf) format('truetype');
- This reply was modified 11 months ago by ezekielion.
- This reply was modified 11 months ago by ezekielion.
It’s related to how the
get_template_path
function is called. It has to be written like so:$this->get_template_path()
the$this->
needs to be prefixed onto the function. So your full code should look like so:url(<?php echo $this->get_template_path(); ?>/fonts/NotoSansTC-Regular.ttf ) format("truetype");
OK. I copied exactly your code over and the error is gone. It seems to display now. Thank you!
No problem ??
I will mark this topic as resolved.
Also, if you don’t mind and have the time, do you think you could leave us a review on www.remarpro.com or on Trustpilot?
Thanks in advance and all the best with the store!
- The topic ‘Unable to see and print Chinese in PDF’ is closed to new replies.