Class Attachment
Represents a file attachment with its content, name, MIME type, and size.
Supported Formats: PNG, BMP, GIF, PSD, PIC, JPEG, PNM, HDR, TGA, WEBP, TIFF, TXT, HTML, PDF, DOCX, XLSX, PPTX.
public sealed class Attachment : IDisposable
- Inheritance
-
Attachment
- Implements
- Inherited Members
Remarks
The Attachment class provides multiple ways to create instances:
Constructors (synchronous):
- Attachment(string) - from file path
- Attachment(byte[], string) - from byte array
- Attachment(Stream, string) - from stream
- Attachment(ImageBuffer, bool, string) - from image buffer
- Attachment(Uri, AttachmentDownloadingProgressCallback) - from URI
Factory methods (synchronous):
- CreateFromBase64String(string, string) - from base64-encoded string
- CreateFromText(string, string) - from plain text
Factory methods (asynchronous):
Constructors
- Attachment(ImageBuffer, bool, string)
Initializes a new Attachment from an in-memory image buffer.
- Attachment(byte[], string)
Initializes a new instance of the Attachment class with the provided data and name. The data must represent one of the supported formats:
- PNG
- BMP
- GIF
- PSD
- PIC
- JPEG
- PNM
- HDR
- TGA
- WEBP
- TIFF
- HTML
- TXT
- DOCX
- XLSX
- PPTX
- Attachment(Stream, string)
Initializes a new instance of the Attachment class by reading the content from the provided stream and using the given file name. The stream must contain data representing one of the supported formats:
- PNG
- BMP
- GIF
- PSD
- PIC
- JPEG
- PNM
- HDR
- TGA
- WEBP
- TIFF
- HTML
- TXT
- DOCX
- XLSX
- PPTX
- Attachment(string)
Initializes a new instance of the Attachment class by loading the content from the specified file path. The file must be one of the supported formats:
- PNG
- BMP
- GIF
- PSD
- PIC
- JPEG
- PNM
- HDR
- TGA
- WEBP
- TIFF
- HTML
- TXT
- DOCX
- XLSX
- PPTX
- Attachment(Uri, AttachmentDownloadingProgressCallback)
Initializes a new instance of the Attachment class by loading content from the specified URI.
Properties
- HasText
Gets a value indicating whether the attachment contains extractable text.
- Id
Gets the unique identifier for this attachment instance.
- IsVisionRequired
Gets a value indicating whether vision processing (e.g., image analysis or OCR) is required to interpret the attachment.
- Length
Gets the length of the attachment content in bytes.
- Mime
Gets the MIME type of the attachment.
- Name
Gets the name of the attachment file.
- PageCount
Gets the number of pages represented by this attachment.
- PageElements
Gets the sequence of page-level text elements extracted from the attachment.
- Path
Gets the full file-system path from which this attachment was loaded.
Methods
- CreateFromBase64String(string, string)
Creates a new Attachment instance from a base64-encoded string.
- CreateFromFileAsync(string, CancellationToken)
Creates a new Attachment instance asynchronously by loading content from the specified file path.
- CreateFromStreamAsync(Stream, string, CancellationToken)
Creates a new Attachment instance asynchronously by reading content from the provided stream.
- CreateFromText(string, string)
Creates a new Attachment from a plain-text string.
- CreateFromUriAsync(Uri, AttachmentDownloadingProgressCallback, CancellationToken)
Creates a new Attachment instance asynchronously by loading content from the specified URI.
- DetectMimeType(byte[], string)
Detects the MIME type of the provided byte array, using only the formats supported by the toolkit.
- DetectMimeType(string)
Detects the MIME type of the file at the specified path, using only the formats supported by the toolkit.
- Dispose()
Releases resources used by this instance.
- GetPageHeight(int)
Gets the height of the specified page.
- GetPageText(int, TextOutputMode, CancellationToken)
Gets the textual content of the specified page, formatted with the given
mode.
- GetPageText(int, CancellationToken)
Gets the textual content of the specified page.
- GetPageTextAsync(int, TextOutputMode, CancellationToken)
Asynchronously gets the textual content of the specified page, formatted with the given
mode.
- GetPageTextAsync(int, CancellationToken)
Asynchronously gets the textual content of the specified page.
- GetPageWidth(int)
Gets the width of the specified page.
- GetText(TextOutputMode, string, CancellationToken)
Extracts and returns the textual content from the specified pages, formatted with the given
mode.
- GetText(TextOutputMode, CancellationToken)
Extracts and returns the textual content using the specified layout aggregation
mode.
- GetText(string, CancellationToken)
Extracts and returns the textual content from the specified pages of the attachment.
- GetText(CancellationToken)
Extracts and returns the textual content from the attachment.
- GetTextAsync(TextOutputMode, string, CancellationToken)
Asynchronously extracts and returns the textual content from the specified pages, formatted with the given
mode.
- GetTextAsync(TextOutputMode, CancellationToken)
Asynchronously extracts and returns the textual content formatted with the given
mode.
- GetTextAsync(string, CancellationToken)
Asynchronously extracts and returns the textual content from the specified pages of the attachment.
- GetTextAsync(CancellationToken)
Asynchronously extracts and returns the textual content from the attachment.
- HasTextOnPage(int, CancellationToken)
Determines whether the specified page contains extractable text.
- HasTextOnPageAsync(int, CancellationToken)
Asynchronously determines whether the specified page contains extractable text.
- SetText(PageElement)
Attaches a textual representation to the attachment from a PageElement structure, overriding any previously set text elements.
- SetText(PageElement, int)
Attaches a textual representation to a specific page of the attachment, overriding any previously set text for that page.
- SetText(string)
Attaches a textual representation to the attachment, replacing any previously extracted text.
- SetText(string, int)
Attaches a textual representation to a specific page of the attachment, overriding any previously set text for that page.
- ToString()
Returns the textual content of the attachment.