当前位置:网站首页>[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 .
边栏推荐
猜你喜欢

3dsmax插件开发遍历节点对象和Object获取及INode变换矩阵说明

Uniapp official component clicking item is invalid, solution

Basic knowledge II - Basic definitions related to sta

qt5-MVC:数据可视化的层次揭秘

元宇宙为 VR/AR 带来的新机会

【qt5-tab标签精讲】Tab标签及内容分层解析

Unknown database connection database error

Green, green the reed. dew and frost gleam.

Neo4j installation, operation, project construction and function realization

Call the classic architecture and build the model based on the classic
随机推荐
ASCII、Unicode、GBK、UTF-8之间的关系
visual studio 2019 快捷键备忘
Complete software development process
做生意更加务实
[problem handled] -nvidia SMI command cannot obtain the GPU process number of its own container and the external GPU process number
尝试新的可能
Uniapp official component clicking item is invalid, solution
Strictmode analysis registration strictmode principle (4)
友盟(软件异常实时监听的好帮手:Crash)接入教程(有点基础的小白最易学的教程)
uniapp官方组件点击item无效,解决方案
Solve idea:class' xxx 'not found in module' xxx‘
流批一体在京东的探索与实践
Institute of Microbiology, commonly used biochemical reactions in microbiological testing
MFC TCP communication server client demo notes vs2019
gin 配置文件
微研所,微生物检验中常用的生化反应
Sun Yuchen told Swiss media Bilan that the bear market will not last long
System settings large page
What are the functions of soil microorganisms in microbial detection?
Looksrare team's "cash out" caused disturbance