GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / EmbedFile Method / EmbedFile(Stream,String,String) Method
The stream that contains file data to embed. This stream object must be initialized before it can be sent into this method and it should remain open for subsequent use.

Any kind of file data, and any numbers of files, can be embedded into a PDF file.

The file title to use for the embedded file data.
The verbal description of this attachment, for example, a purpose of embedding this file.
Example





In This Topic
EmbedFile(Stream,String,String) Method
In This Topic
Embeds (attaches) a file data from a previously instantiated Stream object into the currently loaded PDF document under the provided file title. You can also add a verbal description of this attachment. The file data is embedded (attached) into the source PDF file and can be displayed in a special viewer panel in most PDF viewers.
Syntax
'Declaration
 
Public Overloads Function EmbedFile( _
   ByVal Stream As Stream, _
   ByVal FileTitle As String, _
   ByVal Description As String _
) As GdPictureStatus
public GdPictureStatus EmbedFile( 
   Stream Stream,
   string FileTitle,
   string Description
)
public function EmbedFile( 
    Stream: Stream;
    FileTitle: String;
    Description: String
): GdPictureStatus; 
public function EmbedFile( 
   Stream : Stream,
   FileTitle : String,
   Description : String
) : GdPictureStatus;
public: GdPictureStatus EmbedFile( 
   Stream* Stream,
   string* FileTitle,
   string* Description
) 
public:
GdPictureStatus EmbedFile( 
   Stream^ Stream,
   String^ FileTitle,
   String^ Description
) 

Parameters

Stream
The stream that contains file data to embed. This stream object must be initialized before it can be sent into this method and it should remain open for subsequent use.

Any kind of file data, and any numbers of files, can be embedded into a PDF file.

FileTitle
The file title to use for the embedded file data.
Description
The verbal description of this attachment, for example, a purpose of embedding this file.

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. Also be aware that the provided stream should remain open and can only be closed/disposed of by the user.

You also need to be aware that embedded files are forbidden in PDF/A-1. But PDF/A-2 allows embedding of PDF/A files, facilitating the archiving of sets of PDF/A documents in a single file. PDF/A-3 allows embedding of any file format such as XML, CAD and others into PDF/A documents.

Example
Embedding a text file into the PDF document using stream.
Using (gdpicturePDF As GdPicturePDF = New GdPicturePDF())
    gdpicturePDF.LoadFromFile("document.pdf", True)
    FileStream attachment = new FileStream("textfile.txt", FileMode.Open)
    gdpicturePDF.EmbedFile(attachment, "textfile.txt", "Text Attachment")
    gdpicturePDF.SaveToFile("document.pdf")
    attachment.Close()
    attachment.Dispose()
End Using
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
    gdpicturePDF.LoadFromFile("document.pdf", true);
    FileStream attachment = new FileStream("textfile.txt", FileMode.Open);
    gdpicturePDF.EmbedFile(attachment, "textfile.txt", "Text Attachment");
    gdpicturePDF.SaveToFile("document.pdf");
    attachment.Close();
    attachment.Dispose();
}
See Also