当前位置:网站首页>PDF Text merge
PDF Text merge
2022-07-24 05:58:00 【Didi'cv】
PDF text merge
import os
from PyPDF2 import PdfFileReader, PdfFileWriter
# Use os Modular walk function , Search out all under the specified directory PDF file
# Get all in the same directory PDF The absolute path to the file
def getnumber(path):
try:
res = int(os.path.basename(path).split('.')[0])
except:
res = 10000000
return res
def getFileName(filedir):
file_list = [os.path.join(root, filespath) \
for root, dirs, files in os.walk(filedir) \
for filespath in files \
if str(filespath).endswith('pdf')
]
file_list = sorted(file_list,key=lambda x: getnumber(x))
return file_list if file_list else []
# Merge all under the same directory PDF file
def MergePDF(filepath, outfile):
output = PdfFileWriter()
outputPages = 0
pdf_fileName = getFileName(filepath)
if pdf_fileName:
for index, pdf_file in enumerate(pdf_fileName):
print(" route :%s"%pdf_file)
# Read source PDF file
input = PdfFileReader(open(pdf_file, "rb"))
# Get the source PDF The total number of pages in the file
# if index == 4: pageCount = 1
# else: pageCount = input.getNumPages()
pageCount = input.getNumPages()
outputPages += pageCount
print(" the number of pages :%d"%pageCount)
# Separately page Add to output output in
for iPage in range(pageCount):
output.addPage(input.getPage(iPage))
print(" Total combined pages :%d."%outputPages)
# Write to target PDF file
outPath = os.path.join(filepath, outfile)
if os.path.isfile(outPath) == True:
print(outPath, "PDF file already exist , Please delete and try again !")
return False
outputStream = open(outPath, "wb")
output.write(outputStream)
outputStream.close()
# print("PDF File merge complete !")
return True
else:
# print(" There is nothing to merge PDF file !")
return False
if __name__ == "__main__":
file_dir = input(' Please input Pdf Folder : ').replace('/','//')# Deposit PDF Original folder
outfile = "out.pdf" # Output PDF The name of the document
flag = MergePDF(file_dir, outfile)
if flag: print('PDF merger ')
else: print('PDF Merger failed , Please try again !')
Usage method

Number sorting , Generate the combined PDF file .
边栏推荐
- Watermelon book / Pumpkin book -- Chapter 1 and 2 Summary
- 《统计学习方法(第2版)》李航 第14章 聚类方法 思维导图笔记 及 课后习题答案(步骤详细) k-均值 层次聚类 第十四章
- "Statistical learning methods (2nd Edition)" Li Hang Chapter 17 latent semantic analysis LSA LSI mind mapping notes and after-school exercise answers (detailed steps) Chapter 17
- Draw contour cv2.findcontours function and parameter interpretation
- Statistical learning methods (2nd Edition) Li Hang Chapter 22 summary of unsupervised learning methods mind mapping notes
- "Statistical learning methods (2nd Edition)" Li Hang Chapter 15 singular value decomposition SVD mind map notes and after-school exercise answers (detailed steps) SVD matrix singular value Chapter 15
- CRC-16 Modbus代码
- Thymeleaf快速入门学习
- String methods and instances
- Qt新建工程简介
猜你喜欢

YOLOv5学习总结(持续更新)
![[activiti] Introduction to activiti](/img/99/e973279d661960853b3af69a7e8ef2.png)
[activiti] Introduction to activiti

"Statistical learning methods (2nd Edition)" Li Hang Chapter 14 clustering method mind map notes and after-school exercise answers (detailed steps) K-means hierarchical clustering Chapter 14

Could not load library cudnn_ cnn_ infer64_ 8.dll. Error code 126Please make sure cudnn_ cnn_ infer64_ eight

【深度学习】手写神经网络模型保存
![[MYCAT] MYCAT configuration file](/img/53/63a633d3ae917e3754f9f7f5c6567f.png)
[MYCAT] MYCAT configuration file

顺序栈 C语言 进栈 出栈 遍历

《统计学习方法(第2版)》李航 第17章 潜在语义分析 LSA LSI 思维导图笔记 及 课后习题答案(步骤详细)第十七章

用指针访问二维数组

Jupyter notebook选择conda环境
随机推荐
《机器学习》(周志华)第2章 模型选择与评估 笔记 学习心得
Chapter 5 neural network
On the concepts of "input channel" and "output channel" in convolutional neural networks
MySql与Qt连接、将数据输出到QT的窗口tableWidget详细过程。
Thymeleaf快速入门学习
"Statistical learning methods (2nd Edition)" Li Hang Chapter 14 clustering method mind map notes and after-school exercise answers (detailed steps) K-means hierarchical clustering Chapter 14
找数组中出现次数最多的数
Could not load library cudnn_ cnn_ infer64_ 8.dll. Error code 126Please make sure cudnn_ cnn_ infer64_ eight
Typora 安装包2021年11月最后一次免费版本的安装包下载V13.6.1
labelme转voc代码中的一个小问题
LSTM神经网络
STM32 DSP library MDK vc5\vc6 compilation error: 256, (const float64_t *) twiddlecoeff64_ 256, armBitRevIndexTableF64_ 256,
tensorflow和pytorch框架的安装以及cuda踩坑记录
DeepSort 总结
Add se channel attention module to the network
Iotp2pgate two IOT devices point-to-point communication fast implementation scheme
STM32 standard peripheral Library (Standard Library) official website download method, with 2021 latest standard firmware library download link
[deep learning] handwritten neural network model preservation
Could not load library cudnn_cnn_infer64_8.dll. Error code 126Please make sure cudnn_cnn_infer64_8.
CRC-16 MODBUS code