添付ファイルを追加
Contents
[
Hide
]
PDF の添付ファイルを使用すると、補足文書、画像、またはその他のリソースを PDF 内に直接含めることができます。と PDF コンテンツエディター、プログラムによって特定のページにファイルを添付したり、添付ファイル名を設定したり、説明を入力したりできます。
- PDF コンテンツエディターオブジェクトを作成します。
- 入力 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(infile, attachment_file, outfile):
# Create PdfContentEditor object
content_editor = pdf_facades.PdfContentEditor()
# Bind document to PdfContentEditor
content_editor.bind_pdf(infile)
# Add attachment to page 1
with open(attachment_file, "rb") as attachment_stream:
content_editor.add_document_attachment(
attachment_stream,
path.basename(attachment_file),
"This is a sample attachment for demonstration purposes.",
)
# Save updated document
content_editor.save(outfile)