パスから添付ファイルを追加
Contents
[
Hide
]
PDF には、参照または配布用のドキュメント、スプレッドシート、画像などの埋め込みファイルを含めることができます。「add_document_attachment ()」のファイルパスオーバーロードにより、添付ファイルをファイルパスから直接追加できるため、ファイルを手動で開く必要がなくなります。
- 作成 PDF コンテンツエディター 対象。
- 入力 PDF をバインドします。
- ファイルパスを使用して添付ファイルを追加します。
- 更新したドキュメントを保存します。
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)