PDF documents look the same on every device, and they can also keep related files together: other PDF documents, Word documents, Excel spreadsheets, PowerPoint presentations, images, audio or video files can be attached to a PDF document, and they move with it wherever it goes.
How to add attachment to PDF document
Create a Merger with the path to the PDF document.
Call merger.import_document() with a PdfAttachmentOptions that names the file to attach.
Call merger.save() with the path of the result.
The following example attaches a PowerPoint presentation to a PDF document:
fromgroupdocs.mergerimportMergerfromgroupdocs.merger.domain.optionsimportPdfAttachmentOptionsdefadd_attachment_to_pdf_document():withMerger("./input.pdf")asmerger:# Attach the presentation to the PDF documentattachment_options=PdfAttachmentOptions("./attachment.ppt")merger.import_document(attachment_options)merger.save("./output.pdf")if__name__=="__main__":add_attachment_to_pdf_document()
input.pdf is a sample file used in this example. Click here to download it.
attachment.ppt is a sample file used in this example. Click here to download it.
PdfAttachmentOptions("./attachment.ppt"): names the file to attach. To attach content you already hold in memory, pass its bytes and its extension instead: PdfAttachmentOptions(data, ".ppt").
merger.import_document(attachment_options): attaches the file to the loaded PDF document. Its pages do not change.