当前位置:网站首页>[Office PDF] PDF merging and splitting will free us from the functional limitations of paid software, OK
[Office PDF] PDF merging and splitting will free us from the functional limitations of paid software, OK
2022-07-01 01:32:00 【Teacher Detian】
Good tools , You can do more with less , Study together today Pdf Combination and separation
Tool module PyPDF2
Analytic hierarchy process — File path and file reading and saving
Read into folder :
data\in
Read in file name :temp.pdf
Save the folder :
data\out
Save the file ,1.pdf,2.pdf,3.pdf…
Merge files :
431.pdf
Analytic hierarchy process — Take every page out of the file
pdf_writer = PdfFileWriter()
page = pdfReader.getPage(page_no)
pdf_writer.addPage(page)
Analytic hierarchy process — Take every page out of the file
Construct path information including path and file name of each page
file ='{0}.pdf'.format(page_no + 1)
outfile = os.path.join(outdir,file)
Analytic hierarchy process — Create path information to hard disk , At the same time call pdf_writer Saved page information in , Write to the specified outfile Location
notes :output_pdf Yes receive from pdf_writer Of writing information .
with open(outfile,'wb') as output_pdf:
pdf_writer.write(output_pdf)
print(' Split and write the file ')
Analytic hierarchy process — Rebuild write variables pdf_wrigter, Specify sequence number as 3,0,2 Page added to pdf_writer in ( Merge )
pdf_writer = PdfFileWriter()
pdf_writer.addPage(pdfReader.getPage(3))
pdf_writer.addPage(pdfReader.getPage(0))
pdf_writer.addPage(pdfReader.getPage(2))
Analytic hierarchy process — Re create file name , route , Complete file information , adopt with open() Write to hard disk , Finish writing after merging
file = '431.pdf'
outfile = os.path.join(outdir,file)
with open(outfile,'wb') as output_pdf:
pdf_writer.write(output_pdf)
print(' Select the page you want to merge ')
The following is the complete code
# coding = utf-8
from PyPDF2 import *
import os
indir = r'data\in'
outdir = r'data\out'
infile = os.path.join(indir,'temp.pdf') # Read file path
pdfReader = PdfFileReader(infile)
for page_no in range(pdfReader.numPages):
pdf_writer = PdfFileWriter()
page = pdfReader.getPage(page_no)
pdf_writer.addPage(page)
file ='{0}.pdf'.format(page_no + 1)
outfile = os.path.join(outdir,file)
with open(outfile,'wb') as output_pdf:
pdf_writer.write(output_pdf)
print(' Split complete ')
pdf_writer = PdfFileWriter()
pdf_writer.addPage(pdfReader.getPage(3))
pdf_writer.addPage(pdfReader.getPage(0))
pdf_writer.addPage(pdfReader.getPage(2))
file = '431.pdf'
outfile = os.path.join(outdir,file)
with open(outfile,'wb') as output_pdf:
pdf_writer.write(output_pdf)
print(' Select the page you want to merge ')
Journal entry :
- Code segment writing , analysis , The purpose is to facilitate readers to read and understand the connotation of each small piece of code
- By parsing these small pieces of code , Let us understand the logic of the code
- Through the analysis before and after, let us know python The code is still easy to understand , Easy to read
Learning experience :
Language learning is not a fast process , The improvement of ability , It really needs the accumulation of knowledge , The connotation of every small code , Combine into large blocks of code , Large code blocks are combined into the whole software body , So as to complete the creation of systematic engineering .
Remind every learner not to be too impatient , Within the scope of your own time , Let Zhen knock the code , Ponder over the logic of the code , More accumulation , One day you finally , You will suddenly feel enlightened .
边栏推荐
- Interpreting the scientific and technological literacy contained in maker Education
- Installing mongodb database in Windows Environment
- About vctk datasets
- [leetcode] sum of two numbers [1]
- Install redis database and download redis Desktop Manager in win11
- Open3D 点云包围盒
- 短视频平台开发,依靠DrawerLayout实现侧滑菜单效果
- [network packet loss and network delay? This artifact can help you deal with everything!]
- 软件开发完整流程
- WIN11中MathType编辑中“打开数学输入面板”是灰色不可编辑
猜你喜欢

Docker deployment MySQL 8

微生物健康,食品微生物检测为什么很重要

数字IC设计流程总结

What will Web3 bring in the future?

6月第4周榜单丨飞瓜数据UP主成长排行榜(哔哩哔哩平台)发布!

Unknown database连接数据库错误

neo4j安装、运行以及项目的构建和功能实现

Exploration and practice of "flow batch integration" in JD

Call the classic architecture and build the model based on the classic

gin_ gorm
随机推荐
Unknown database连接数据库错误
sort自定义函数
Digital IC design process summary
[dynamic planning] path dp:931 Minimum Falling Path Sum
[leetcode] sum of two numbers [1]
qt5-MVC:数据可视化的层次揭秘
【qt5-tab标签精讲】Tab标签及内容分层解析
Pytorch programming knowledge (2)
MFC TCP communication server client demo notes vs2019
Draw some interesting figures with flutter's canvas
流批一体在京东的探索与实践
数字IC设计流程总结
Pre training / transfer learning of models
[simulation] 922 Sort Array By Parity II
【模拟】922. Sort Array By Parity II
微生物健康,食品微生物检测为什么很重要
视频教程 | 长安链推出系列视频教程合集(入门)
TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to
用 Flutter 的 Canvas 画点有趣的图形
K210 site helmet