Class PdfAttachmentCollection
- Namespace
- Syncfusion.Pdf.Interactive
- Assembly
- Syncfusion.Pdf.Portable.dll
Represents a collection of the attachment objects.
public class PdfAttachmentCollection : PdfCollection, IEnumerable
- Inheritance
-
PdfAttachmentCollection
- Implements
- Inherited Members
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Create an attachment.
PdfAttachment attachment = new PdfAttachment("Input.txt");
attachment.Description = "Input.txt";
attachment.MimeType = "application/txt";
//Add the attachment to the document.
document.Attachments.Add(attachment);
//Save and close the PDF document.
document.Save("Output.pdf");
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Create an attachment.
Dim attachment As New PdfAttachment("Input.txt")
attachment.Description = "Input.txt"
attachment.MimeType = "application/txt"
'Add the attachment to the document.
document.Attachments.Add(attachment)
'Save and close the PDF document.
document.Save("Output.pdf")
document.Close(True)
Constructors
PdfAttachmentCollection()
Initializes a new instance of the PdfAttachmentCollection class.
public PdfAttachmentCollection()
- See Also
Properties
this[int]
public PdfAttachment this[int index] { get; }
Parameters
index
int
Property Value
- See Also
Methods
Add(PdfAttachment)
Add PdfAttachment in the specified attachment collection.
public int Add(PdfAttachment attachment)
Parameters
attachment
PdfAttachmentThe PdfAttachment which contains the file data.
Returns
- int
The position of the inserted attachment.
Examples
//Create a new PDF document
PdfDocument document = new PdfDocument();
//Create an attachment
PdfAttachment attachment = new PdfAttachment("Input.txt");
attachment.Description = "Input.txt";
attachment.MimeType = "application/txt";
//Add the attachment to the document
document.Attachments.Add(attachment);
//Save and close the PDF document
document.Save("Output.pdf");
document.Close(true);
'Create a new PDF document
Dim document As New PdfDocument()
'Create an attachment
Dim attachment As New PdfAttachment("Input.txt")
attachment.Description = "Input.txt"
attachment.MimeType = "application/txt"
'Add the attachment to the document
document.Attachments.Add(attachment)
'Save and close the PDF document
document.Save("Output.pdf")
document.Close(True)
- See Also
Clear()
Remove all the attachments from the collection.
public void Clear()
Examples
//Load the PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
//Get the attachments
PdfAttachmentCollection attachments = loadedDocument.Attachments;
//Remove all the bookmarks form the collection
attachments.Clear();
//Save and close the PDF document
loadedDocument.Save("Output.pdf");
loadedDocument.Close(true);
'Load the PDF document
Dim loadedDocument As New PdfLoadedDocument("Input.pdf")
'Get the attachments
Dim attachments As PdfAttachmentCollection = loadedDocument.Attachments
'Remove all the bookmarks form the collection
attachments.Clear()
'Save and close the document
loadedDocument.Save("Output.pdf")
loadedDocument.Close(True)
- See Also
Contains(PdfAttachment)
Determines whether the attachment collection contains the specified attachment.
public bool Contains(PdfAttachment attachment)
Parameters
attachment
PdfAttachmentThe attachment to be searched.
Returns
- bool
if it contains the specified attachment, set to
true
. otherwisefalse
Examples
//Create a new PDF document
PdfDocument document = new PdfDocument();
//Create an attachment
PdfAttachment attachment = new PdfAttachment("Input.txt");
attachment.Description = "Input.txt";
attachment.MimeType = "application/txt";
//Add the attachment to the document
document.Attachments.Add(attachment);
//check the collection contains the specified attachment.
bool isAttachmentContained = document.Attachments.Contains(attachment);
//Save and close the PDF document
document.Save("Output.pdf");
document.Close(true);
'Create a new PDF document
Dim document As New PdfDocument()
'Create an attachment
Dim attachment As New PdfAttachment("Input.txt")
attachment.Description = "Input.txt"
attachment.MimeType = "application/txt"
'Add the attachment to the document
document.Attachments.Add(attachment)
'check the collection contains the specified attachment.
Dim isAttachmentContained As Boolean = document.Attachments.Contains(attachment)
'Save and close the PDF document
document.Save("Output.pdf")
document.Close(True)
- See Also
IndexOf(PdfAttachment)
search and find the index of the attachment.
public int IndexOf(PdfAttachment attachment)
Parameters
attachment
PdfAttachmentThe attachment to find the position.
Returns
- int
The index of the specified attachment.
Examples
//Create a new PDF document
PdfDocument document = new PdfDocument();
//Create an attachment
PdfAttachment attachment = new PdfAttachment("Input.txt");
attachment.Description = "Input.txt";
attachment.MimeType = "application/txt";
//Add the attachment to the document
document.Attachments.Add(attachment);
//Get the index of attachment
int index = document.Attachments.IndexOf(attachment);
//Save and close the PDF document
document.Save("Output.pdf");
document.Close(true);
'Create a new PDF document
Dim document As New PdfDocument()
'Create an attachment
Dim attachment As New PdfAttachment("Input.txt")
attachment.Description = "Input.txt"
attachment.MimeType = "application/txt"
'Add the attachment to the document
document.Attachments.Add(attachment)
'Get the index of attachment
Dim index As Integer = document.Attachments.IndexOf(attachment)
'Save and close the PDF document
document.Save("Output.pdf")
document.Close(True)
- See Also
Insert(int, PdfAttachment)
Inserts the attachment at specified index.
public void Insert(int index, PdfAttachment attachment)
Parameters
index
intThe index at which attachment to be inserted.
attachment
PdfAttachmentThe attachment to be inserted.
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Create an attachment.
PdfAttachment attachment = new PdfAttachment("Input.txt");
attachment.Description = "Input.txt";
attachment.MimeType = "application/txt";
//insert the attachment at specified index.
document.Attachments.Insert(0, attachment);
//Save and close the PDF document.
document.Save("Output.pdf");
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Create an attachment.
Dim attachment As New PdfAttachment("Input.txt")
attachment.Description = "Input.txt"
attachment.MimeType = "application/txt"
'insert the attachment at specified index.
document.Attachments.Insert(0, attachment)
'Save and close the PDF document.
document.Save("Output.pdf")
document.Close(True)
- See Also
Remove(PdfAttachment)
Removes the specified attachment from the collection.
public void Remove(PdfAttachment attachment)
Parameters
attachment
PdfAttachmentThe attachment to be removed.
Examples
//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
//Load an attachment collection.
PdfAttachmentCollection attachments = loadedDocument.Attachments;
//Get the attachment at the specified index.
PdfAttachment attachment = loadedDocument.Attachments[0];
//Remove attachment by attachment name.
attachments.Remove(attachment);
//Save and close the document.
loadedDocument.Save("Output.pdf");
loadedDocument.Close(true);
'Load the PDF document.
Dim loadedDocument As New PdfLoadedDocument("Input.pdf")
'Load an attachment collection.
Dim attachments As PdfAttachmentCollection = loadedDocument.Attachments
'Get the attachment at the specified index.
attachment As PdfAttachment = loadedDocument.Attachments(0)
'Remove attachment by attachment name.
attachments.Remove(attachment)
'Save and close the document.
loadedDocument.Save("Output.pdf")
loadedDocument.Close(True)
- See Also
RemoveAt(int)
Removes attachment at the specified index.
public void RemoveAt(int index)
Parameters
index
intThe index at which the attachment to be removed.
Examples
//Load the PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
//Load an attachment collection
PdfAttachmentCollection attachments = loadedDocument.Attachments;
//Remove attachment by index
attachments.RemoveAt(0);
//Save and close the document
loadedDocument.Save("Output.pdf");
loadedDocument.Close(true);
'Load the PDF document
Dim loadedDocument As New PdfLoadedDocument("Input.pdf")
'Load an attachment collection
Dim attachments As PdfAttachmentCollection = loadedDocument.Attachments
'Remove attachment by index
attachments.RemoveAt(0)
'Save and close the document
loadedDocument.Save("Output.pdf")
loadedDocument.Close(True)
- See Also