python批量添加PDF文档水印
from PyPDF2 import PdfReader, PdfWriterimport os
def add_watermark_to_pdfs(folder_path, watermark_pdf, output_folder):
# 确保输出文件夹存在
os.makedirs(output_folder, exist_ok=True)
# 读取文件夹中的所有PDF文件
for filename in os.listdir(folder_path):
if filename.endswith('.pdf'):
pdf_reader = PdfReader(os.path.join(folder_path, filename))
pdf_writer = PdfWriter()
watermark_reader = PdfReader(watermark_pdf)
watermark_page = watermark_reader.pages
for page in pdf_reader.pages:
page.merge_page(watermark_page)
pdf_writer.add_page(page)
# with open(output_pdf, 'wb') as out:
# pdf_writer.write(out)
# 保存添加水印后的PDF文件
with open(os.path.join(output_folder, filename), 'wb') as out:
pdf_writer.write(out)
# 调用函数批量添加水印
folder_path = 'pdf'
watermark_path = 'imgs/vft_logo.PDF'#水印文件存储为pdf
output_folder = 'watermark'
add_watermark_to_pdfs(folder_path, watermark_path, output_folder) beiqian04 发表于 2024-7-24 17:04
可以修改成去除水印吗?
可以的,老铁 很实用,感谢分享 有预览图吗? word里自带的能加不?
很实用,感谢分享 很实用,感谢分享
感谢楼主的分享 可以修改成去除水印吗? 赶快出一期去除水印的吧!