Add File Attachment Annotation
Contents
[
Hide
]
File attachment annotations allow you to embed external files as interactive icons on a PDF page. Using the file-path overload, you can attach files directly from disk without manually opening streams. This method also lets you customize the annotation icon and provide a description for users.
- Create the PdfContentEditor object.
- Bind the input PDF.
- Define the Annotation Rectangle.
- Add the File Attachment Annotation.
- Save the updated Document.
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_file_attachment_annotation(infile, attachment_file, outfile):
# Create PdfContentEditor object
content_editor = pdf_facades.PdfContentEditor()
# Bind document to PdfContentEditor
content_editor.bind_pdf(infile)
# Create file attachment annotation on page 1
content_editor.create_file_attachment(
apd.Rectangle(100, 520, 20, 20),
"Attachment annotation contents",
attachment_file,
1,
"PushPin",
)
# Save updated document
content_editor.save(outfile)