Tambahkan Lampiran

Contents
[ ]

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.

  1. Buat objek PdfContentEditor.
  2. Hubungkan PDF input.
  3. Buka file Attachment.
  4. Tambahkan Attachment ke PDF.
  5. 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)