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

deepl翻译的PDF文档保护密码解除

1、首先将后缀名(.docx)修改为压缩包格式(.zip)。

2、修改解密word加密.py里zip的位置,和新生成的zip的位置和名称

import zipfile
import xml.etree.ElementTree as ET
import os
import shutil# 定义文件路径
zip_file_path = r'C:\Users\Administrator\Desktop\新建文件夹 (3)\小说 en.zip'
new_zip_file_path = r'C:\Users\Administrator\Desktop\新建文件夹 (3)\小说 en_modified.zip'
xml_file_path_in_zip = 'word/settings.xml'# 创建临时目录
temp_dir = 'temp_zip'
os.makedirs(temp_dir, exist_ok=True)# 打开 ZIP 文件
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:# 解压缩所有文件到临时目录zip_ref.extractall(temp_dir)# 构建完整的 XML 文件路径
xml_file_full_path = os.path.join(temp_dir, xml_file_path_in_zip)# 解析 XML 文件,并指定命名空间
tree = ET.parse(xml_file_full_path)
root = tree.getroot()# 定义命名空间
namespace = {'w': 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'}# 查找并修改 w:documentProtection 元素的 w:enforcement 属性
document_protection = root.find('.//w:documentProtection', namespace)
if document_protection is not None:if '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}enforcement' in document_protection.attrib:document_protection.attrib['{http://schemas.openxmlformats.org/wordprocessingml/2006/main}enforcement'] = 'false'# 将修改后的 XML 文件保存回临时目录
tree.write(xml_file_full_path, encoding='utf-8', xml_declaration=True, default_namespace='http://schemas.openxmlformats.org/wordprocessingml/2006/main')# 创建新的 ZIP 文件
with zipfile.ZipFile(new_zip_file_path, 'w', zipfile.ZIP_DEFLATED) as new_zip_ref:for foldername, subfolders, filenames in os.walk(temp_dir):for filename in filenames:file_path = os.path.join(foldername, filename)arcname = os.path.relpath(file_path, temp_dir)new_zip_ref.write(file_path, arcname)# 清理临时目录
shutil.rmtree(temp_dir)print(f'修改后的 ZIP 文件已保存到: {new_zip_file_path}')

3、运行解密word加密.py

4、将新生成的zip后缀改回.docx

5、打开.docx看是否已经解除密码保护了

http://www.lryc.cn/news/382285.html

相关文章:

  • LeetCode 算法:二叉树的直径 c++
  • 盘立方期货Kdj幅图指标公式源码
  • SkyWalking 极简入门
  • 本篇内容:ArkTS开发系列之事件(2.8.1触屏、键鼠、焦点事件)
  • 测试的基础知识大全【测试概念、分类、模型、流程、测试用例书写、用例设计、Bug、基础功能测试实战】
  • Power Apps
  • qt图像处理-将OpenCV的cv::Mat类型转换为QImage类型
  • 代码随想录训练营第十八天 530二叉搜索树的最小绝对差 501二叉搜索树中的众数 236二叉树的最近公共祖先
  • 微信小程序之横向列表展示
  • 无人机巡检小羊仿真
  • springboot redission 分布式锁
  • Vuex中的重要核心属性
  • Redis哨兵集群搭建
  • 网络爬虫requests库使用指南
  • VSCODE 配置C++ 与OPENCV
  • C语言小例程28/100
  • WPF文本绑定显示格式StringFormat设置-特殊格式时间日期和多数据绑定
  • Java包介绍
  • 【2024.6.21】今日科技时事:科技前沿大事件
  • LeetCode:经典题之1491、896 题解与延伸
  • 2024三掌柜赠书活动第二十五期:Rust 游戏开发实战
  • 基于Java蛋糕甜品商城系统设计和实现(源码+LW+调试文档+讲解等)
  • Tomcat get请求传数组集合参数
  • 信息学奥赛初赛天天练-34-CSP-J2021完善程序-按位异或、模拟算法、数组模拟环、约瑟夫问题应用
  • 【计算机视觉】人脸算法之图像处理基础知识(六)
  • 仓颉编程语言入门
  • 在前端项目中,如何处理错误和异常?
  • Ubuntu系统下修改网卡IP地址
  • Scrapy如何对爬虫数据进行清洗和处理?
  • Linux:基础IO(三.软硬链接、动态库和静态库、动精态库的制作和加载)