IRONSOFTWAREHOME
Add Attachments
from ironpdf import *

# Instantiate the Renderer and create PdfDocument from HTML
renderer = ChromePdfRenderer()
my_pdf = renderer.RenderHtmlFileAsPdf("my-content.html")

# Open PDF document to be attached
pdf = PdfDocument.FromFile("new_sample.pdf")
 
# Here we can add an attachment with a name and a byte[]
attachment1 = my_pdf.Attachments.AddAttachment("attachment_1", pdf.BinaryData)
 
# And here is an example of removing an attachment
my_pdf.Attachments.RemoveAttachment(attachment1)
 
my_pdf.SaveAs("my-content.pdf")
pip install ironpdf
Add Attachments

Add Attachments

IronPDF for Python can embed file attachments within a PDF document and remove them programmatically, using the Attachments collection on any PdfDocument object.

Getting Started

Load or render a PdfDocument, then use Attachments.AddAttachment to embed binary data as a named attachment. Use Attachments.RemoveAttachment to remove an attachment by reference.

Understanding the Code

  • pdf.Attachments.AddAttachment(name, data): Embeds a file attachment in the PDF with the given name. The second argument accepts a byte[] (binary data). In this example, pdf.BinaryData provides the raw bytes of a second loaded PdfDocument.
    • Returns an attachment reference object that can be used later with RemoveAttachment.
  • my_pdf.Attachments.RemoveAttachment(attachment): Removes a previously added attachment from the document using the reference returned by AddAttachment.
  • SaveAs(path): Saves the final document, with all attachments embedded or removed as configured.

Use Cases

Attachments are useful for including source data alongside a report PDF - for example, embedding the raw spreadsheet, XML data file, or original HTML template that was used to generate the document. Embedded attachments are portable and travel with the PDF file.

Ready to Get Started?

Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Python Module Download for PDF
Install with pip

Version: 2026.9

  1. Download and install Python 3.7+.
  2. Install pip from pypi.org if it isn't installed already.
  3. Execute the above command in the terminal.
Python PDF Module
Download Module

Version: 2026.9

Manually install into your project

  1. Download the package
  2. Run this command from the terminal
    pip install ironpdf-2026.9-py37-none-win_amd64.whi

Licenses from $999