첨부 파일 추가

Contents
[ ]

PDF의 첨부 파일을 사용하면 추가 문서, 이미지 또는 기타 리소스를 PDF에 직접 포함할 수 있습니다.와 함께 PDF 콘텐츠 편집기, 프로그래밍 방식으로 특정 페이지에 파일을 첨부하고, 첨부 파일 이름을 설정하고, 설명을 제공할 수 있습니다.

  1. PDF 컨텐트 편집기 객체를 만듭니다.
  2. 입력 PDF를 바인딩합니다.
  3. 첨부 파일을 엽니다.
  4. PDF에 첨부 파일을 추가합니다.
  5. 업데이트된 문서를 저장합니다.
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)