wkhtmltopdf 黑體在html轉換pdf時,黑體亂碼,分析可能wkhtmltopdf對黑體字體不太兼容;
1.html內容如下
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<body>
<div class="content"><p style="font-family: 宋體; font-size: 22pt;">我是宋體</p> <p style="font-family: 黑體; font-size: 26pt;">我是黑體</p>
</div>
</body>
</html>
?2.轉換為pdf后黑體字體亂碼
?
3.解決辦法把html內的黑體替換為宋體再轉換為pdf:
html_content = html_content.replace("黑體", "宋體")
參考資料
windows 下 wkhtmltopdf 轉換 HTML 時 字符編碼正確、字體已安裝仍然中文亂碼的解決方法_wkhtmltopdf 在window上亂碼-CSDN博客