.html method can't handle Chinese correctly, even after used the .setFont method.
See original GitHub issueHello, I’m using jsPDF
1.5.3
version, but I found Chinese doesn’t display correctly when I use .html
method. But it will work when I use the .text
method.
This makes me confused. So, does there any solutions, for trans a Chinese HTML page to PDF
with using the awesome jsPDF
? I will be very grateful for this 😊.
Here are my scripts:( I’m using SourceHanSansCN.ttf
for Chinese, you can find it from here: Source-Han-TrueType )
<script src="https://html2canvas.hertzen.com/dist/html2canvas.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js'></script>
<script src="./js/SourceHanSansCN-Normal-normal.js"></script>
Here is my javascript code:
var doc = new jsPDF({ orientation: 'p', format: 'a4' });
doc.setFont( 'SourceHanSansCN-Normal', 'normal' );
doc.html( '<div>Chinese: 中文</div>' , {
callback: function ( newDoc ) {
newDoc.save( 'chinese-html.pdf' )
}
});
Issue Analytics
- State:
- Created 4 years ago
- Comments:24
Top Results From Across the Web
.html method can't handle Chinese correctly, even after used ...
Hello, I'm using jsPDF 1.5.3 version, but I found Chinese doesn't display correctly when I use .html method. But it will work when...
Read more >How to make sure Chinese text is rendered in webpage?
All Chinese text is rendered in the same font, so it looks like the browser in some way can find the font that...
Read more >Different representation of unicode code points in Japanese ...
Generally, CJK characters in Unicode are “unified”, which means that a single code point is used even though the character has traditionally been...
Read more >TextMesh Pro - Chinese font problems - Unity Forum
I search for a .ttf Chinese font online and import into my project. I then use it to in the Font Asset Creator...
Read more >Chinese Standard Web Fonts: A Guide to CSS Font Family ...
Good Rules for Using Chinese fonts in CSS. Use the Chinese characters, and also spell out the font name. When declaring a Chinese...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ok my last post had the html-markup parsed
if doc.setFont(‘fontname’) works then setting font-family:‘fontname’ should work as well. As mentioned earlier by @FaustYKKN you should use lowercase letters while naming your fonts