GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / GetFileAttachmentAnnotEmbeddedFile Method
The 0-based index of the required annotation within the current page. It must be a value from 0 to GetAnnotationCount-1.
Output parameter. An array of bytes containing the data of the embedded file associated with the specified annotation.
Example





In This Topic
GetFileAttachmentAnnotEmbeddedFile Method (GdPicturePDF)
In This Topic
Gets the content of the embedded (attached) file associated with the specified annotation related to the currently selected page of the loaded PDF document. You need to identify the annotation object by its 0-based index, that is always related to the currently selected page.

Be aware that PDF documents can also contain embedded files as a whole. Such files are called File Attachments and they are attached directly to a PDF document. You can refer to our examples how to extract embedded files in both ways.

Syntax
'Declaration
 
Public Function GetFileAttachmentAnnotEmbeddedFile( _
   ByVal AnnotationIdx As Integer, _
   ByRef Data() As Byte _
) As GdPictureStatus
public GdPictureStatus GetFileAttachmentAnnotEmbeddedFile( 
   int AnnotationIdx,
   ref byte[] Data
)
public function GetFileAttachmentAnnotEmbeddedFile( 
    AnnotationIdx: Integer;
   var  Data: Bytearray of
): GdPictureStatus; 
public function GetFileAttachmentAnnotEmbeddedFile( 
   AnnotationIdx : int,
   Data : byte[]
) : GdPictureStatus;
public: GdPictureStatus GetFileAttachmentAnnotEmbeddedFile( 
   int AnnotationIdx,
   ref byte[]* Data
) 
public:
GdPictureStatus GetFileAttachmentAnnotEmbeddedFile( 
   int AnnotationIdx,
   array<byte>^% Data
) 

Parameters

AnnotationIdx
The 0-based index of the required annotation within the current page. It must be a value from 0 to GetAnnotationCount-1.
Data
Output parameter. An array of bytes containing the data of the embedded file associated with the specified annotation.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

We strongly recommend always checking this status first.

Remarks
This method is only allowed for use with non-encrypted documents.

Please always ensure that you have selected the correct page using the SelectPage method before applying an annotation index.

Example
How to retrieve all files associated with all file attachment annotations in the loaded PDF document.
Dim caption As String = "Example: GetFileAttachmentAnnotEmbeddedFile"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
    Dim pageCount As Integer = gdpicturePDF.GetPageCount()
    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
        Dim message As String = ""
        Dim status As GdPictureStatus = GdPictureStatus.OK
        For page As Integer = 1 To pageCount
            message = message + "Page nr." + page.ToString()
            status = gdpicturePDF.SelectPage(page)
            If status = GdPictureStatus.OK Then
                Dim annotCount As Integer = gdpicturePDF.GetAnnotationCount()
                status = gdpicturePDF.GetStat()
                If status = GdPictureStatus.OK Then
                    Dim subtype As String = ""
                    For annotID As Integer = 0 To annotCount - 1
                        subtype = gdpicturePDF.GetAnnotationSubType(annotID)
                        status = gdpicturePDF.GetStat()
                        If (status = GdPictureStatus.OK) AndAlso (subtype.Equals("FileAttachment")) Then
                            message = message + vbCrLf + "AnnotID: " + annotID.ToString()
                            Dim filedata As Byte() = Nothing
                            Dim filesize As Integer = 0
                            Dim fileDesc As String = "", crDate As String = "", modDate As String = ""
                            Dim filename As String = gdpicturePDF.GetFileAttachmentAnnotFileName(annotID)
                            status = gdpicturePDF.GetStat()
                            If status = GdPictureStatus.OK Then filesize = gdpicturePDF.GetFileAttachmentAnnotFileSize(annotID) Else status = gdpicturePDF.GetStat()
                            If status = GdPictureStatus.OK Then fileDesc = gdpicturePDF.GetFileAttachmentAnnotFileDescription(annotID) Else status = gdpicturePDF.GetStat()
                            If status = GdPictureStatus.OK Then crDate = gdpicturePDF.GetFileAttachmentAnnotCreationDate(annotID) Else status = gdpicturePDF.GetStat()
                            If status = GdPictureStatus.OK Then modDate = gdpicturePDF.GetFileAttachmentAnnotModificationDate(annotID) Else status = gdpicturePDF.GetStat()
                            If status = GdPictureStatus.OK Then status = gdpicturePDF.GetFileAttachmentAnnotEmbeddedFile(annotID, filedata) Else status = gdpicturePDF.GetStat()
                            If status = GdPictureStatus.OK Then
                                Using file As System.IO.Stream = System.IO.File.OpenWrite(filename)
                                    file.Write(filedata, 0, filesize)
                                End Using
                                message = message + "  file: " + filename + "  desc: " + fileDesc + "  size: " + filesize.ToString() +
                                          "  creation: " + crDate + "  modif: " + modDate
                            End If
                        End If
                        message = message + "  status: " + status.ToString()
                    Next
                Else
                    message = message + "GetAnnotationCount - status: " + status.ToString()
                End If
            Else
                message = message + "SelectPage - status: " + status.ToString()
            End If
            message += vbCrLf
        Next
        MessageBox.Show(message, caption)
    Else
        MessageBox.Show("The GetPageCount() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
    End If
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetFileAttachmentAnnotEmbeddedFile";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
    int pageCount = gdpicturePDF.GetPageCount();
    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
    {
        string message = "";
        GdPictureStatus status = GdPictureStatus.OK;
        for (int page = 1; page <= pageCount; page++)
        {
            message = message + "Page nr." + page.ToString();
            status = gdpicturePDF.SelectPage(page);
            if (status == GdPictureStatus.OK)
            {
                int annotCount = gdpicturePDF.GetAnnotationCount();
                status = gdpicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                {
                    string subtype = "";
                    for (int annotID = 0; annotID < annotCount; annotID++)
                    {
                        subtype = gdpicturePDF.GetAnnotationSubType(annotID);
                        status = gdpicturePDF.GetStat();
                        if ((status == GdPictureStatus.OK) && (subtype.Equals("FileAttachment")))
                        {
                            message = message + "\nAnnotID: " + annotID.ToString();
                            byte[] filedata = null;
                            int filesize = 0;
                            string fileDesc = "", crDate = "", modDate = "";
                            string filename = gdpicturePDF.GetFileAttachmentAnnotFileName(annotID);
                            status = gdpicturePDF.GetStat();
                            if (status == GdPictureStatus.OK) filesize = gdpicturePDF.GetFileAttachmentAnnotFileSize(annotID);
                            else status = gdpicturePDF.GetStat();
                            if (status == GdPictureStatus.OK) fileDesc = gdpicturePDF.GetFileAttachmentAnnotFileDescription(annotID);
                            else status = gdpicturePDF.GetStat();
                            if (status == GdPictureStatus.OK) crDate = gdpicturePDF.GetFileAttachmentAnnotCreationDate(annotID);
                            else status = gdpicturePDF.GetStat();
                            if (status == GdPictureStatus.OK) modDate = gdpicturePDF.GetFileAttachmentAnnotModificationDate(annotID);
                            else status = gdpicturePDF.GetStat();
                            if (status == GdPictureStatus.OK) status = gdpicturePDF.GetFileAttachmentAnnotEmbeddedFile(annotID, ref filedata);
                            else status = gdpicturePDF.GetStat();
                            if (status == GdPictureStatus.OK)
                            {
                                using (System.IO.Stream file = File.OpenWrite(filename))
                                {
                                    file.Write(filedata, 0, filesize);
                                }
                                message = message + "  file: " + filename + "  desc: " + fileDesc + "  size: " + filesize.ToString() +
                                          "  creation: " + crDate + "  modif: " + modDate;
                            }
                        }
                        message = message + "  status: " + status.ToString();
                    }
                }
                else
                    message = message + "GetAnnotationCount - status: " + status.ToString();
            }
            else
                message = message + "SelectPage - status: " + status.ToString();
            message += "\n";
        }
        MessageBox.Show(message, caption);
    }
    else
        MessageBox.Show("The GetPageCount() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
else
    MessageBox.Show("The file can't be loaded.", caption);
gdpicturePDF.Dispose();
See Also