PDFium Delphi Component Docs

GetAttachmentDictionaryValue method

Component: TPdf  ·  Unit: PDFium
Reads one key of the file specification dictionary of a document-level embedded attachment and reports the value kind together with the decoded string

Syntax

function GetAttachmentDictionaryValue(Index: Integer; const Key: WString): TPdfDictionaryValue;

IndexInteger. Zero-based index of the embedded attachment, in the range 0 .. AttachmentCount - 1. An out-of-range index raises an EPdfError
KeyWString. Name of the entry to read from the attachment's file specification dictionary, for example a custom key written by a producing application
ResultTPdfDictionaryValue. Kind always carries the native value type; for pdvkString and pdvkName values StringValue is filled and HasScalarValue is True

Description

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

Remarks

Example

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;

See Also

AttachmentHasKey, GetAttachmentStringValue, SetAttachmentStringValue, Attachment