从路径添加附件
Contents
[
Hide
]
PDF 可以包含嵌入的文件,例如文档、电子表格或图像,以供参考或分发。‘add_document_attachment()’ 的文件路径重载允许您直接从文件路径添加附件,消除手动打开文件的需求。
- 创建 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 add_attachment_from_path(infile, attachment_file, outfile):
# Create PdfContentEditor object
content_editor = pdf_facades.PdfContentEditor()
# Bind document to PdfContentEditor
content_editor.bind_pdf(infile)
# Add attachment using file-path overload
content_editor.add_document_attachment(
attachment_file,
"Attachment added using file path overload.",
)
# Save updated document
content_editor.save(outfile)