Tambahkan Lampiran
Contents
[
Hide
]
Lampiran file dalam PDF memungkinkan Anda menyertakan dokumen tambahan, gambar, atau sumber daya lainnya langsung dalam PDF. Dengan PdfContentEditor, Anda dapat secara programatis melampirkan file ke halaman tertentu, mengatur nama lampiran, dan memberikan deskripsi.
- Buat objek PdfContentEditor.
- Hubungkan PDF input.
- Buka file Attachment.
- Tambahkan Attachment ke PDF.
- Simpan Document yang diperbarui.
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)