python 去除PDF水印
作者:
狼牙雪豹 | 来源:发表于
2022-09-23 16:17 被阅读0次import os
from PyPDF2 import PdfFileReader,PdfFileWriter
current_path = os.getcwd()
file_path = os.getcwd()+'/jianshu/'
print(file_path) # 获取当前工作目录路径)
output = PdfFileWriter()
with open(file_path+"s.pdf", 'rb') as pf:
pin = PdfFileReader(pf)
for i in range(pin.getNumPages()):
page = pin.getPage(i)
page['/Resources']['/XObject']['/Fm0'].clear()
page['/Resources']['/XObject']['/Fm1'].clear()
page['/Resources']['/XObject']['/Fm2'].clear()
page['/Resources']['/XObject']['/Fm3'].clear()
fm4 = page.get('/Resources').get('/XObject').get('/Fm4')
if fm4:
page['/Resources']['/XObject']['/Fm4'].clear()
output.addPage(page)
with open("out.pdf", 'wb') as ouf:
output.write(ouf)
# page['/Resources']即为页面结构,分析结构,找出其中需要删除的元素即可。
本文标题:python 去除PDF水印
本文链接:https://www.haomeiwen.com/subject/ymynortx.html
网友评论