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

海城 网站建设网站开发与设计入门

海城 网站建设,网站开发与设计入门,北京建设教育协会官网,做网站封面要怎么做最近同事经常找我帮她打印试卷#xff0c;很奇葩的是#xff0c;她的试卷都是*红书上下载的图片#xff0c;一张张打印不好看#xff0c;而且可能打印不完全#xff0c;大小也不协调#xff0c;所以有了这个脚本。 【需要给小孩打印图片格式的试卷时也比较实用】 -----…最近同事经常找我帮她打印试卷很奇葩的是她的试卷都是*红书上下载的图片一张张打印不好看而且可能打印不完全大小也不协调所以有了这个脚本。 【需要给小孩打印图片格式的试卷时也比较实用】 --------------------------------------------------------------------------------------------------------------------------------- 使用方法 方法一直接将脚本放到图片文件夹内并运行脚本 方法二命令行运行 命令行参数 python convert_images_to_pdf.py [图片文件夹路径] [PDF保存路径]  图片文件夹路径可选默认为python脚本所在目录  PDF保存路径可选默认路径为 图片文件夹路径 文件名为图片文件夹名.PDF。需先指定图片文件夹路径后再指定PDF保存路径 --------------------------------------------------------------------------------------------------------------------------------- 命令行示例 假设脚本名为convert_images_to_pdf.py只指定图片目录 python convert_images_to_pdf.py C:\img_folder 同时指定图片目录和pdf路径  python convert_images_to_pdf.py C:\img_folder  D:\result.pdf 代码 # -*- coding: utf-8 -*-import os import subprocess import sysfrom PIL import Image from reportlab.lib.pagesizes import letter from reportlab.pdfgen import canvasdef pause_exit():subprocess.run(pause, shellTrue)exit()def get_images(img_folder):遍历目录获取目录下所有的图片img_format (.jpg, .png, .bmp)images []for file_name in os.listdir(img_folder):if file_name.lower().endswith(img_format):images.append(os.path.join(img_folder, file_name))return sorted(images)def get_image_size(img_file, page_width, page_height):设置每个图片的大小with Image.open(img_file) as img:img_width, img_height img.sizeif img_height page_height * 0.95 or img_width page_width * 0.95:height_scale (page_height * 0.95) / img_heightwidth_scale (page_width * 0.95) / img_widthscale min(height_scale, width_scale)img_width * scaleimg_height * scalereturn img_width, img_heightdef create_pdf(pdf_file, images, page_width, page_height):创建 pdf 文件并添加图片c canvas.Canvas(pdf_file, pagesizeletter)total_images len(images)for i, img_path in enumerate(images):img_width, img_height get_image_size(img_path, page_width, page_height)x (page_width - img_width) / 2y (page_height - img_height) / 2c.drawImage(img_path, x, y, img_width, img_height)c.showPage()progress_bar(i 1, total_images)c.save()def create_pdf_from_path(img_folder, pdf_fileNone):遍历给定路径将路径下的图片添加进pdf并将pdf保存在指定路径下images get_images(img_folder)if images:if not pdf_file:pdf_name os.path.basename(img_folder) .pdfpdf_file os.path.join(img_folder, pdf_name)page_width, page_height lettercreate_pdf(pdf_file, images, page_width, page_height)return pdf_fileelse:print(f{img_folder} 下没有图片当前支持的图片格式为 jpg、png 和 bmp)pause_exit()def progress_bar(current, total, bar_length60):进度条filled_length int(bar_length * current // total)bar * filled_length - * (bar_length - filled_length)percent current / total * 100sys.stdout.write(f\r处理进度|{bar}| {percent:.2f}%)sys.stdout.flush()if __name__ __main__:subprocess.run(title 目录内图片转PDF, shellTrue)try:(*rest,) sys.argv[1:]if not rest:img_folder os.getcwd() # 使用当前文件夹作为 img_folderpdf_file Noneelse:img_folder, *pdf_file restpdf_file pdf_file[0] if pdf_file else Noneexcept ValueError:print(请提供图片文件夹路径作为参数)pause_exit()if not os.path.exists(img_folder):print(f{img_folder} 路径不存在)pause_exit()elif not os.path.isdir(img_folder):print(f{img_folder} 不是一个文件夹)pause_exit()else:pdf_file create_pdf_from_path(img_folder, pdf_file)if pdf_file:subprocess.run([explorer, pdf_file])else:pause_exit()
http://www.yingshimen.cn/news/87256/

相关文章:

  • 定制开发app价格西安网站优化排名推广
  • 关于网站开发的外文翻译云南网站建设优化技术
  • 青岛做网站公司哪家好设计师网络用语
  • 五里坨网站建设如何写网站建设方案书
  • 邯郸公司网站建设搜狐网站网络营销怎么做
  • 群网站建设合同主流的网站建设的软件有哪些
  • 如何做自助搜券网站国外网站建立
  • 杭州酒店网站建设音乐网站的制作
  • dw内部网站链接怎么做网站页面设计方案怎么写
  • 产品展示网站模板下载天津市房地产官网
  • 深圳网站建设大概多少钱网站界面设计案例分析
  • 海外网站加速器广州做贸易网站
  • 网站开发符合seo结构做logo的比赛网站
  • 纯静态 网站嘉定网站设计开发
  • 电子商务网站建设与维护试卷答案高大上 网站
  • 合肥建设干部学校网站建设网站功能
  • 小纯洁网站开发wordpress文章页设置全屏
  • 私人公司怎么做网站国外在线crm系统suitecrm
  • 做翻译兼职的网站是哪个职业生涯规划大赛心得体会
  • 旅游做攻略的网站有哪些google提交网站
  • 自适应网站什么做购买手表的网站
  • 做网站需要专业微信公众号开发教程视频
  • 沈阳医疗网站建设网站建设策划书的要求
  • 湖南网站优化外包费用婺源网站建制作
  • 公共设施建设投资公司网站雅奇小蘑菇做网站好不好用
  • 罗湖高端网站设计西安cms模板建站
  • 苏州餐饮 网站建设一个主机可以放几个网站
  • 在门户网站上做推广加盟网站制作定制
  • 汉口江岸区城市建设局网站公司关于网站建设的通知
  • 绮思网站建设qswoo山东卓创网络网站建设