python使用wkhtmltopdf将html字符串保存pdf,解决出现方框的问题

出现的问题:
解决办法:
html 复制代码
<html>
<head>
    <meta charset="UTF-8"/>
</head>
<style>
* {
    font-family:  Arial,SimSun !important;
}
</style>
</html>
在html字符串前面加上上面代码,意思是设置字体编码和样式
html示例:
html 复制代码
<!DOCTYPE html>
<html>
      <head>
    <meta charset="UTF-8"/>
<style>
* {
    font-family:  Arial,SimSun;
}
</style>
</head>
 <br><br>
<body>
<table style="border:1px #A8a8a8 solid; " border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#f4f4f4"> 
 <tbody> 
    <table border="0" cellpadding="0" cellspacing="0" width="100%"> 
     <tbody> 
      <tr> 
       <td class="buleB16" height="80" valign="middle" align="center">中国人民银行青岛市分行行政处罚信息公示表(2023年12月22日)</td> 
      </tr> 
     </tbody> 
  <br><br></body></html>
python代码示例:
python 复制代码
import pdfkit
html_str = """上述html代码"""
# 设置wkhtmltopdf路径
config = pdfkit.configuration(wkhtmltopdf='/usr/local/bin/wkhtmltopdf')
options = {
    'encoding': "utf-8",
}
pdfkit.from_string(html_str, 'output.pdf', configuration=config, options=options)
结果如下:
安装wkhtmltopd包参考:https://blog.csdn.net/qq_25647857/article/details/138248214
转pdf报错参考:http://kaito-kidd.com/2015/03/12/python-html2pdf/
相关推荐
你好1234567890121 天前
PDF编辑软件 pdfelement绿色版
pdf
小邓睡不饱耶1 天前
东方财富网股票数据爬取实战:从接口分析到数据存储
开发语言·爬虫·python·网络爬虫
2401_891655811 天前
GitHub镜像站搭建全攻略技术文章大纲
python·github
cm6543201 天前
使用XGBoost赢得Kaggle比赛
jvm·数据库·python
yzx9910131 天前
WorkBuddy 使用指南:解锁几大核心功能,提升工作效率
人工智能·python
蛐蛐蛐1 天前
在昇腾310P推理服务器上安装CANN和PyTorch
人工智能·pytorch·python·npu
qq_416018721 天前
游戏与图形界面(GUI)
jvm·数据库·python
轮到我狗叫了1 天前
ResNet-阅读
python·深度学习·机器学习
Sunshine for you1 天前
使用Python分析你的Spotify听歌数据
jvm·数据库·python
2401_884563241 天前
用Python读取和处理NASA公开API数据
jvm·数据库·python