当前位置:网站首页>[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 .
边栏推荐
- Chromatic judgement bipartite graph
- [leetcode] climb stairs [70]
- 【多源bfs】934. Shortest Bridge
- 尝试新的可能
- Impact relay zc-23/dc220v
- 医疗HIS行业短信发送解决方案
- Strictmode analysis activity leakage -strictmode principle (3)
- 未来的 Web3会带来什么?
- 迪赛智慧数——其他图表(平行坐标图):2021年应届专业就业情况
- Split the linked list [take next first and then cut the linked list to prevent chain breakage]
猜你喜欢

Docker deployment MySQL 8

微研所,微生物检验中常用的生化反应

视频教程 | 长安链推出系列视频教程合集(入门)

flutter报错 -- The argument type ‘Function‘ can‘t be assigned to the parameter type ‘void Function()?‘

数字IC设计流程总结

Openmv and k210 of the f question of the 2021 video game call the openmv API for line patrol, which is completely open source.

Green, green the reed. dew and frost gleam.

Interpreting the scientific and technological literacy contained in maker Education

gin 配置文件

WIN11中MathType编辑中“打开数学输入面板”是灰色不可编辑
随机推荐
Introduction and principle analysis of cluster and LVS
Koa koa combine routes sub route management
Visual studio 2019 Download
Pytorch programming knowledge (2)
ESP8266 RC522
Orb-slam2 source code learning (II) map initialization
微研所,微生物检验中常用的生化反应
Strictmode jamming and leakage detection -strictmode principle (2)
Why not two or four TCP handshakes
mysql插入\更新前+判断条件
visual studio 2019 快捷键备忘
MATLAB 最远点采样(FPS改进版)
Open3D 点云包围盒
Xjy-220/43ac220v static signal relay
Sun Yuchen told Swiss media Bilan that the bear market will not last long
【模拟】922. Sort Array By Parity II
[Deepin] 常用集合
短信在企业中的应用有哪些?
Open3d point cloud bounding box
dc_ Study and summary of labs--lab1