微慑信息网

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)

 

赞(0) 打赏
转载请附本站链接,未经允许不得转载,,谢谢:微慑信息网-VulSee.com » HTML转换为PDF工具: wkhtmltopdf

评论 抢沙发

微慑信息网 专注工匠精神

微慑信息网-VulSee.com-关注前沿安全态势,聚合网络安全漏洞信息,分享安全文档案例

访问我们联系我们

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册