微慑信息网

HTML转换为PDF工具: wkhtmltopdf

官网

https://wkhtmltopdf.org/

各种语言版本

C#:

https://github.com/codaxy/wkhtmltopdf

https://github.com/tlbdk/WkHtmlToPdfRunner/tree/master/WkHtmlToPdfRunner

QtWebKit:

https://github.com/wkhtmltopdf/wkhtmltopdf

Python:

https://github.com/JazzCore/python-pdfkit

JAVA:

https://github.com/jhonnymertz/java-wkhtmltopdf-wrapper

(参考:https://blog.csdn.net/x6582026/article/details/53835835)


windows下python脚本示例(来自t00ls匿名):

def validateTitle(title):
    """ 将 title 名字 规则化
    :param title: title name 字符串
    :return: 文件命名支持的字符串
    """
    rstr = r"[\=\(\)\,\/\\\:\*\?\"\<\>\|\' ']"  # '= ( ) , / \ : * ? " < > |  '   还有空格
    new_title = re.sub(rstr, "_", title)  # 替换为下划线
    return new_title
# options = {
#     'animation': 'false', #导出PDF一定要设置,否则显示不全
#
# }
options = {
        'page-size': 'A4',
        'margin-top': '0mm',
        'margin-right': '0mm',
        'margin-bottom': '0mm',
        'margin-left': '0mm',
        # 'orientation':'Landscape',#横向
        'encoding': "UTF-8",
        'no-outline': None,
    'animation':'false',
          # 'footer-right':'[page]' 设置页码
    }

#session = requests.session()
confg = pdfkit.configuration(wkhtmltopdf=r'wkhtmltopdf\bin\wkhtmltopdf.exe')
# 这里指定一下wkhtmltopdf的路径

readFile = open('url.txt','r',encoding='utf8')
urlList = []
for lines in readFile.readlines():
    urlList.append(lines.strip())
for u in urlList:
    # try:
    print(u)
    name = (get_con(u)[1]+'_'+get_con(u)[0])

    print('正在将{}网页转为PDF'.format(name))
    time.sleep(2)
    strCMD = r'wkhtmltopdf\\bin\\wkhtmltopdf.exe --disable-smart-shrinking "%s" %s.pdf' % (u,validateTitle(name))
    print(strCMD)
    os.popen(strCMD)

 

本文标题:HTML转换为PDF工具: wkhtmltopdf
本文链接:
(转载请附上本文链接)
https://vulsee.com/archives/vulsee_2020/0731_11674.html
转载请附本站链接,未经允许不得转载,,谢谢:微慑信息网-VulSee.com » HTML转换为PDF工具: wkhtmltopdf
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

微慑信息网 专注工匠精神

访问我们联系我们