当前位置: 首页 > 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.yidumall.com/news/17043.html

相关文章:

  • 黑龙江做网站的公司有哪些武汉seo关键词排名优化
  • 网站网站建设培训百度app 浏览器
  • 德州做网站哪家好许昌网络推广公司
  • 网站购买外链百度首页纯净版怎么设置
  • 电子商务网站安全性能主要包括安徽百度推广怎么做
  • 越秀区建设水务局网站河南靠谱seo电话
  • 做视频网站想用家庭网络广州信息流推广公司
  • 做网站有哪些要求代运营公司
  • 龙岩做网站开发哪家厉害免费b站软件推广网站2023
  • 做淘宝客网站能有效果吗网络运营推广具体做什么工作
  • 做网站 长百度账户托管运营
  • 模板做网站影响seo拓客平台有哪些
  • 怎么建php网站2024年最新一轮阳性症状
  • 网站名称填写什么汽车网络营销推广方案
  • 大埔网站建设百度一下你就知道了 官网
  • 英文网站制作 官网广东seo点击排名软件哪里好
  • 网站备案主体修改如何创建网址
  • 天津企业网站设计哪家好软文网站推广法
  • 自己做盗版影视网站百度allin 人工智能
  • 芜湖做的好的招聘网站邵阳网站seo
  • jsp网站开发需要哪些技术女装关键词排名
  • 织梦网站建设交流群seo查询网站是什么
  • 怎样做买东西的网站网络建站流程
  • 网站动图是怎么做的泰安百度推广代理
  • 网络营销seo是什么意思广州seo网络培训课程
  • wordpress后端页面开发西安seo公司哪家好
  • 网站注入木马网站流量来源
  • 郴州哪里做网站网站建设报价方案
  • 怎样做企业的网站首页个人免费建站系统
  • 汉口做网站公司沈阳百度推广排名优化