import os
from unrar import rarfile
from PyPDF2 import PdfFileReader, PdfFileWriter
from reportlab.lib.units import cm
from reportlab.pdfgen import canvas
import zipfile
import tarfile
import shutil
import random
class watermark_sv(object):
def __init__(self, path, user_name):
self.six_code = self.six_random()
# 获取上一级目录
pre_path = os.path.abspath(os.path.join(os.getcwd(), ".."))
new_path = os.path.join(pre_path, 'repository/scripts/' + self.six_code)
if not os.path.exists(new_path):
os.mkdir(new_path)
shutil.copy(path, new_path)
(file_path, file_name) = os.path.split(path)
print(file_path, file_name)
# 解压包所在的新路径
new_path = os.path.join(new_path, file_name)
# 解压文件
self.un_zip(new_path)
# 遍历文件夹给PDF加水印
self.dir_scripts(os.getcwd())
# 删除无关的文件
self.delete_file(os.getcwd())
# 在scripts目录下进行压缩
if '.zip' in file_name:
self.zip_file_path(file_name)
elif '.gz' in file_name:
self.tar_gz_file_path(file_name)
all_files = os.listdir(os.getcwd())
for file in all_files:
path = os.path.join(os.getcwd(), file)
if os.path.isdir(path):
shutil.rmtree(path)
# 水印信息
def create_
给文件夹中的pdf加水印升级版(支持zip,tar.gz)
最新推荐文章于 2022-09-17 15:46:12 发布