PDFium Delphi Component Docs

ReadAttachmentMetadata method

Component: TPdf  ·  Unit: PDFium
Reads the metadata of the document-level embedded attachments in one pass, without extracting any payload bytes

Syntax

function ReadAttachmentMetadata(MaxAttachments: Integer = 10000): TPdfAttachmentMetadataArray;

MaxAttachmentsInteger. Upper bound on how many attachment entries are captured. Must be greater than zero, otherwise an EPdfError is raised. The default is 10000
ResultTPdfAttachmentMetadataArray. One TPdfAttachmentMetadata record per attachment: Index, Name, Description, MimeType, Relationship (the /AFRelationship name, empty when absent or when the export is missing), Size and Readable

Description

Enumerates the EmbeddedFiles tree of the loaded document in a single native pass and returns one TPdfAttachmentMetadata record per entry. Only descriptive values are read — the payload bytes stay in the file, so listing a document with many large attachments costs no payload memory

The Index field matches the zero-based index used by Attachment, AttachmentName and the other attachment indexers, so a listed entry can be extracted later through the same slot

Readable reports whether the native side could open the payload; Size (in bytes, as Int64) is filled only for readable entries. Unreadable entries still appear in the array so that indexes stay aligned with the document

The call runs under the render lock and requires the document to be loaded; a MaxAttachments of zero or less raises an EPdfError

Remarks

Example

var
  Meta: TPdfAttachmentMetadata;
begin
  Pdf1.FileName := 'with-attachments.pdf';
  Pdf1.Active := True;
  for Meta in Pdf1.ReadAttachmentMetadata do
    Memo1.Lines.Add(Format('%d: %s (%s, %d bytes, readable=%s)',
      [Meta.Index, Meta.Name, Meta.MimeType, Meta.Size,
        BoolToStr(Meta.Readable, True)]));
end;

See Also

ExtractAttachmentsToStreams, Attachment, AttachmentCount, AttachmentName