وثائق PDFiumVCL

AttachmentName property

يحافظ إدخال API هذا على المعرّفات والتواقيع وكتل الكود ومصطلحات PDF بصيغتها الأصلية.
Component: TPdf  ·  Unit: PDFium
Returns the Unicode file name registered for the embedded file at the given zero-based index in the document EmbeddedFiles name tree.

Syntax

property AttachmentName[Index: Integer]: WString; // read only

Description

Every PDF file attachment carries an associated file name in its file specification dictionary — typically the original file name as it appeared on the author's disk (for example contract.docx or source-data.csv). AttachmentName exposes that name as a WString so it can be displayed in a UI, used as a suggested save-as path, or matched by extension.

The returned string is decoded from the PDF's UTF-16BE or PDFDocEncoding storage so non-ASCII names (Chinese, Cyrillic, accented Latin) round-trip correctly. Where the original author left only a key entry without an explicit /F or /UF filename, an empty string is returned.

The property is read-only. Renaming an attachment is not exposed by this API; if you need to change a filename, delete the slot with DeleteAttachment and recreate it with CreateAttachment, then re-assign the bytes through Attachment.

Parameters

IndexInteger. Zero-based attachment position. Must be in [0, AttachmentCount - 1]. Passing an out-of-range index returns an empty string.

Remarks

Example

var
  I: Integer;
  FileName: string;
begin
  Pdf1.LoadFromFile('package.pdf');
  ListBox1.Items.BeginUpdate;
  try
    ListBox1.Items.Clear;
    for I := 0 to Pdf1.AttachmentCount - 1 do
    begin
      FileName := Pdf1.AttachmentName[I];
      if FileName = '' then
        FileName := Format('(unnamed #%d)', [I]);
      ListBox1.Items.AddObject(FileName, TObject(I));
    end;
  finally
    ListBox1.Items.EndUpdate;
  end;
end;

See Also

Attachment, AttachmentCount, AttachmentType, CreateAttachment, DeleteAttachment