当前位置:网站首页>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开始算
边栏推荐
- Shell script classic case: backup of files
- Linux bash: redis-server: command not found
- Groupid(artifact id)
- 我把问烂了的MySQL面试题总结了一下
- c语言hello world代码(代码编程入门)
- Nuget打包并上传教程
- Unity Shader入门精要学习——透明效果
- Description of Hikvision camera streaming RTSP address rules
- I summed up the bad MySQL interview questions
- Sentinel服务熔断和降级
猜你喜欢

The 232-layer 3D flash memory chip is here: the single-chip capacity is 2TB, and the transmission speed is increased by 50%

uniapp微信小程序引用标准版交易组件

1小时直播招募令:行业大咖干货分享,企业报名开启丨量子位·视点

多智能体协同控制研究中光学动作捕捉与UWB定位技术比较

In the future, the interviewer asks you why it is not recommended to use Select *, please answer him out loud!

使用NVM进行node版本切换管理

jvm 一之 类加载器

OAuth2:微服务权限校验Session共享

OAuth2:搭建授权服务器

I summed up the bad MySQL interview questions
随机推荐
Open Inventor 10.12 重大改进--和谐版
Prometheus之node_exporter性能监控信息采集含义
A detailed guide to simulating latency with SQL/JDBC
为什么要分库分表?
Comparison of Optical Motion Capture and UWB Positioning Technology in Multi-agent Cooperative Control Research
Use of C# Assembly
NPM Taobao mirror (latest version) released a new version of npm mirror at 2021-11-21 16:53:52 [easy to understand]
C# Get network card information NetworkInterface IPInterfaceProperties
小试牛刀:Go 反射帮我把 Excel 转成 Struct
小试牛刀:Go 反射帮我把 Excel 转成 Struct
AWS implements scheduled tasks - Lambda+EventBridge
Message queue data storage MySQL table design
[QNX Hypervisor 2.2用户手册]9.14 safety
Nuget package and upload tutorial
Linux bash: redis-server: command not found
Linux bash: redis-server: 未找到命令
Uniapp WeChat small application reference standard components
How to clean up the lodash.memoize cache in the element-plus virtual table virtual-list component?
OAuth2:四种授权方式
三角恒等变换公式