优化排版
This commit is contained in:
@@ -17,6 +17,7 @@ from reportlab.pdfbase import pdfmetrics
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from PIL import Image as PILImage
|
from PIL import Image as PILImage
|
||||||
import re # 用于正则表达式提取磁力链接
|
import re # 用于正则表达式提取磁力链接
|
||||||
|
from PyPDF2 import PdfReader, PdfWriter
|
||||||
|
|
||||||
|
|
||||||
def download_image(url):
|
def download_image(url):
|
||||||
@@ -168,9 +169,12 @@ def fetch_and_create_pdf(url):
|
|||||||
# 生成PDF
|
# 生成PDF
|
||||||
doc.build(content)
|
doc.build(content)
|
||||||
|
|
||||||
|
|
||||||
# 获取PDF文件的绝对路径
|
# 获取PDF文件的绝对路径
|
||||||
absolute_pdf_path = os.path.abspath(pdf_filename)
|
absolute_pdf_path = os.path.abspath(pdf_filename)
|
||||||
print(f"PDF saved as {absolute_pdf_path}")
|
print(f"PDF saved as {absolute_pdf_path}")
|
||||||
|
# 加密PDF
|
||||||
|
add_pdf_encryption(absolute_pdf_path)
|
||||||
|
|
||||||
# 关闭浏览器
|
# 关闭浏览器
|
||||||
driver.quit()
|
driver.quit()
|
||||||
@@ -178,6 +182,26 @@ def fetch_and_create_pdf(url):
|
|||||||
return absolute_pdf_path
|
return absolute_pdf_path
|
||||||
|
|
||||||
|
|
||||||
|
def add_pdf_encryption(pdf_file, password="4000"):
|
||||||
|
""" 使用PyPDF2为PDF添加加密保护 """
|
||||||
|
pdf_writer = PdfWriter()
|
||||||
|
pdf_reader = PdfReader(pdf_file)
|
||||||
|
|
||||||
|
# 将所有页面添加到PDF写入器中
|
||||||
|
for page_num in range(len(pdf_reader.pages)):
|
||||||
|
pdf_writer.add_page(pdf_reader.pages[page_num])
|
||||||
|
|
||||||
|
# 添加密码
|
||||||
|
pdf_writer.encrypt(password)
|
||||||
|
|
||||||
|
# 保存加密后的PDF
|
||||||
|
with open(pdf_file, "wb") as output_pdf:
|
||||||
|
pdf_writer.write(output_pdf)
|
||||||
|
|
||||||
|
print(f"PDF加密成功,密码为: {password}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def pdf_file_path():
|
def pdf_file_path():
|
||||||
url = 'https://www.sehuatang.net/forum.php?mod=forumdisplay&fid=103&filter=typeid&typeid=481'
|
url = 'https://www.sehuatang.net/forum.php?mod=forumdisplay&fid=103&filter=typeid&typeid=481'
|
||||||
pdf_path = fetch_and_create_pdf(url)
|
pdf_path = fetch_and_create_pdf(url)
|
||||||
|
|||||||
Reference in New Issue
Block a user