当前位置:网站首页>[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 .
边栏推荐
- [Deepin] 常用集合
- Open3D 点云包围盒
- 软件开发完整流程
- flutter报错 -- The argument type ‘Function‘ can‘t be assigned to the parameter type ‘void Function()?‘
- 45岁程序员告诉你:程序员为什么要跳槽,太真实...
- Introduction and principle analysis of cluster and LVS
- Dx-11q signal relay
- Install redis database and download redis Desktop Manager in win11
- Gin configuration file
- Sécurité et santé microbiennes, qu'est - ce que le traitement biologique?
猜你喜欢
随机推荐
Service grid ASM year end summary: how do end users use the service grid?
Locking relay ydb-100, 100V
用 Flutter 的 Canvas 画点有趣的图形
Construction and beautification of personal blog
C语言一点点(未来可会增加)
MFC TCP communication server client demo notes vs2019
Kongyiji's first question: how much do you know about service communication?
[simulation] 922 Sort Array By Parity II
Note d'étude du DC: zéro dans le chapitre officiel - - Aperçu et introduction du processus de base
Visual studio 2019 Download
gin 配置文件
Xjy-220/43ac220v static signal relay
Why build a personal blog
Exploration and practice of "flow batch integration" in JD
Visual studio 2019 shortcut notes
Opencv basic operation 2 realizes label2rgb and converts gray-scale images into color images
Document service design
微生物检测,土壤微生物的作用有哪些?
[问题已处理]-nvidia-smi命令获取不到自身容器的GPU进程和外部的GPU进程号
Split the linked list [take next first and then cut the linked list to prevent chain breakage]









