当前位置:网站首页>PDF 拆分/合并
PDF 拆分/合并
2022-07-31 14:28:00 【[虚幻私塾】】
优质资源分享
学习路线指引(点击解锁) | 知识定位 | 人群定位 |
---|---|---|
🧡 Python实战微信订餐小程序 🧡 | 进阶级 | 本课程是python flask+微信小程序的完美结合,从项目搭建到腾讯云部署上线,打造一个全栈订餐系统。 |
Python量化交易实战 | 入门级 | 手把手带你打造一个易扩展、更安全、效率更高的量化交易系统 |
不会真的有人会去下载那些广告免费,实则要收会员费的黑心软件来进行PDF的拆分合并吧???
在下载两个均不能免费实现PDF自由拆分、合并,以及PDF打印方式会增加文件大小的情况下,一个合格的程序员肯定不能向不良商家低头,所以使用PyPDF2实现这些功能,并给大家分享一个简单、易用、易懂的python小程序。
from PyPDF2 import PdfFileReader, PdfFileMerger, PdfFileWriter
def merge(input1,input2,output):
file\_merger = PdfFileMerger()
file\_merger.append(input1)
file\_merger.append(input2)
file\_merger.write(output)
def split(input,output,start\_page, end\_page):
try:
read\_file = input
fp\_read\_file = open(read\_file, 'rb')
pdf\_input = PdfFileReader(fp\_read\_file) # 将要分割的PDF内容格式话
page\_count = pdf\_input.getNumPages() # 获取PDF页数
print("该文件共有{}页".format(page\_count)) # 打印页数
try:
print(f'开始分割{start\_page}页-{end\_page}页,保存为{output}......')
pdf\_output = PdfFileWriter() # 实例一个 PDF文件编写器
for i in range(start\_page, end\_page):
pdf\_output.addPage(pdf\_input.getPage(i))
with open(output, 'wb') as sub\_fp:
pdf\_output.write(sub\_fp)
print(f'完成分割{start\_page}页-{end\_page}页,保存为{output}!')
except IndexError:
print(f'分割页数超过了PDF的页数')
# fp.close()
except Exception as e:
print(e)
if \_\_name\_\_ == '\_\_main\_\_':
input1 = open(r"1.pdf", "rb") #打开第一个PDF文件
input2 = open(r"2.pdf", "rb") #打开第二个PDF文件
output=r'submit.pdf'
merge(input1,input2,output)
# input = r"submit.pdf" #打开第二个PDF文件
# output= r'1.pdf'
# split(input,output,9,35) # start 起始页 从0 开始算,end 是尾页从1开始算
边栏推荐
- Small test knife: Go reflection helped me convert Excel to Struct
- MySQL玩到这种程度,难怪大厂抢着要!
- 龟速乘【模板】
- Groupid(artifact id)
- 海康摄像机取流RTSP地址规则说明
- leetcode:485.最大连续 1 的个数
- Resolved (pymysqL connect to the database error) pymysqL. Err. ProgrammingError: (1146, "Table" test. Students' doesn 't exist ")
- UnityShader入门学习(三)——Unity的Shader
- 动作捕捉系统用于柔性机械臂的末端定位控制
- 搭建私有的的Nuget包服务器教程
猜你喜欢
以后面试官问你 为啥不建议使用Select *,请你大声回答他!
Resnet&API
MySQL 23 classic interviews hang the interviewer
"Listen to me, thank you" can be said in ancient poetry?Tsinghua University has developed an artifact of "Searching Sentences According to Meaning", which can search for the famous sayings you want wi
1小时直播招募令:行业大咖干货分享,企业报名开启丨量子位·视点
The JVM a class loader
小试牛刀:Go 反射帮我把 Excel 转成 Struct
MySQL玩到这种程度,难怪大厂抢着要!
【redis】发布和订阅消息
OpenShift 4 - 定制 RHACS 安全策略,阻断生产集群使用高风险 Registry
随机推荐
OAuth2:使用JWT令牌
[Blue Bridge Cup Trial Question 46] Scratch Magnet Game Children's Programming Scratch Blue Bridge Cup Trial Question Explanation
MySQL has played to such a degree, no wonder the big manufacturers are rushing to ask for it!
Linux bash: redis-server: 未找到命令
For enterprises in the digital age, data governance is difficult, but it should be done
MySQL【聚合函数】
MySQL【子查询】
组合系列--有排列就有组合
【redis】发布和订阅消息
232层3D闪存芯片来了:单片容量2TB,传输速度提高50%
线程池的使用二
[QNX Hypervisor 2.2用户手册]9.13 rom
redhat/openssl generates a self-signed ca certificate and uses it
leetcode:485.最大连续 1 的个数
尚硅谷-JVM-内存和垃圾回收篇(P1~P203)
R语言的画图代码及差异性分析[通俗易懂]
Comparison of Optical Motion Capture and UWB Positioning Technology in Multi-agent Cooperative Control Research
ERROR: Failed building wheel for osgeo
Selenium自动化测试之Selenium IDE
纸质说明书秒变3D动画,斯坦福大学吴佳俊最新研究,入选ECCV 2022