AddEmbeddedFile

Document properties

Description

Embeds a file inside the PDF as an embedded file stream but does not, by itself, register the file in any catalog list or draw a clickable annotation. The function returns an EmbeddedFileID handle that can be passed to AddFileAttachment (to attach a paper-clip icon on a page) or AddLinkToEmbeddedFile (to create a clickable hotspot that opens the file). To both embed a file and list it as a document-level attachment in a single call, use EmbedFile instead.

Syntax

Delphi

Function TPDFlib.AddEmbeddedFile(Const FileName, MIMEType: WideString): Integer;

ActiveX

Function PDFlib::AddEmbeddedFile(FileName As String, MIMEType As String) As Long

DLL

int DLAddEmbeddedFile(int InstanceID, const wchar_t * FileName, const wchar_t * MIMEType);

Parameters

FileNameThe full path and name of the source file on disk. Its bytes are copied verbatim into a PDF embedded file stream.
MIMETypeThe MIME type of the file, for example image/jpeg or application/xml. May be an empty string when the MIME type is unknown.

Return values

0The file could not be opened or no document is active.
Non-zeroAn EmbeddedFileID handle for use with AddFileAttachment, AddLinkToEmbeddedFile, or SetEmbeddedFileStrProperty.

Remarks

PDF version behavior: embedded file streams and file specification dictionaries require PDF 1.3. If the current document version is lower and the save version is not locked, AddEmbeddedFile automatically raises the document to PDF 1.3. Calls that register the file as a document-level attachment can require a higher version: AddFileAttachment and EmbedFile use the PDF 1.4 /Names /EmbeddedFiles name tree, and AddLinkToEmbeddedFile uses PDF 1.4 annotation opacity/appearance transparency.

Yalnızca AddEmbeddedFile ile gömülen bir dosya PDF'in bir parçasıdır ancak belge eki listesine kaydedilene veya bir sayfa ek açıklaması tarafından başvurulana kadar okuyucu arayüzünde görünmez; aynı EmbeddedFileID'yi AddFileAttachment ve AddLinkToEmbeddedFile ile yeniden kullanmak, gömülü baytları çoğaltmadan tek bir gömülü dosyayı hem belge düzeyindeki hem de sayfa düzeyindeki arayüz aracılığıyla sunmanıza olanak tanır

PDF/A compatibility:

Example

// Expose the same embedded file through the document attachment list and a page annotation
var
  FileID: Integer;
begin
  PDF.NewDocument;
  PDF.AddStandardFont('Helvetica');

  FileID := PDF.AddEmbeddedFile('C:\reports\sales.csv', 'text/csv');
  if FileID = 0 then Exit;

  PDF.AddFileAttachment('Source data', FileID);

  PDF.AddPage;
  PDF.PrintText(50, 750, 'See attached source data');
  PDF.AddLinkToEmbeddedFile(50, 720, 16, 16, FileID, 'Source data', 'Open source CSV', 4, 0);

  PDF.SaveToFile('with-attachment.pdf');
end;

See also

AddFileAttachment, AddLinkToEmbeddedFile, EmbedFile, SetEmbeddedFileAFRelationship, SetEmbeddedFileStrProperty, EmbeddedFileCount