当前位置: 首页 > news >正文

中国建设工程监理网站企业管理系统

中国建设工程监理网站,企业管理系统,装修设计网页版,深圳航空公司官网首页目录 说明 说明 将审计文件的所需要贴的编码直接作为水印贴在页面四个角落,节省辨别时间 我曾经写过一个给pdf页面四个角落加上文件名水印的python脚本,现在需要加一个图形界面进一步加强其实用性。首先通过路径浏览指定文件路径,先检测该路…

目录

  • 说明

说明

将审计文件的所需要贴的编码直接作为水印贴在页面四个角落,节省辨别时间

我曾经写过一个给pdf页面四个角落加上文件名水印的python脚本,现在需要加一个图形界面进一步加强其实用性。首先通过路径浏览指定文件路径,先检测该路径是不是已经存在的文件夹,如果不是,再判断是不是txt如果也不是,提示需要txt路径列表或者提供根路径,如果是文件路径,提示该路径下子文件夹的文件也会被做同样处理,做好文件备份隔离防护工作。如果是txt则按行读取,并且提示其中的路径有多少是有效的。
提供一个勾选框,决定是否要将路径中的各种图片格式转化为同名pdf。然后提供两个文本框指定图片转化线程数和水印添加线程数
然后再提供2个参数文本框,第一个文本框内数字为g(成为打印页边距)分别用来调节水印离两个方向页面边界的距离(%为单位的相对距离,实际距离取决于读取到的页面尺寸,长和宽的乘积取平方根再乘以g%),第2文本框用来指定相对字体大小f%%为单位,计算一个参考高度等于页面长宽乘积取平方根再乘以5%再乘以f%,然后计算选定字体显示高度与参考高度相等的字号),用标签提示最好在实验文件夹中测试好需要的相对字体大小
font_family根据系统可选提供下拉菜单,改为用户指定,前两个默认为Times New Roman和楷体
水印内容和示例代码中一样根据文件名、当前页数和总页数来确定
由于插入点是文本左上角,而四个角文本的方向不同,为了让文本更好贴合打印边界又不超出打印边界,该代码根据页面尺寸、打印边距和指定字体字号情况下文本显示所占矩形空间来确定插入点的具体位置
点击执行按钮,遍历一次路径如果有图片需要转化又未被转化,先转化图片为pdf(多线程执行),同时记录所有有待处理的pdf文件数(包括图片转化出来的)
再遍历一次路径,将每个pdf的按照设定参数添加水印(用多线程执行),并且替换原文件。按已处理文件数/总文件数显示进度条,完成后弹窗提示import os
import re
import fitz
from PIL import ImageFont
def text_position(w,h,x,y,width,height,gap):if y<=height/2:if x<=width/2:x=max(x,gap)+hy=gap+wreturn [x,y]else:x=width-gap-wy=max(gap,y)+hreturn [x,y]else:if x<=width/2:x=gap+wy=height-max(gap,height-y)-hreturn [x,y]else:x=width-max(gap,width-x)-hy=height-gap-wreturn [x,y]
def text_size(line,font_family,font_size):font = ImageFont.truetype(font_family, font_size, 0)width, height = font.getsize(line)#DeprecationWarning: getsize is deprecated and will be removed in Pillow 10 (2023-07-01). Use getbbox or getlength instead.return [width,height]
def text_insert_once(x1,y1,x2,y2,x3,y3,x4,y4,text,fname,fsize,page):p = fitz.Point(x2,y2)#右上角page.insert_text(p,  # bottom-left of 1st chartext,  # the text (honors '\n')fontname = fname,  # the default fontfontsize = fsize,  # the default font sizerotate = 0,  # also available: 90, 180, 270)p = fitz.Point(x3,y3)#左下角,从右往左page.insert_text(p,  # bottom-left of 1st chartext,  # the text (honors '\n')fontname = fname,  # the default fontfontsize = fsize,  # the default font sizerotate = 180,  # also available: 90, 180, 270)p = fitz.Point(x1,y1)#左上角,从下到上page.insert_text(p,  # bottom-left of 1st chartext,  # the text (honors '\n')fontname = fname,  # the default fontfontsize = fsize,  # the default font sizerotate = 90,  # also available: 90, 180, 270)p = fitz.Point(x4,y4)#右下角,从上到下page.insert_text(p,  # bottom-left of 1st chartext,  # the text (honors '\n')fontname = fname,  # the default fontfontsize = fsize,  # the default font sizerotate = 270,  # also available: 90, 180, 270)
def pnum_print(pdf,file,flag=1):pagenum=pdf.page_count    i=0for page in pdf:content=[]#假定短边留白5%,长边留白3.3%i=i+1width=page.rect.widthheight=page.rect.height[wx,hx]=[0.06,0.04]if width>= height:#w=round(width*wx,0)h=round(height*wx,0)w=helse:w=round(width*wx,0)h=wfs=int(w/4)text=str(i)+'/'+str(pagenum)content.append(os.path.splitext(file)[0])content.append(text)       ff=page.insert_font(fontname="HT",fontfile=r"C:\Windows\Fonts\simhei.ttf", fontbuffer=None , set_simple=False )[x1,y1,x2,y2,x3,y3,x4,y4]=[0,0,width,0,0,height,width,height]for c in content:[w,h]=text_size(c,"simhei.ttf",fs)[x1,y1]=text_position(w,h,x1,y1,width,height,0*w)[x2,y2]=text_position(w,h,x2,y2,width,height,0*w)[x3,y3]=text_position(w,h,x3,y3,width,height,0*w)[x4,y4]=text_position(w,h,x4,y4,width,height,0*w)text_insert_once(x1,y1,x2,y2,x3,y3,x4,y4,c,"HT",fs,page)if pdf.can_save_incrementally():if flag==1:pdf.saveIncr()else:pdf.save(os.path.splitext(file)[0]+'(共'+str(pagenum)+'页)'+'.pdf')print(file+"***********processed")pdf.close()if flag!=1:os.remove(file)#os.remove(file)else:print("Can't save Incermentally")#增量保存的文件损坏和签名问题
def path_read(flag,source):path=[]if flag=="父节点":for p in os.listdir(source):if os.path.isdir(source+'\\'+p):path.append(source+'\\'+p)return pathif flag=="列表文件":with open(source,'r') as f :for p in f.readlines():pp=p.replace('\n','')if os.path.isdir(pp):path.append(pp)return pathreturn None
def pic2pdf(file):img_file=['.png','.jpg',',jepg']title=os.path.splitext(file)[0]if os.path.splitext(file)[1] in img_file:imgdoc = fitz.open(file) # 打开图片pdfbytes = imgdoc.convert_to_pdf() # 使用图片创建单页的 PDFimgpdf = fitz.open("pdf", pdfbytes)doc=fitz.open()doc.insert_pdf(imgpdf) # 将当前页插入文档if os.path.exists(title+".pdf"):os.remove(title+".pdf")doc.save(title+".pdf") # 保存pdf文件doc.close()imgdoc.close()os.remove(file)
img_file=['.png','.jpg',',jepg']
img_convert=True #False  #True
#path=path_read(flag="列表文件",source=r'E:\huang\Desktop\路径列表.txt')
path=path_read(flag="父节点",source=r'E:\huang\Desktop\浙江通力传动科技股份有限公司\乐总底稿整理\新建文件夹\内控')
print(path)
for p in path:os.chdir(p)print(p)if img_convert:for file in os.listdir():if os.path.splitext(file)[1] in img_file:pic2pdf(file)for file in os.listdir():if os.path.splitext(file)[1]=='.pdf':print(file)if re.search(r'\(共\d+?页\)',file)==None:pdf_book=fitz.open(file)pnum_print(pdf_book,file,0)
http://www.hkea.cn/news/805165/

相关文章:

  • 雄安网站建设制作网站关键词如何快速上首页
  • 佛山从事网站建设百度小程序入口官网
  • 自建网站平台可以实现哪些功能网络营销这个专业怎么样
  • 佛山新网站制作公司网页制作成品模板网站
  • 校园网站建设的意见企业管理培训课程网课
  • 郑大远程教育动态网站建设seo优化关键词排名
  • 做logo什么网站昆明百度关键词优化
  • 怎样做省钱购物网站sem推广代运营
  • 英文网站开发公司万网阿里云域名查询
  • 做调查问卷网挣钱的网站新闻 今天
  • 网站建设工作小组在线建站平台免费建网站
  • 可以发广告的网站湖南seo推广系统
  • 大丰网站建设哪家好成都seo
  • 学校网站建设项目的wbsseo交流qq群
  • 筑梦网站建设西安百度竞价开户
  • 个体营业执照可以做网站搞推广吗推广网站制作
  • 公共交通公司网站建设方案移动慧生活app下载
  • 国内开源代码网站搜了网推广效果怎么样
  • html5 metro风格网站模板今日新闻事件
  • 网站不在首页显示出来做网络推广
  • 上海网站seo公司网页推广平台
  • 网站服务器租用价格表百度怎么发布自己的广告
  • 经纪人做网站技巧搜索引擎入口yandex
  • 教育网站制作哪家服务好全球外贸采购网
  • 响应式网络网站源码百度关键词查询网站
  • 南京网站制作设计公司网络运营团队
  • 阿里巴巴上怎样做自己的网站seo网站优化网站编辑招聘
  • 网站做付费推广都需要问什么网络热词2022
  • 给男票做网站表白的软件产品市场推广计划书
  • 西安网站制作定制怎么制作自己的个人网站