1 import pdfkit
 2 import zipfile
 3 import os
 4 import sys
 5 import re
 6 
 7 # 出现乱码时解码
 8 def recode(raw: str) -> str:
 9     try:
10         return raw.encode('cp437').decode('gbk')
11     except:
12         return raw.encode('utf-8').decode('utf-8')
13 
14 def saveFile(htmlobj,pdfobj):
15     options = {
16         'page-size':'Letter','margin-top':'0.75in','margin-right':'0.75in',
17         'margin-bottom':'0.75in','margin-left':'0.75in','encoding':"UTF-8",
18         'custom-header': [('Accept-Encoding','gzip')],
19         'cookie': [('cookie-name1','cookie-value1'),('cookie-name2','cookie-value2'),],
20         "enable-local-file-access": None,
21         "header-left" : "收集人:冯际成 QQ:604756218 ",
22         "header-right" : "[date] 机密文件请勿外传",
23         "header-spacing" : 3,
24         "footer-spacing" : 3,
25         "footer-center" : "- 第 [page] 页-",
26         "header-line":None,
27         "page-size": 'A4',
28         "outline-depth":10,
29     }
30     config = pdfkit.configuration(wkhtmltopdf=r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe') 
31     pdfDir = os.path.dirname(pdfobj)
32     if not os.path.exists(pdfDir):
33         os.makedirs(pdfDir)
34     pdfkit.from_file(htmlobj,pdfobj,options=options,configuration=config,verbose=True)
35 
36 def ziw2pdf(root,file):
37 
38     current_directory = os.path.dirname(os.path.abspath(__file__)) #获得当前路径
39     pathZip = os.path.join(root,file)
40     #开始合合成路径
41     split_list=pathZip.replace(".ziw","").split("\\")[7:]
42     head=current_directory+r"\tmp"
43     if not os.path.exists(head):
44         os.makedirs(head)
45     for path in split_list:
46         head = os.path.join(head, re.sub(r"\s+", "", path))
47     ziwobj    = head
48     
49     split_list=pathZip.replace(".ziw",".pdf").split("\\")[7:]
50     head=current_directory+r"\pdf"
51     if not os.path.exists(head):
52         os.makedirs(head)
53     for path in split_list:
54         head = os.path.join(head, re.sub(r"\s+", "", path))
55     pdfobj = head
56     zipFile = zipfile.ZipFile(pathZip)          # 压缩包路径
57     zipFileList = zipFile.namelist()            # 获取压缩包里所有文件
58     for f in zipFileList:
59         zipFile.extract(f, ziwobj)                 # 循环解压文件到指定目录
60         name1 = os.path.join(ziwobj, f)            # 乱码文件名
61         name2 = os.path.join(ziwobj, recode(f))    # 解码后文件名
62         os.rename(name1, name2)                 # 文件重命名
63     zipFile.close()                             # 关闭文件释放内存
64     htmlobj =os.path.join(ziwobj ,"index.html")
65     saveFile(htmlobj,pdfobj)
66 
67 if __name__ == '__main__':
68     ziw_list = []
69     file_dir = "C:\\Users\\fengjicheng\\Documents\\My Knowledge\\Data\\caoxiancc@live.cn\\SAP"
70     #file_dir = "C:\\Users\\fengjicheng\\Documents\\My Knowledge\\Data\\caoxiancc@live.cn\\AI"
71     for root,dirs,files in os.walk(file_dir):
72         for file in files:
73             if file.endswith(".ziw"):
74                 ziw2pdf(root,file)
75         

 

posted @ 2024-05-10 16:12 冯际成 阅读(41) 评论(0) 推荐(0) 编辑
摘要: 1、(401) 未经授权; 解决方法:将用户名密码加密后,添加到HTTP HEADER中。 String auth = "ZRFC" + ":" + "Init1234"; String encodeAuth = "Basic " + new String(Base64.getEncoder().e 阅读全文
posted @ 2022-05-11 13:54 冯际成 阅读(974) 评论(0) 推荐(0) 编辑
摘要: 第二种设置永久cookie 若要免登录可以调用 免登录 Process.Start("iexplore.exe", LinkAddress.CookiesFind); 阅读全文
posted @ 2017-03-18 10:07 冯际成 阅读(890) 评论(0) 推荐(0) 编辑
摘要: declare m_cursor cursor scroll forselect top 10 DeptID,DeptParentID from Department open m_cursordeclare @DeptID varchar(100), @DeptParentID varchar(1 阅读全文
posted @ 2017-03-09 09:09 冯际成 阅读(440) 评论(0) 推荐(0) 编辑
摘要: 测试代码 扩展方法实现 阅读全文
posted @ 2016-12-15 12:24 冯际成 阅读(1380) 评论(0) 推荐(0) 编辑
摘要: http://ip/dir 点击SAP NetWeaver Administrator 找到这个服务:com.sap.aii.adapter.rfc.svc修改以上2个值syncMessageDeliveryTimeoutMsec = 600000,默认值为300000 xiadapter.inbo 阅读全文
posted @ 2016-12-12 16:54 冯际成 阅读(932) 评论(0) 推荐(0) 编辑
摘要: http://id.ourgame.com/mobilepassport!getMobileYzm.do?passport=http://id.ourgame.com/mobilepassport!getMobileYzm.do?passport=http://id.ourgame.com/mobi 阅读全文
posted @ 2016-08-26 09:24 冯际成 阅读(4392) 评论(1) 推荐(1) 编辑
摘要: 今天一朋友问我他在dw中做的网页为什么在浏览器中显示乱码,根据工作经验一般处理方式如下: 1.查看文件编码,用记事本打开另存为编码格式为utf-8 2.在html代码head中添加 <meta charset="UTF-8" /><meta http-equiv="content-type" con 阅读全文
posted @ 2016-02-26 14:21 冯际成 阅读(627) 评论(0) 推荐(0) 编辑
摘要: MATLAB是美国MathWorks公司出品的商业数学软件,用于算法开发、数据可视化、数据分析以及数值计算的高级技术计算语言和交互式环境,主要包括MATLAB和Simulink两大部分 阅读全文
posted @ 2015-07-04 07:26 冯际成 阅读(289) 评论(0) 推荐(0) 编辑
摘要: 首先使用chrome浏览器,找到相关页面 F12打开命令窗口输入:var el=$('.post'); $("*").not(el.find('*')).hide(); el.parents().andSelf().css({width:480,padding:0,margin:0,bord... 阅读全文
posted @ 2015-06-21 10:39 冯际成 阅读(413) 评论(0) 推荐(0) 编辑

返回顶部

点击右上角即可分享
微信分享提示