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
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository36 other files it gives its agents.
- accessibility-and-tagged-pdfsAGENTS.md
- aspose-pdf-examplesAGENTS.md
- basic-operationsAGENTS.md
- compare-pdfAGENTS.md
- conversionAGENTS.md
- documentAGENTS.md
- facades-acroformsAGENTS.md
- facades-annotationsAGENTS.md
- facades-bookmarksAGENTS.md
- facades-convert-documentsAGENTS.md
- facades-documentsAGENTS.md
- facades-edit-documentAGENTS.md
- facades-extract-images-and-textAGENTS.md
- facades-fill-formsAGENTS.md
- facades-formsAGENTS.md
- facades-metadataAGENTS.md
- facades-pagesAGENTS.md
- facades-secure-documentsAGENTS.md
- facades-sign-documentsAGENTS.md
- facades-stampsAGENTS.md
- facades-texts-and-imagesAGENTS.md
- facades-xmp-metadataAGENTS.md
- graphs-zugferd-operatorsAGENTS.md
- pagesAGENTS.md
- parse-pdfAGENTS.md
- securing-and-signing-pdfAGENTS.md
- stampingAGENTS.md
- uncategorizedAGENTS.md
- working-with-annotationsAGENTS.md
- working-with-formsAGENTS.md
- working-with-graphsAGENTS.md
- working-with-imagesAGENTS.md
- working-with-tablesAGENTS.md
- working-with-textAGENTS.md
- working-with-xmlAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
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
- Distinctive: line 115
Create a {attachment_file} FileSpecification with a {string_literal} description and add it to {doc}.EmbeddedFiles via the Add method to …
- Distinctive: line 116
After modifying the attachment collection, persist changes by calling {doc}.Save({output_pdf}).
- Distinctive: line 118
Add a file attachment using PdfContentEditor.AddDocumentAttachment({attachment_file}, {string_literal}) where the second argument is the …
≈ “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.
Files
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
.csfile 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
.csexamples stored directly in this folder.
Required Namespaces
using Aspose.Pdf;(48/49 files) ← category-specificusing 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
| File | Title | Key APIs | Description |
| add-attachment-to-password-protected-pdf | Add Attachment to Password-Protected PDF | Document, FileSpecification, EmbeddedFiles | Shows 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-handling | Add File Attachment to PDF with Error Handling | Document, FileSpecification, FileAttachmentAnnotation | Demonstrates how to attach a file to a PDF page using Aspose.Pdf and includes robust error handli... |
| add-file-attachment-to-pdf | Add File Attachment to PDF | Document, Page, Rectangle | Demonstrates how to load an existing PDF, create a FileSpecification for a file, attach it to a p... |
| add-file-attachment-with-retry | Add File Attachment to PDF with Retry Logic | Document, Page, FileSpecification | Shows 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-attachments | Add Image Watermark to PDF Attachments | Document, FileSpecification, ImageStamp | Shows how to iterate through embedded PDF attachments, apply an image watermark to every page of ... |
| add-in-memory-attachment-to-pdf | Add In-Memory Attachment to PDF | Document, FileSpecification, Save | Demonstrates how to embed a file stored in a MemoryStream as an attachment in a PDF using Aspose.... |
| add-multiple-attachments-to-pdf | Add Multiple Attachments to a PDF | Document, FileSpecification, Add | Shows how to embed several files into an existing PDF by iterating a list of file paths and savin... |
| add-multiple-files-to-pdf-portfolio | Add Multiple Files to a PDF Portfolio | Document, EmbeddedFileCollection, FileSpecification | Demonstrates how to embed several files of different formats into a single PDF portfolio using As... |
| add-nested-pdf-to-pdf-portfolio | Add Nested PDF to Existing PDF Portfolio | Document, FileSpecification, EmbeddedFilesCollection | Demonstrates how to embed a PDF file as a nested item inside an existing PDF portfolio using Aspo... |
| add-unicode-file-attachment-to-pdf | Add Unicode File Attachment to PDF | Document, Page, Rectangle | Shows how to embed a file with a Unicode (e.g., Chinese) filename into a PDF as a file‑attachment... |
| add-word-document-to-pdf-portfolio | Add Word Document to PDF Portfolio | Document, Collection, FileSpecification | Demonstrates how to create a PDF portfolio and embed a Word (.docx) file using Aspose.Pdf's Colle... |
| apply-custom-visual-template-to-pdf-portfolio | Apply Custom Visual Template to PDF Portfolio | Document, Page, Graph | Shows 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-pdf | Attach a File from a Byte Array to a PDF | Document, Page, FileSpecification | Demonstrates how to create a FileSpecification from a byte array using a MemoryStream and add it ... |
| attach-remote-file-to-pdf | Attach Remote File to PDF | Document, Page, Rectangle | Downloads a file from a remote URL into memory and adds it as a file attachment annotation to an ... |
| batch-add-attachment-to-pdfs | Batch Add Attachment to PDFs | Document, FileSpecification, EmbeddedFilesCollection | Shows how to iterate through a folder of PDF files, attach the same external file to each documen... |
| batch-extract-pdf-attachments-to-zip | Batch Extract PDF Attachments to a ZIP Archive | Document, EmbeddedFilesCollection, EmbeddedFile | Shows how to iterate over multiple PDF files, retrieve their embedded attachments with Aspose.Pdf... |
| compress-pdf-portfolio-with-optimization | Compress PDF Portfolio and Save with Optimization | Document, OptimizationOptions, OptimizeResources | Shows how to load an existing PDF Portfolio, enable object compression using OptimizationOptions,... |
| create-pdf-portfolio-embed-files | Create PDF Portfolio by Embedding Files | Document, FileSpecification, Pages | Demonstrates how to convert an existing PDF into a PDF Portfolio by adding multiple embedded file... |
| create-pdf-portfolio-with-attachments | Create PDF Portfolio with Attachments | Document, Collection, FileSpecification | Demonstrates how to create a PDF portfolio document and embed files as attachments using Aspose.P... |
| delete-outline-items-by-text | Delete PDF Outline Items by Matching Text | Document, OutlineCollection, OutlineItemCollection | Demonstrates loading a PDF, searching its outline (bookmark) entries for a specific text, and rem... |
| delete-pdf-attachment-by-filename | Delete PDF Attachment by Filename using Aspose.Pdf | Document, EmbeddedFiles, FindByName | Demonstrates how to locate and remove an embedded file from a PDF by matching its filename with A... |
| embed-attachment-metadata-into-pdf | Embed Attachment Metadata into PDF Information Dictionary | Document, FileSpecification, PdfFormatConversionOptions | Loads a PDF, adds an embedded file, stores custom attachment metadata in the document information... |
| embed-hidden-xml-metadata-pdf-attachment | Embed Hidden XML Metadata as PDF Attachment | Document, Page, FileAttachmentAnnotation | Serializes a custom metadata object to XML, embeds it in a PDF as a hidden file attachment annota... |
| embed-image-into-pdf-portfolio | Embed Image into PDF Portfolio with Display Name | Document, FileSpecification, Add | Demonstrates how to embed an image file into a PDF portfolio using Aspose.Pdf and set a custom di... |
| extract-attachments-from-encrypted-pdf | Extract Attachments from Encrypted PDF | Document, Decrypt, EmbeddedFiles | Shows how to open a password‑protected PDF, decrypt it, and extract all embedded file attachments... |
| extract-embedded-file-from-pdf-portfolio | Extract Embedded File from PDF Portfolio by Index | Document, EmbeddedFileCollection, FileSpecification | Demonstrates how to load a PDF containing a portfolio, retrieve an embedded file by its 1‑based i... |
| extract-embedded-files-from-pdf-portfolio | Extract Embedded Files from PDF Portfolio | Document, EmbeddedFiles, Save | The example opens a PDF portfolio, iterates through its embedded files, and saves each file to a ... |
| extract-pdf-attachment-metadata | Extract PDF Attachment Metadata to JSON | Document, Page, Annotation | Shows how to read file‑attachment annotations from a PDF, obtain each attachment's file name and ... |
| extract-pdf-attachments-in-parallel | Extract PDF Attachments in Parallel | Document, EmbeddedFiles, EmbeddedFile | Shows how to process multiple PDF files concurrently and extract all embedded attachments using A... |
| extract-pdf-attachments-sha256-hash | Extract PDF Attachments and Compute SHA-256 Hashes | Document, FileSpecification, EmbeddedFilesCollection | Loads 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.DocumentAspose.Pdf.EmbeddedFileCollectionAspose.Pdf.EmbeddedFilesCollectionAspose.Pdf.Facades.PdfContentEditorAspose.Pdf.FileEncodingAspose.Pdf.FileSpecificationAspose.Pdf.FileSpecification.ParamsAspose.Pdf.FileSpecificationParamsPdfContentEditor.AddDocumentAttachmentPdfContentEditor.BindPdfPdfContentEditor.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 -->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
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.

