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/
相关推荐
0思必得028 分钟前
[Web自动化] Selenium处理滚动条
前端·爬虫·python·selenium·自动化
沈浩(种子思维作者)42 分钟前
系统要活起来就必须开放包容去中心化
人工智能·python·flask·量子计算
2301_790300961 小时前
Python数据库操作:SQLAlchemy ORM指南
jvm·数据库·python
m0_736919101 小时前
用Pandas处理时间序列数据(Time Series)
jvm·数据库·python
getapi1 小时前
实时音视频传输与屏幕共享(投屏)
python
觉醒大王1 小时前
哪些文章会被我拒稿?
论文阅读·笔记·深度学习·考研·自然语言处理·html·学习方法
java干货2 小时前
为什么 “File 10“ 排在 “File 2“ 前面?解决文件名排序的终极算法:自然排序
开发语言·python·算法
机器懒得学习2 小时前
智能股票分析系统
python·深度学习·金融
毕设源码-郭学长2 小时前
【开题答辩全过程】以 基于python的二手房数据分析与可视化为例,包含答辩的问题和答案
开发语言·python·数据分析
SR_shuiyunjian2 小时前
Python第三次作业
python