当前位置:网站首页>[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 .
边栏推荐
- Complete software development process
- gin 配置文件
- 基础知识之二——STA相关的基本定义
- [leetcode] climb stairs [70]
- [问题已处理]-nvidia-smi命令获取不到自身容器的GPU进程和外部的GPU进程号
- Use strictmode strictmode principle (1)
- [leetcode] sum of two numbers [1]
- 基础知识之三——标准单元库
- visual studio 2019 快捷键备忘
- Thinking brought by strictmode -strictmode principle (5)
猜你喜欢

使用 C# 创造 ASCII 艺术

Q play soft large toast to bring more comfortable sleep

Locking relay ydb-100, 100V

流批一体在京东的探索与实践

Looksrare team's "cash out" caused disturbance

Xjy-220/43ac220v static signal relay

New opportunities for vr/ar brought by metauniverse

软件开发完整流程

Solve idea:class' xxx 'not found in module' xxx‘

flutter报错 -- The argument type ‘Function‘ can‘t be assigned to the parameter type ‘void Function()?‘
随机推荐
MFC TCP通信服务端客户端Demo备忘vs2019
WIN11中MathType编辑中“打开数学输入面板”是灰色不可编辑
dc_ Study and summary of labs--lab1
What will Web3 bring in the future?
System.CommandLine版CSRebot
Introduction and principle analysis of cluster and LVS
系统设置大页
Unknown database connection database error
用 Flutter 的 Canvas 画点有趣的图形
visual studio 2019 快捷键备忘
短视频平台开发,依靠DrawerLayout实现侧滑菜单效果
6月第4周榜单丨飞瓜数据UP主成长排行榜(哔哩哔哩平台)发布!
尝试新的可能
孙宇晨接受瑞士媒体Bilan采访:熊市不会持续太久
[network packet loss and network delay? This artifact can help you deal with everything!]
Pytorch programming knowledge (2)
TypeError: Argument ‘angle‘ can not be treated as a double
Strictmode analysis activity leakage -strictmode principle (3)
StrictMode分析Registion-StrictMode原理(4)
Interpreting the scientific and technological literacy contained in maker Education