function GetAttachmentDictionaryValue(Index: Integer; const Key: WString): TPdfDictionaryValue;
| Index | Integer. Zero-based index of the embedded attachment, in the range 0 .. AttachmentCount - 1. An out-of-range index raises an EPdfError |
| Key | WString. Name of the entry to read from the attachment's file specification dictionary, for example a custom key written by a producing application |
| Result | TPdfDictionaryValue. Kind always carries the native value type; for pdvkString and pdvkName values StringValue is filled and HasScalarValue is True |
Every entry of the EmbeddedFiles tree is a PDF file specification dictionary, and that dictionary is where the private metadata of an attachment lives. This call probes one key of that dictionary and returns a TPdfDictionaryValue: the value kind is decoded from the native type query, and when the entry holds a string or a name, the text is read and returned in StringValue with HasScalarValue set
Values of other kinds — numbers, booleans, arrays, nested dictionaries, streams — are reported by Kind alone; HasScalarValue stays False because only string and name entries are decoded. Use AttachmentHasKey first to test whether a key exists at all
The call requires a loaded document and a valid attachment index. Use GetAttachmentStringValue when the plain text of a string entry is enough and the kind does not matter, and SetAttachmentStringValue to write a string entry back
Kind of a missing key resolves to pdvkUnknown; treat that together with HasScalarValue = False as “no value”Desc and DESC are different entries
var
Value: TPdfDictionaryValue;
begin
if Pdf1.AttachmentHasKey(0, 'SourceApp') then
begin
Value := Pdf1.GetAttachmentDictionaryValue(0, 'SourceApp');
if Value.HasScalarValue then
Memo1.Lines.Add('Source: ' + Value.StringValue);
end;
end;