当前位置:网站首页>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开始算
边栏推荐
- 组合系列--有排列就有组合
- Redis与分布式:哨兵模式
- c语言hello world代码(代码编程入门)
- The Selenium IDE of the Selenium test automation
- 多智能体协同控制研究中光学动作捕捉与UWB定位技术比较
- 小试牛刀:Go 反射帮我把 Excel 转成 Struct
- 已解决(pymysqL连接数据库报错)pymysqL.err.ProgrammingError: (1146,“Table ‘test.students‘ doesn‘t exist“)
- Unity学习笔记 关于AVPro视频跳转功能(Seeking)的说明
- Network cable RJ45 interface pins [easy to understand]
- element-plus虚拟表格virtual-list组件中是怎么实现清理lodash.memoize缓存的?
猜你喜欢

一篇文章讲清楚!数据库和数据仓库到底有什么区别和联系?

Resnet&API

“听我说谢谢你”还能用古诗来说?清华搞了个“据意查句”神器,一键搜索你想要的名言警句...

2021 OWASP TOP 10 漏洞指南

49.【拷贝构造函数与重载】
![[Blue Bridge Cup Trial Question 46] Scratch Magnet Game Children's Programming Scratch Blue Bridge Cup Trial Question Explanation](/img/57/f23c21c7ed4b9701a3f6119bfd8493.png)
[Blue Bridge Cup Trial Question 46] Scratch Magnet Game Children's Programming Scratch Blue Bridge Cup Trial Question Explanation

Open Inventor 10.12 Major Improvements - Harmony Edition

小试牛刀:Go 反射帮我把 Excel 转成 Struct

组合系列--有排列就有组合

对数字化时代的企业来说,数据治理难做,但应该去做
随机推荐
Unity Shader入门精要学习——透明效果
使用NVM进行node版本切换管理
组合系列--有排列就有组合
线程池的使用二
The role of /etc/profile, /etc/bashrc, ~/.bash_profile, ~/.bashrc files
推荐系统-召回阶段-2013:DSSM(双塔模型)【Embedding(语义向量)召回】【微软】
Unity学习笔记 关于AVPro视频跳转功能(Seeking)的说明
使用CompletableFuture进行异步处理业务
hyperf的启动源码分析(二)——请求如何到达控制器
ADS communicate with c #
【Pytorch】F.softmax()方法说明
redhat/openssl生成自签ca证书并使用
The 232-layer 3D flash memory chip is here: the single-chip capacity is 2TB, and the transmission speed is increased by 50%
Shell project combat 1. System performance analysis
Shell script classic case: backup of files
Detailed guide to compare two tables using natural full join in SQL
OAuth2:使用JWT令牌
UnityShader入门学习(二)——渲染流水线
Open Inventor 10.12 Major Improvements - Harmony Edition
搭建私有的的Nuget包服务器教程