Search Results for

    Show / Hide Table of Contents

    Class PdfAttachment

    Represents a file attachment embedded within a PDF document. Provides access to attachment metadata and binary data for extraction or modification.

    PDF attachments are complete files stored within the PDF container. They appear as paperclip icons in PDF readers and can contain any file type (spreadsheets, images, documents, etc.).

    Example - Extract attachment to disk:

    var pdf = PdfDocument.FromFile("invoice_with_receipt.pdf");
    foreach (var attachment in pdf.Attachments)
    {
        Console.WriteLine($"Found: {attachment.Name} at index {attachment.Index}");
        File.WriteAllBytes(attachment.Name, attachment.Data);
    }

    Inheritance
    System.Object
    PdfClientAccessor
    PdfAttachment
    Namespace: IronPdf
    Assembly: IronPdf.dll
    Syntax
    public class PdfAttachment : PdfClientAccessor
    Remarks

    Common Use Cases:

    Related Resources:

    Properties

    Data

    Gets or sets the raw binary data of the attachment. Read to extract, write to replace content while preserving the filename.

    Example - Extract and modify:

    // Extract attachment data:
    byte[] data = attachment.Data;
    File.WriteAllBytes($"extracted_{attachment.Name}", data);
    

    // Replace attachment content: attachment.Data = File.ReadAllBytes("updated_receipt.pdf"); pdf.SaveAs("invoice_updated.pdf");

    Declaration
    public byte[] Data { get; set; }
    Property Value
    Type Description
    System.Byte[]

    The complete binary content of the attached file.

    Remarks

    Reading this property retrieves data from the PDF. For large attachments, consider caching the result if accessed multiple times.

    Index

    Gets the zero-based index of this attachment within the PDF document. Index may change if attachments are added or removed (alphabetically sorted).

    Declaration
    public int Index { get; }
    Property Value
    Type Description
    System.Int32

    Zero-based position in the attachment collection.

    Name

    Gets the filename of this attachment as stored in the PDF document. Typically includes file extension (e.g., "receipt.pdf", "data.xlsx").

    Use this name when saving extracted attachments to preserve original filenames.

    Declaration
    public string Name { get; }
    Property Value
    Type Description
    System.String

    The attachment filename including extension.

    See Also

    PdfAttachmentCollection
    Attachments
    ☀
    ☾
    Downloads
    • Download with Nuget
    • Start for Free
    In This Article
    Back to top
    Install with Nuget
    Want to deploy IronPDF to a live project for FREE?
    What’s included?
    30 days of fully-functional product
    Test and share in a live environment
    No watermarks in production
    Get your free 30-day Trial Key instantly.
    No credit card or account creation required
    Your Trial License Key has been emailed to you.
    Download IronPDF free to apply
    your Trial Licenses Key
    Install with NuGet View Licenses
    Licenses from $499. Have a question? Get in touch.