吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1171|回复: 25
收起左侧

[Python 原创] 小猿口算 PDF去LOGO,加名字和班级

[复制链接]
shieep 发表于 2025-3-25 17:40
小猿口算打印时右下和左上角有LOGO,打印的话不环保浪费墨,我们把他去除,
还有姓名班级手写的话太费劲。直接添加。
直接脚本+处理的文件,或者添加注册表到右键菜单。这个是处理前后对比。
请根据自己实际路径进行修改下。 1111.png
[Python] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import fitz
import sys
import os
font_path = "C:/Windows/Fonts/simsun.ttc"
def process_pdf(input_pdf_path, output_pdf_path, name, class_info):
    doc = fitz.open(input_pdf_path)
    for page in doc:
        # 删除左上角和右下角的图片
        for image in page.get_images(full=True):
            xref = image[0]
            if (image[2]== 558 and image[3]==120) or (image[2]== 215 and image[3]==219):
                page.delete_image(xref)
 
        # 在姓名和班级后面添加信息
        text_instances = page.search_for("姓名:")
        print(text_instances)
        for inst in text_instances:
            page.insert_text((inst.x1, inst.y1-8),name,fontname="china-ss" ,fontsize=12)
 
        text_instances = page.search_for("班级:")
        for inst in text_instances:
            page.insert_text((inst.x1, inst.y1-8),class_info,fontname="china-ss" ,fontsize=12)
 
    doc.save(output_pdf_path)
    doc.close()
 
if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python script.py <input_pdf>")
        sys.exit(1)
 
    input_pdf = sys.argv[1]
    file_name, _ = os.path.splitext(input_pdf)
    output_pdf = f"{file_name}_output.pdf"
    name = "XXX"
    class_info = "一(3)班"
    process_pdf(input_pdf, output_pdf, name, class_info)

添加到PDF右键菜单里
[Asm] 纯文本查看 复制代码
1
2
3
4
5
6
7
Windows Registry Editor Version 5.00
 
[HKEY_CLASSES_ROOT\SystemFileAssociations\.pdf\shell\小猿口算处理]
@="小猿口算处理"
 
[HKEY_CLASSES_ROOT\SystemFileAssociations\.pdf\shell\小猿口算处理\command]
@="\"C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python312\\python.exe\" \"C:\\Users\\Administrator\\Desktop\\pdf_process.py\" \"%1\""

免费评分

参与人数 2吾爱币 +4 热心值 +2 收起 理由
苏紫方璇 + 3 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
chaozhi + 1 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

QQ112 发表于 2025-3-25 17:53
小白动手能力差
xiangdong 发表于 2025-3-25 17:59
好思路,拿走了,把代码改改能用到好多地方,楼主大才
kosjd 发表于 2025-3-25 18:04
1687178877 发表于 2025-3-25 18:06
学习学习
流浪情人 发表于 2025-3-25 18:09
小白学习起来还是比较难的啊
jzjzjz 发表于 2025-3-25 18:20
看着可厉害
烂鬼单车 发表于 2025-3-25 19:05
感谢分享
工地搬砖挣口粮 发表于 2025-3-25 19:16
小学生噩梦
dysunb 发表于 2025-3-25 19:59
这个小程序不错,很实用
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-4-23 19:14

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表