import PIL import os import re from fpdf import FPDF from PIL import Image from PIL import ImageDraw from PIL import ImageFont fileAddress = r'C:\Users\1\Desktop\附件下载_行程码截图收集(收集结果)\image' #文件文件夹位置 _fileAddress = r'C:\Users\1\Desktop\附件下载_行程码截图收集(收集结果)\image/' #文件文件夹位置 submitAddress = r'C:\Users\1\Desktop\1/' #文件存放文件夹位置 pdf = FPDF() pdf.set_auto_page_break(0) imgList = os.listdir(fileAddress) print(imgList) font = ImageFont.truetype("/usr/share/fonts/chinese/simsun.ttc", 50) #设置字体样式/大小 for file in imgList: a_list = re.findall(r'[\u4e00-\u9fa5]', file) filename = '' for i in a_list: filename = filename + i file = _fileAddress + file im1 = Image.open(file) draw = ImageDraw.Draw(im1) draw.text((120, 400), filename, (255, 0, 0), font = font) #设置文字位置/内容/颜色/字体 draw = ImageDraw.Draw(im1) im1.save(submitAddress + filename + '.png') imagelist = [i for i in os.listdir(submitAddress)] for image in sorted(imagelist): pdf.add_page() pdf.image(os.path.join(submitAddress, image), w=190, h=250) pdf.output(os.path.join(submitAddress, "1.pdf"), "F") #pdf名字