删除附件
Contents
[
Hide
]
PDF 可能包含文档、图像或其他文件等附件。在出于安全、隐私或分发目的需要清除 PDF 中所有附件的场景中。使用 PdfContentEditor,您可以以编程方式删除文档中所有嵌入的附件。
- 创建 PdfContentEditor 对象。
- 绑定输入 PDF。
- 删除所有附件。
- 保存已更新的 Document。
import aspose.pdf.facades as pdf_facades
import aspose.pydrawing as apd
from io import BytesIO
import sys
from os import path
sys.path.append(path.join(path.dirname(__file__), ".."))
from config import set_license, initialize_data_dir
def remove_attachments(infile, outfile):
# Create PdfContentEditor object
content_editor = pdf_facades.PdfContentEditor()
# Bind document to PdfContentEditor
content_editor.bind_pdf(infile)
# Remove all attachments from document
content_editor.delete_attachments()
# Save updated document
content_editor.save(outfile)