# -*- coding =utf-8 -*-
# @Time : 2021/1/26 10:09
# @Author :Mr
# @File :pdftest.py
# @Software :PyCharm
from PyPDF2 import PdfFileReader, PdfFileWriter
import os
# 创建输出文件目录
def mkdir(read_file_path, out_path=None):
if out_path is None:
out_path = (os.path.join(os.path.dirname(read_file_path),
os.path.basename(read_file_path)[:-4].replace(" ", "")))
if not os.path.exists(out_path): # 判断是否存在文件夹如果不存在则创建为文件夹
# print("--- 创建新的文件夹... ---")
os.makedirs(out_path) # makedirs 创建文件时如果路径不存在会创建这个路径
# print("--- OK ---")
else:
# print("--- 文件夹已存在! ---")
pass
return out_path
# 切分每一页
def split_pdf(read_file_path, out_path=None):
out_path = mkdir(read_file_path, out_path)
pdfReader = PdfFileReader(read_file_path)
for page in r
python使用PyPDF2库进行PDF基本操作
最新推荐文章于 2025-03-15 20:23:58 发布