agentleFS
aspose-pdfaspose-pdf/agentic-net-examples/working-with-attachments/AGENTS.md

agentic-net-examples / working-with-attachments

AGENTS.md2 starsChanged 4 months agoMITView on GitHub

C# examples for working-with-attachments using Aspose.PDF for .NET

The file

We split this AGENTS.md into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Create a {attachment_file} FileSpecification with a {string_literal} description and add it to {doc}.EmbeddedFiles via the Add method to …

    line 115
  2. Distinctive:

    After modifying the attachment collection, persist changes by calling {doc}.Save({output_pdf}).

    line 116
  3. Distinctive:

    Add a file attachment using PdfContentEditor.AddDocumentAttachment({attachment_file}, {string_literal}) where the second argument is the …

    line 118

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS - working-with-attachments

Working with attachments in PDF using C# / .NET -- 49 verified, compile-tested examples for Aspose.PDF for .NET 26.8.0. Each .cs file is a standalone, build-validated console example, generated and runtime-checked by an AI agent before publishing.

Persona

You are a C# developer specializing in PDF processing using Aspose.PDF for .NET, working within the working-with-attachments category. This folder contains standalone C# examples for working-with-attachments operations. See the root agents.md for repository-wide conventions and boundaries.

Scope

  • This folder contains examples for working-with-attachments.
  • Files are standalone .cs examples stored directly in this folder.

Required Namespaces

  • using Aspose.Pdf; (48/49 files) ← category-specific
  • using Aspose.Pdf.Annotations; (16/49 files)
  • using Aspose.Pdf.Drawing; (2/49 files)
  • using Aspose.Pdf.AI; (1/49 files)
  • using Aspose.Pdf.Devices; (1/49 files)
  • using Aspose.Pdf.Facades; (1/49 files)
  • using Aspose.Pdf.Optimization; (1/49 files)
  • using Aspose.Pdf.Text; (1/49 files)
  • using System; (49/49 files)
  • using System.IO; (48/49 files)
  • using System.Collections.Generic; (6/49 files)
  • using NUnit.Framework; (2/49 files)
  • using System.Threading.Tasks; (2/49 files)
  • using System.Diagnostics; (1/49 files)
  • using System.IO.Compression; (1/49 files)
  • using System.Net.Http; (1/49 files)
  • using System.Security.Cryptography; (1/49 files)
  • using System.Text; (1/49 files)
  • using System.Text.Json; (1/49 files)
  • using System.Threading; (1/49 files)
  • using System.Xml.Serialization; (1/49 files)

Common Code Pattern

Most files follow this pattern:

using (Document doc = new Document("input.pdf"))
{
    // ... operations ...
    doc.Save("output.pdf");
}

Files in this folder

FileTitleKey APIsDescription
add-attachment-to-password-protected-pdfAdd Attachment to Password-Protected PDFDocument, FileSpecification, EmbeddedFilesShows how to open an encrypted PDF with a user password, embed a file as an attachment, and save ...
add-file-attachment-to-pdf-with-error-handlingAdd File Attachment to PDF with Error HandlingDocument, FileSpecification, FileAttachmentAnnotationDemonstrates how to attach a file to a PDF page using Aspose.Pdf and includes robust error handli...
add-file-attachment-to-pdfAdd File Attachment to PDFDocument, Page, RectangleDemonstrates how to load an existing PDF, create a FileSpecification for a file, attach it to a p...
add-file-attachment-with-retryAdd File Attachment to PDF with Retry LogicDocument, Page, FileSpecificationShows how to attach a file to the first page of a PDF located on a network share using Aspose.Pdf...
add-image-watermark-to-pdf-attachmentsAdd Image Watermark to PDF AttachmentsDocument, FileSpecification, ImageStampShows how to iterate through embedded PDF attachments, apply an image watermark to every page of ...
add-in-memory-attachment-to-pdfAdd In-Memory Attachment to PDFDocument, FileSpecification, SaveDemonstrates how to embed a file stored in a MemoryStream as an attachment in a PDF using Aspose....
add-multiple-attachments-to-pdfAdd Multiple Attachments to a PDFDocument, FileSpecification, AddShows how to embed several files into an existing PDF by iterating a list of file paths and savin...
add-multiple-files-to-pdf-portfolioAdd Multiple Files to a PDF PortfolioDocument, EmbeddedFileCollection, FileSpecificationDemonstrates how to embed several files of different formats into a single PDF portfolio using As...
add-nested-pdf-to-pdf-portfolioAdd Nested PDF to Existing PDF PortfolioDocument, FileSpecification, EmbeddedFilesCollectionDemonstrates how to embed a PDF file as a nested item inside an existing PDF portfolio using Aspo...
add-unicode-file-attachment-to-pdfAdd Unicode File Attachment to PDFDocument, Page, RectangleShows how to embed a file with a Unicode (e.g., Chinese) filename into a PDF as a file‑attachment...
add-word-document-to-pdf-portfolioAdd Word Document to PDF PortfolioDocument, Collection, FileSpecificationDemonstrates how to create a PDF portfolio and embed a Word (.docx) file using Aspose.Pdf's Colle...
apply-custom-visual-template-to-pdf-portfolioApply Custom Visual Template to PDF PortfolioDocument, Page, GraphShows how to load a PDF Portfolio and apply a visual template to each page by adding a semi‑trans...
attach-file-from-byte-array-to-pdfAttach a File from a Byte Array to a PDFDocument, Page, FileSpecificationDemonstrates how to create a FileSpecification from a byte array using a MemoryStream and add it ...
attach-remote-file-to-pdfAttach Remote File to PDFDocument, Page, RectangleDownloads a file from a remote URL into memory and adds it as a file attachment annotation to an ...
batch-add-attachment-to-pdfsBatch Add Attachment to PDFsDocument, FileSpecification, EmbeddedFilesCollectionShows how to iterate through a folder of PDF files, attach the same external file to each documen...
batch-extract-pdf-attachments-to-zipBatch Extract PDF Attachments to a ZIP ArchiveDocument, EmbeddedFilesCollection, EmbeddedFileShows how to iterate over multiple PDF files, retrieve their embedded attachments with Aspose.Pdf...
compress-pdf-portfolio-with-optimizationCompress PDF Portfolio and Save with OptimizationDocument, OptimizationOptions, OptimizeResourcesShows how to load an existing PDF Portfolio, enable object compression using OptimizationOptions,...
create-pdf-portfolio-embed-filesCreate PDF Portfolio by Embedding FilesDocument, FileSpecification, PagesDemonstrates how to convert an existing PDF into a PDF Portfolio by adding multiple embedded file...
create-pdf-portfolio-with-attachmentsCreate PDF Portfolio with AttachmentsDocument, Collection, FileSpecificationDemonstrates how to create a PDF portfolio document and embed files as attachments using Aspose.P...
delete-outline-items-by-textDelete PDF Outline Items by Matching TextDocument, OutlineCollection, OutlineItemCollectionDemonstrates loading a PDF, searching its outline (bookmark) entries for a specific text, and rem...
delete-pdf-attachment-by-filenameDelete PDF Attachment by Filename using Aspose.PdfDocument, EmbeddedFiles, FindByNameDemonstrates how to locate and remove an embedded file from a PDF by matching its filename with A...
embed-attachment-metadata-into-pdfEmbed Attachment Metadata into PDF Information DictionaryDocument, FileSpecification, PdfFormatConversionOptionsLoads a PDF, adds an embedded file, stores custom attachment metadata in the document information...
embed-hidden-xml-metadata-pdf-attachmentEmbed Hidden XML Metadata as PDF AttachmentDocument, Page, FileAttachmentAnnotationSerializes a custom metadata object to XML, embeds it in a PDF as a hidden file attachment annota...
embed-image-into-pdf-portfolioEmbed Image into PDF Portfolio with Display NameDocument, FileSpecification, AddDemonstrates how to embed an image file into a PDF portfolio using Aspose.Pdf and set a custom di...
extract-attachments-from-encrypted-pdfExtract Attachments from Encrypted PDFDocument, Decrypt, EmbeddedFilesShows how to open a password‑protected PDF, decrypt it, and extract all embedded file attachments...
extract-embedded-file-from-pdf-portfolioExtract Embedded File from PDF Portfolio by IndexDocument, EmbeddedFileCollection, FileSpecificationDemonstrates how to load a PDF containing a portfolio, retrieve an embedded file by its 1‑based i...
extract-embedded-files-from-pdf-portfolioExtract Embedded Files from PDF PortfolioDocument, EmbeddedFiles, SaveThe example opens a PDF portfolio, iterates through its embedded files, and saves each file to a ...
extract-pdf-attachment-metadataExtract PDF Attachment Metadata to JSONDocument, Page, AnnotationShows how to read file‑attachment annotations from a PDF, obtain each attachment's file name and ...
extract-pdf-attachments-in-parallelExtract PDF Attachments in ParallelDocument, EmbeddedFiles, EmbeddedFileShows how to process multiple PDF files concurrently and extract all embedded attachments using A...
extract-pdf-attachments-sha256-hashExtract PDF Attachments and Compute SHA-256 HashesDocument, FileSpecification, EmbeddedFilesCollectionLoads a PDF, enumerates its embedded file attachments, and calculates a SHA‑256 hash for each att...
...and 19 more files

Category Statistics

  • Total examples: 49

Category-Specific Tips

Key API Surface

  • Aspose.Pdf.Document
  • Aspose.Pdf.EmbeddedFileCollection
  • Aspose.Pdf.EmbeddedFilesCollection
  • Aspose.Pdf.Facades.PdfContentEditor
  • Aspose.Pdf.FileEncoding
  • Aspose.Pdf.FileSpecification
  • Aspose.Pdf.FileSpecification.Params
  • Aspose.Pdf.FileSpecificationParams
  • PdfContentEditor.AddDocumentAttachment
  • PdfContentEditor.BindPdf
  • PdfContentEditor.Save

Rules

  • Create a {attachment_file} FileSpecification with a {string_literal} description and add it to {doc}.EmbeddedFiles via the Add method to embed the file in the PDF.
  • After modifying the attachment collection, persist changes by calling {doc}.Save({output_pdf}).
  • Bind a PDF document with PdfContentEditor.BindPdf({input_pdf}) before performing any edit operations.
  • Add a file attachment using PdfContentEditor.AddDocumentAttachment({attachment_file}, {string_literal}) where the second argument is the attachment description.
  • Persist the changes by calling PdfContentEditor.Save({output_pdf}).

Warnings

  • The EmbeddedFiles collection is lazily instantiated; ensure {doc}.EmbeddedFiles is not null before adding.
  • FileSpecification constructor expects the source file to exist on disk.
  • AddDocumentAttachment only supports attaching external files; other attachment types are not covered in this example.
  • The example assumes the PDF contains an EmbeddedFiles collection; calling Delete() on an empty collection is safe but may be unnecessary.
  • The source file referenced in the FileSpecification must exist on disk; otherwise an exception will be thrown.

General Tips

  • See parent AGENTS.md for:
    • Boundaries -- Always / Ask First / Never rules for all examples
    • Common Mistakes -- verified anti-patterns that cause build failures
    • Domain Knowledge -- cross-cutting API-specific gotchas
    • Testing Guide -- build and run verification steps
  • Review code examples in this folder for working-with-attachments patterns
<!-- AUTOGENERATED:START -->

Updated: 2026-08-20 | Run: 20260820_001147_12d7b3

<!-- AUTOGENERATED:END -->

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.