老婆出轨 发表于 2024-9-6 04:30:36

【教学类-52-08】20240905动物数独(6宫格)一页2张任务卡,一页一个动物贴

https://i-blog.csdnimg.cn/direct/10363761a26842ef8f40e278f2998d0a.png
配景需求:

前文提到6宫格数独的图片6*6=36图,假如将6张任务卡放在一个A4上,看上去6种动物很小,所以我换了一个word模板,变成了2张任务卡放在一个A4上。

【教学类-52-07】20240903动物数独(6宫格)一页2张任务卡,无答案-CSDN博客文章浏览阅读846次,点赞25次,收藏6次。【教学类-52-07】20240903动物数独(6宫格)一页2张任务卡,无答案https://g.csdnimg.cn/static/logo/favicon32.icohttps://blog.csdn.net/reasonsummer/article/details/141903770https://i-blog.csdnimg.cn/direct/ef90cb6c99b54494abab1da8077e9563.png
但是我没有放大贴图卡片,照旧每张10*10CM。

https://i-blog.csdnimg.cn/direct/9fabaf0cc6f34756b9f6c4ff1ec6739d.png
我想,假如将动物数独用于公开课,就必要比较大的学具,也就是1关任务卡贴1张A4,约莫是21*21CM一张,而动物贴图卡片也必要1张A4,约莫是21*21CM一张。

也就是自制KT 版的巨细是 6宫格图(20*6=120*120CM)

https://i-blog.csdnimg.cn/direct/f401ed69f20a4238b7fd026f5dfa35b8.png
我们幼儿园用的KT版是1.2*2.4M,,恰好切出一个6宫格图案,可以用来撑满个别化的墙面。

https://i-blog.csdnimg.cn/direct/f0a9482680984191b03d84018ebc1aea.png

话不多说,直接进上代码

# 测试11*11格,2*2一共4套3*3 宫格
'''
动物6宫格 任务卡一页一张(36张),答案卡一页一张(36张),贴图一页一张(36张)
108张很浪费彩墨,但是如果是公开课,还是值得的。
生成时间90分钟

动物数独 6宫格,

1、大卡片9.84CM一行,A4一页4张
2、参考图(空1格到空34格子,生成PDF,转为png
3、将png关卡图片做成8.82*9.7的小图卡(A4一页4张)
4、图片卡和关卡图合并在一个PDF
5、有答案
关卡图1张一页,最大化19.6

时间:2024年4月12日
作者:「Vaeeeeeee」,AI对话大师,阿夏
时间:2024年4月12日 13:35


'''

print('-----0、生成大图片卡-------')

   
# -*- coding:utf-8 -*-

'''
制作动物/脸谱数独的黏贴关卡 A4一页4张图片 9.85CM
作者:AI对话大师,阿夏
时间:2024年6月3日
# '''

# print('----1、读取行列-------')
import os,time
from docx import Document
from docx.shared import Cm
from docx2pdf import convert
from PyPDF2 import PdfMerger
import shutil

path=r'C:\Users\jg2yXRZ\OneDrive\桌面\动物数独6宫格'

# # 新建一个”装N份word和PDF“的临时文件夹
imagePath=path+r'\\零时Word'
os.makedirs(imagePath,exist_ok=True)# 若图片文件夹不存在就创建
imagePath4=path+r'\\汇总'
os.makedirs(imagePath4,exist_ok=True)

doc = Document(path +r'\动物数独(6宫格横板)1图关卡.docx')

# 获取文档中的所有表格
tables = doc.tables

# 选择你需要读取的表格(在这种情况下是第1张表格)
target_table = tables

# 获取所选表格的行数和列数
num_rows = len(target_table.rows)
num_columns = len(target_table.columns)

print("行数:", num_rows)
# 3
print("列数:", num_columns)
# # 2

print('----2、读取图片-------')

import os

# 指定文件夹路径
folder_path = path + r'\02动物图片'

# 读取文件夹中所有文件的名称并加上路径
pic_list = *6

# 打印文件名称和路径
print(pic_list)
print(len(pic_list))



# print('----3、插入六套大图片-------')



for f in range(len(pic_list)):
    # 打开.docx文件
    doc = Document(path + r'\动物数独(6宫格横板)1图关卡.docx')
    # 获取文档中的所有表格
    table = doc.tables

    # 遍历表格的所有行和单元格
    i = 0
    for row in table.rows:
      for cell in row.cells:
            # 在单元格中插入图片
            cell_paragraph = cell.paragraphs
            run = cell_paragraph.add_run()
            run.add_picture(pic_list, width=Cm(19.6), height=Cm(19.6))
            cell_paragraph.alignment = 1# 设置单元格中的文本居中
            i += 1# 移动到下一个图片路径

    # 保存修改后的.docx文件
    doc.save(imagePath + fr'\{f:02d}页.docx')
    # docx 文件另存为PDF文件
    inputFile = imagePath + fr'\{f:02d}页.docx'# 要转换的文件:已存在
    outputFile = imagePath + fr'\{f:02d}页.pdf'# 要生成的文件:不存在
    convert(inputFile, outputFile)
    time.sleep(5)

# 合并PDF文件
pdf_lst =
pdf_lst =
pdf_lst.sort()
file_merger = PdfMerger()
for pdf in pdf_lst:
    file_merger.append(pdf)

file_merger.write(imagePath4 + r"\02操作卡.pdf")
file_merger.close()

# 第5步
shutil.rmtree(imagePath) #递归删除文件夹,即:删除非空文件夹




print('----3、制作空白题卡-------')

import random
from win32com.client import constants, gencache
from win32com.client.gencache import EnsureDispatch
from docx import Document
from docx.shared import Pt, RGBColor
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.oxml.ns import qn
from docx.enum.text import WD_ALIGN_PARAGRAPH


import docxtpl
import pandas as pd
from docx2pdf import convert

from docx.oxml.ns import nsdecls
from docx.oxml import parse_xml
import copy




num=1
# int(input('生成几份\n'))
# 制作"单元格"# 几宫格
hsall=6
# int(input('请输入4或9\n'))
hs=hsall

# kk=int(input('空格数量,输入5,就是50%,就是空一半)\n'))

print('------1、如果正好想生成1空、2空、3空、4空的数字,需要测算百分比的具体数字------')

n=hsall
g=n*n

a=[]
for i in range(1,101):
    # 因为有100,所以三位数
   
    print(f'{n}宫格,难度{i:03d},抽取{i:03d}%:实际有{int(g*i/100):03d}空,已有图案{g-int(g*i/100):03d}')
    a.append(f'{n}宫格,难度{i:03d},抽取{i:03d}%:实际有{int(g*i/100):03d}空,已有图案{g-int(g*i/100):03d}')
print(a)
print(len(a))
# # 用冒号分割,如果0空,加入,

# 创建一个空列表用于存储匹配的元素
b = []

# 遍历原始列表
for element in a:
    # 如果找到匹配的元素,以":"为分隔符将字符串分割成两部分
    parts = element.split(":")
    # print(parts)
    # # 提取第一部分中包含的数字信息
    info = parts
    b.append(info)
# 对列表b进行排序,并去除重复项
b = list(set(b))
b.sort(reverse=False)
print(b)

f=[]
for d in range(len(b)):
    for c in a:
      # print(c)
      # 读取一个就中断
      if c[-15:]==b:
            f.append(c)
            break
f.pop(0)
# 删除['6宫格,难度01,抽取1%:实际有00空,已有图案14',
# f.pop(-1)
# # 删除'6宫格,难度100,抽取100%:实际有14空,已有图案00'
print(f)
# ['6宫格,难度007,抽取007%:实际有001空,已有图案015', '6宫格,难度013,抽取013%:实际有002空,已有图案014', '6宫格,难度019,抽取019%:实际有003空,已有图案013', '6宫格,难度025,抽取025%:实际有004空
# ,已有图案012', '6宫格,难度032,抽取032%:实际有005空,已有图案011', '6宫格,难度038,抽取038%:实际有004空,已有图案010', '6宫格,难度044,抽取044%:实际有007空,已有图案009', '6宫格,难度050,抽取050%:实际有008空,已有图案008', '6宫格,难度057,抽取057%:实际有009空,已有图案007', '6宫格,难度043,抽取043%:实际有010空,已有图案004', '6宫格,难度049,抽取049%:实际有011空,已有图案005', '6宫格,
# 难度075,抽取075%:实际有012空,已有图案004', '6宫格,难度082,抽取082%:实际有013空,已有图案003', '6宫格,难度088,抽取088%:实际有014空,已有图案002', '6宫格,难度094,抽取094%:实际有015空,已有图案
# 001']
print(len(f))
# 15
# 难度有15关

# 提取百分数
g=[]
w=[]
for p in f:
    g.append(int(p))    # 提取第4-7个数字=百分比数字
    w.append(int(p))    # 提取空格数量
print(g)
#
print(len(g))
# 15关
print(w)

print(len(w))
# 34


print('------2、制作6宫格随机数字------')

# 制作"单元格"# 几宫格
for kk in range(len(g)):
# hs=int(input('请输入宫格数量(3,5.6,7,8,)\n'))

   
    # 因为有3-9的不同word模板,所以有不同的套数和字体大小
    ll=['6'] # 如果输入345
    mm=['11']# 3对应的套数是4*3套
    nn=['36']# 3对应的写入单元格的数字大小36磅
    for r in range(len(ll)):
      if hs ==int(ll):
            # 底边几套.底边看有2份
            db=int(mm)
            # int(input('底边几套? 3\n'))
            # 侧边几套 侧边看也是2份
            print(db )      
            cb=int(mm)
            # int(input('侧边几套? 2\n'))
            print(cb)
            size=int(nn)
            print(size)      # 写入单元格数字的大小(撑满格子)

    path=r'C:\Users\jg2yXRZ\OneDrive\桌面\动物数独6宫格'
    # 新建一个”装N份word和PDF“的临时文件夹
    imagePath=path+r'\\零时Word'
    os.makedirs(imagePath,exist_ok=True)

    # imagePath2=path+r'\\零时jpg1'
    # os.makedirs(imagePath2,exist_ok=True)

    # imagePath3=path+r'\\零时jpg2'
    # os.makedirs(imagePath3,exist_ok=True)

    imagePath4=path+r'\\汇总'
    os.makedirs(imagePath4,exist_ok=True)

    imagePatha=path+r'\答案'
    imagePathq=path+r'\题目'
    os.makedirs(imagePatha,exist_ok=True)
    os.makedirs(imagePathq,exist_ok=True)

    # 计算不同模板中的单元格坐标,放在bg里
    # 棋盘格子数量,
    # 如果长方形:底边3*侧边2,3*2=4套 ,就是10*10宫格,底边格子数量就是10*3=30,侧边格子数量就是10*2=20,
    # if db==cb:

    db_size = hs*db
    cb_size=hs*cb
    print('{}宫格排列底{}侧{}共{}套,底边格子数{}'.format(hs,db,cb,db*cb,db_size ))
    print('{}宫格排列底{}侧{}共{}套,侧边格子数{}'.format(hs,db,cb,db*cb,cb_size ))

    # 确定每个宫格的左上角坐标 00 04 4044 中间没有分栏的空格了,所以hs不用+1
    bgszm=[]
    for a in range(0,cb_size,hs):    # 0-11每隔4,写一个坐标侧边y
      for b in range(0,db_size,hs):# 0-11每隔4,写一个坐标侧边x
            bgszm.append('{}{}'.format('%02d'%a,'%02d'%b))
    print(bgszm)
    # 10宫格排列底3侧2共4套,底边格子数30
    # 10宫格排列底3侧2共4套,侧边格子数20
    # 10宫格排列底3侧2共4套,侧边格子数20
    # ['0000', '0010', '0020', '1000', '1010', '1020']
      

    # 转为元祖
    start_coordinates = [(int(s), int(s)) for s in bgszm]
    cell_coordinates = []

    # 推算每个起始格子后面的单元格数字
    for start_coord in start_coordinates:
      i, j = start_coord
      subgrid_coordinates = []
      for x in range(hs):
            for y in range(hs):
                subgrid_coordinates.append((i + x, j + y))
      cell_coordinates.append(subgrid_coordinates)

    # 打印结果(元祖样式)
    bg=[]
    for coordinates in cell_coordinates:
      # print(coordinates)   # [(4, 8), (4, 9), (4, 10), (5, 8), (5, 9), (5, 10), (4, 8), (4, 9), (4, 10)]
      for c incoordinates:
            print(c)      # 元组 (1, 2) 样式
            s = ''.join(str(num).zfill(2) for num in c)   # zfill将元组 (1, 2) 转换为字符串 '0102' 特别是(5,10)这种必须转成2个数字0510
            print(str(s))      #'12'
            bg.append(s)#'0102'
    print(bg)

    P=[]
    for z in range(num):
      P.clear()
      #    制作4份数据
      for j in range(db*cb):    #3宫格,4*3=12套
      
      # ————————————————生成随机宫格,按比例空缺格子
      # 版权声明:本文为CSDN博主「Vaeeeeeee」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
      # 原文链接:https://blog.csdn.net/m0_46366547/article/details/131334720
            def generate_sudoku_board():
                # 函数体生成数独库表盘
                # 创建一个9x9的二维列表,表示数独棋盘
                board = [ * hs for _ in range(hs)]

                # 递归函数,用于填充数独棋盘的每个单元格
                def filling_board(row, col):
                  # 检查是否填充完成整个数独棋盘
                  if row == hs:
                        return True
                  
                  # 计算下一个单元格的行和列索引
                  next_row = row if col < hs-1 else row + 1
                  next_col = (col + 1) % hs

                  # 获取当前单元格在小九宫格中的索引
                  box_row = row
                  box_col = col

                  # 随机生成1到9的数字
                  numbers = random.sample(range(1, hs+1), hs)

                  for num in numbers:
                        # 检查行、列、小九宫格是否已经存在相同的数字
                        if num not in board and all(board != num for i in range(hs)) and all(num != board for i in range(box_row, box_row) for j in range(box_col, box_col)):
                            board = num

                            # 递归填充下一个单元格
                            if filling_board(next_row, next_col):
                              return True

                            # 回溯,将当前单元格重置为0
                            board = 0

                  return False

                # 填充数独棋盘
                filling_board(0, 0)
                return board   
               
            # 第一种是出现全部数字,也就是出现全部图案
            board1 = generate_sudoku_board()

            # 定义类型1
            def create_board1():               
                return board1

            # 定义类型2
            def create_board2(): # level数字越大代表游戏难度越大
                """
                生成一个随机的数独棋盘,空白格少
                """
                global board1# 全局变量
               
                # 第二种定量出现空白格子
                board2 =copy.deepcopy(board1)
                ggg=int(g)
                blanks = random.sample(range(hs*hs), int(float(hs*hs*ggg)/100))# 16*97/100=15.52是浮点数,然后再转成整数
                # blanks = 0
                for i in blanks:
                  row = i // hs
                  col = i % hs
                  board2 = 0

                        
                  # if random.randint(0, hs) < level:
                  #   board1 = 0
                return board2
            # 16个数字
            v1 = create_board1()   
            # 16-X个数字   
            v2 = create_board2()

            v=v1+v2
            print(v)
            # [, , , , , , , ]

            

            # 提取每个数字
            P = ['' if a2 == 0 else a2 for a1 in v for a2 in a1]
            print(P)
            print(len(P))
            #
            
            half_len = int(len(P) // 2)
            Q = for i in range(0, len(P), half_len)]
            print(Q)
            # [,]
            

            time.sleep(10)         

                  
      print('------答案卡和题目卡------')
      
      title=['答案','题目']

      imagePath1=path+r'\答案1'
      imagePath2=path+r'\题目1'
      os.makedirs(imagePath1,exist_ok=True)
      os.makedirs(imagePath2,exist_ok=True)

      
               


      ti=      
      
      for tt in range(len(Q)):         
            doc = Document(path+r'\动物数独(6宫格横板).docx')
            # 获取第一个表格,写难度用的
            table = doc.tables
            for b1 in range(0,1):
                # 在'00'单元格中插入文本
                cell_00 = table.cell(0, b1)
                cell_00_paragraph = cell_00.paragraphs
                cell_00_paragraph.text =f"第 {kk+1} 关 {title}"
                cell_00_paragraph.style.font.bold = True
                cell_00_paragraph.style.font.size = Pt(24)
                cell_00_paragraph.style.font.name = "黑体"
                cell_00_paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER

            #   
            table = doc.tables          # 表0,表2 写标题用的
            # 标题写入3、5单元格
            for t in range(0,len(bg)):             # 0-5是最下面一行,用来写关卡数字
                pp=int(bg)   #
                qq=int(bg)
                k=str(Q)            # 提取list图案列表里面每个图形t=索引数字
                print(pp,qq,k)

                # 图案符号的字体、大小参数
                run=table.cell(pp,qq).paragraphs.add_run(k)    # 在单元格0,0(第1行第1列)输入第0个图图案
                run.font.name = '黑体'#输入时默认华文彩云字体
                # run.font.size = Pt(44)#输入字体大小默认30号 换行(一页一份大卡片
                run.font.size = Pt(size) #是否加粗
                # run.font.color.rgb = RGBColor(150,150,150) #数字小,颜色深0-255
                run.font.color.rgb = RGBColor(0,0,0) #数字小,颜色深0-255
                run.bold=True
                # paragraph.paragraph_format.line_spacing = Pt(180) #数字段间距
            
                r = run._element
                r.rPr.rFonts.set(qn('w:eastAsia'), '黑体')#将输入语句中的中文部分字体变为华文行楷
                table.cell(pp,qq).paragraphs.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER#居中

            doc.save(ti+fr'\{z+1:02d}.docx')
            time.sleep(3)

      
            print('------4、每张word转为pdf----')      
            from docx import Document
            from docx.shared import Cm

            # 读取四张卡通动物的文件名
            animal_path = path+r'\02动物图片'# 替换为实际的文件夹路径
            # 获取文件夹中所有文件的完整路径
            file_paths =
            print(file_paths)

      
            doc = Document(ti+fr'\{z+1:02d}.docx')
         

            # 获取所有表格
            tables = doc.tables

            # 遍历每个表格
            for table in tables:
                # 遍历表格的行
                for i, row in enumerate(table.rows):
                  # 遍历行的单元格
                  for j, cell in enumerate(row.cells):
                        # 读取单元格的文本值
                        cell_text = cell.text

                        for x in range(0,hs):
                        # 判断单元格的值是否为1
                            if cell_text == f'{x+1}':
                              # 删除原来的文本
                              cell.text = ''
                              # 插入图片
                              run = cell.paragraphs.add_run()
                              # 4.8格子
                              run.add_picture(file_paths, width=Cm(3), height=Cm(3))
                                    # 设置图片对齐方式为居中
                              run.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
                              # 设置单元格的水平和垂直对齐方式为居中
                              cell.vertical_alignment = WD_ALIGN_PARAGRAPH.CENTER
                              cell.paragraphs.alignment = WD_ALIGN_PARAGRAPH.CENTER
                           

            # 保存修改后的文档
            doc.save(ti+fr'\{z+1:02d}.docx')
            time.sleep(2)

            # # 关闭Word文档
            # doc.close()
            
            from docx2pdf import convert
            # docx 文件另存为PDF文件
            inputFile = ti+fr'\{z+1:02d}.docx'
            outputFile =ti+fr'\{z+1:02d}.pdf'
            # 先创建 不存在的 文件
            f1 = open(outputFile, 'w')
            f1.close()
            # 再转换往PDF中写入内容
            convert(inputFile, outputFile)
            time.sleep(10)      
            
      print('----------更改pdf新名字------------')                  
      # 两个pdf
      import os
      from PyPDF2 import PdfFileReader, PdfFileWriter
      
      tii=

      
      for t3 in range(len(tii)):
            pdf_lst = ) if f.endswith('.pdf')]

            pdf_path = os.path.join(ti, pdf_lst)
            print(pdf_path)         
            # 源头文件名C:\Users\jg2yXRZ\OneDrive\桌面\动物数独6宫格\答案1\01.pdf   
            new_file_name = f"{title} 动物拼图{hs}宫格 难度{kk+1:02d} 空{int(w):03d}格({db}乘{cb}等于{num}份{db*cb}张).pdf"
            

            # 重命名并移动文件到imagePatha文件夹下
            output_path = os.path.join(tii, new_file_name)
            print(output_path)
            # 目标文件名C:\Users\jg2yXRZ\OneDrive\桌面\动物数独6宫格\答案\答案 动物拼图6宫格 难度01 空001格(1乘1等于1份1张).pdf
            os.rename(pdf_path, output_path)            # 源文件名,目标文件名
            time.sleep(5)   
            
            shutil.rmtree(ti) #递归删除文件夹,即:删除非空文件夹
            time.sleep(2)    # 防止转换时报错,预留生成时间


# print('----------第4步:把都有16管PDF关卡变png------------')

#coding=utf-8
from win32com.client import Dispatch
import os
import re
import fitz

wdFormatPDF = 17 #转换的类型
zoom_x=2 #尺寸大小,越大图片越清晰 5超大,这里改成2
zoom_y=2 #尺寸大小,越大图片越清晰,长宽保持一致
rotation_angle=0#旋转的角度,0为不旋转


li=
for l in li:
    for root, dirs, files in os.walk(l):
      for file in files:
            if re.search('\.pdf$', file):
                filename = os.path.abspath(root + "\\" + file)
                print(filename)
                # 打开PDF文件
                pdf = fitz.open(filename)
                # 逐页读取PDF
                for pg in range(0, pdf.pageCount):
                  page = pdf
                  # 设置缩放和旋转系数
                  trans = fitz.Matrix(zoom_x, zoom_y).preRotate(rotation_angle)
                  pm = page.getPixmap(matrix=trans, alpha=True)
                  # 开始写图像
                  pm.writePNG(filename.replace('.pdf', '') + str(pg+1) + ".png")
                pdf.close()

    # 删除生成文件PDF
    for parent, dirnames, filenames in os.walk(l):
      for fn in filenames:
            if fn.lower().endswith('.pdf'):
                os.remove(os.path.join(parent, fn))


print('----------第7步:把关卡png六张六张写入docx,转pdf------------')

   
# -*- coding:utf-8 -*-


# print('----1、读取行列-------')
from docx import Document
from docx.shared import Cm
import os


# # 新建一个”装N份word和PDF“的临时文件夹

imagePath11=path+r'\零时Word11'
imagePath22=path+r'\零时Word22'
os.makedirs(imagePath11,exist_ok=True)
os.makedirs(imagePath22,exist_ok=True)

tiii=
tii=
title=['答案','题目']
for t4 in range(len(tiii)):
# 打开.docx文件
    doc = Document(path +r'\动物数独(6宫格横板)1图关卡.docx')
    # 获取文档中的所有表格
    tables = doc.tables

    # 选择你需要读取的表格(在这种情况下是第1张表格)
    target_table = tables

    # 获取所选表格的行数和列数
    num_rows = len(target_table.rows)
    num_columns = len(target_table.columns)

    print("行数:", num_rows)
    # 3
    print("列数:", num_columns)
    # # 2

   
    import os

   
    # 读取文件夹中所有文件的名称并加上路径
    file_paths = ) for file in files]
    print(file_paths)
    print(len(file_paths))

    pic_list_six = for i in range(0, len(file_paths), 1)]



    # print('----3、插入图片-------')
    for f in range(len(pic_list_six)):
    # # 打开.docx文件
      doc = Document(path +r'\动物数独(6宫格横板)1图关卡.docx')

      # 获取文档中的所有表格
      tables = doc.tables

      # 获取第一个表格
      table = tables   

      # 遍历表格的所有行和单元格   
      i = 0
      for row in table.rows:
            for cell in row.cells:
                # 在单元格中插入图片
                cell_paragraph = cell.paragraphs
                run = cell_paragraph.add_run()
                run.add_picture(pic_list_six, width=Cm(19.6), height=Cm(19.6))
                # Cm(9.84), height=Cm(9.84))
                cell_paragraph.alignment = 1# 设置单元格中的文本居中
                i += 1
               
               

      # 保存修改后的.docx文件
      doc.save(tiii + fr'\{f:02d}页.docx')
      from docx2pdf import convert
      # docx 文件另存为PDF文件
      inputFile =tiii + fr'\{f:02d}页.docx'
      outputFile =tiii + fr'\{f:02d}页.pdf'
      # 先创建 不存在的 文件
      f1 = open(outputFile,'w')
      f1.close()
      # 再转换往PDF中写入内容
      convert(inputFile, outputFile)




    pdf_lst = ) if f.endswith('.pdf')]
    pdf_lst = , filename) for filename in pdf_lst]
    pdf_lst.sort()
    file_merger = PdfMerger()
    for pdf in pdf_lst:
      print(pdf)
      file_merger.append(pdf)
    # file_merger.write("C:/Users/jg2yXRZ/OneDrive/桌面/描字帖/(打印合集)大班A整页描字帖2乘5加表格-4名字-({}人).pdf".format(num))
    file_merger.write(imagePath4+fr"\{t4:02d}{title}.pdf")
    file_merger.close()
      # doc.Close()

    # # # print('----------第5步:删除临时文件夹------------')   
    # import shutil
    # shutil.rmtree(imagePath) #递归删除文件夹,即:删除非空文件夹
    # import shutil
    # shutil.rmtree(imagePath2) #递归删除文件夹,即:删除非空文件夹

    print('----------第8步:把关卡pdf和图卡pdf合并在一起------------')


# 最后把PDF合并
import os
from PyPDF2 import PdfMerger, PdfFileReader

# 创建一个PdfMerger对象
merger = PdfMerger()

# 遍历文件夹中的所有PDF文件

folder_path = path
for filename in os.listdir(imagePath4):
    if filename.endswith('.pdf'):
      # 打开PDF文件z
      pdf_path = os.path.join(imagePath4, filename)
      pdf_file = open(pdf_path, 'rb')
      pdf_reader = PdfFileReader(pdf_file)
   
      # 将PDF文件添加到合并器中
      merger.append(pdf_reader)
      
      # 关闭当前打开的PDF文件
      pdf_file.close()


# 保存合并后的PDF文件
output_path = path+fr"\动物数独{hs}宫格(空格1-{len(w)}({len(w)}关卡图1图一页和{hs*hs}大图卡和{hs*hs}答案卡 最大号图片).pdf"
merger.write(output_path)
merger.close()
time.sleep(3)

print("PDF文件合并完成!")


shutil.rmtree(imagePath4) #递归删除文件夹,即:删除非空文件夹
shutil.rmtree(imagePath22) #递归删除文件夹,即:删除非空文件夹
shutil.rmtree(imagePath) #递归删除文件夹,即:删除非空文件夹
shutil.rmtree(imagePatha) #递归删除文件夹,即:删除非空文件夹
shutil.rmtree(imagePathq) #递归删除文件夹,即:删除非空文件夹
shutil.rmtree(imagePath11) #递归删除文件夹,即:删除非空文件夹    由于是最大的图篇,所以生成了快90分钟!o(╥﹏╥)o



一页贴一张,图片容量大,所以保存的时间要延伸。部分延时time.sleep(10)边长。

https://i-blog.csdnimg.cn/direct/686fb0e48d104b2bb1c3652f4378ed23.png


作品展示

https://i-blog.csdnimg.cn/direct/80b6401410ea413895f7280022dae9a1.png

贴图卡 36张(一张A4一个动物)一个动物约莫20CM,6个动物就是120CM(1,2米)

https://i-blog.csdnimg.cn/direct/88c70e9ea9d3461dbbe9b5693e1fb54b.png
任务卡:

https://i-blog.csdnimg.cn/direct/0eb32b5836bd4be29ebb5760fae20bf1.png
答案卡

https://i-blog.csdnimg.cn/direct/aa77b4cc7aac483196413ab6561e029c.png

对比

https://i-blog.csdnimg.cn/direct/71124c6d251d407591fe87241075b454.png

这是最大号的





免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 【教学类-52-08】20240905动物数独(6宫格)一页2张任务卡,一页一个动物贴