Add Attachment From Path
Contents
[
Hide
]
PDF can include embedded files such as documents, spreadsheets, or images for reference or distribution. The file-path overload of ‘add_document_attachment()’ allows you to add attachments directly from a file path, eliminating the need to open the file manually.
- Create the PdfContentEditor object.
- Bind the input PDF.
- Add the Attachment Using File Path.
- 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_attachment_from_path(infile, attachment_file, outfile):
# Create PdfContentEditor object
content_editor = pdf_facades.PdfContentEditor()
# Bind document to PdfContentEditor
content_editor.bind_pdf(infile)
# Add attachment using file-path overload
content_editor.add_document_attachment(
attachment_file,
"Attachment added using file path overload.",
)
# Save updated document
content_editor.save(outfile)