PDFiumVCL 文档

Attachment property

此 API 条目保留标识符、签名、代码块和 PDF 术语的原始形式。
Component: TPdf  ·  Unit: PDFium
Reads or replaces the raw byte payload of the document-level embedded file at the specified zero-based index. Each slot corresponds to one entry in the PDF EmbeddedFiles name tree defined in section 7.11 of the PDF 1.7 specification.

Syntax

property Attachment[Index: Integer]: TBytes;

Description

PDF documents can carry arbitrary auxiliary files (source spreadsheets, original Word documents, attached invoices, signed XML payloads, ZIP bundles, even other PDFs) inside a document-level container called the EmbeddedFiles name tree. Each entry is a PDF file specification dictionary whose stream holds the actual bytes of the attached file. PDFiumVCL exposes that tree as a flat 0-based index from 0 to AttachmentCount - 1.

Reading Attachment[Index] returns the decoded byte content of the attached file as a TBytes array — exactly the bytes any other PDF reader would extract when the user clicks the paperclip icon and saves the attachment. The returned bytes are already decompressed; you can write them straight to disk, push them to a stream, or feed them back into another TPdf instance if the attachment is itself a PDF.

Writing replaces the file stream of an existing attachment slot in place. The slot must already exist; use CreateAttachment first if you need to add a new entry. Writes are buffered in memory and only become persistent after the document is saved with SaveAs.

Parameters

IndexInteger. Zero-based position in the EmbeddedFiles name tree. Must satisfy 0 <= Index < AttachmentCount. Indexes match those reported by AttachmentName and AttachmentType, so iterating 0..AttachmentCount - 1 visits each attachment exactly once.

Remarks

Example

var
  I: Integer;
  Data: TBytes;
  OutPath: string;
begin
  Pdf1.LoadFromFile('with-attachments.pdf');
  for I := 0 to Pdf1.AttachmentCount - 1 do
  begin
    Data := Pdf1.Attachment[I];
    OutPath := 'extracted\' + Pdf1.AttachmentName[I];
    TFile.WriteAllBytes(OutPath, Data);
    Memo1.Lines.Add(Format('%s (%s, %d bytes)',
      [Pdf1.AttachmentName[I], Pdf1.AttachmentType[I], Length(Data)]));
  end;
end;

See Also

AttachmentCount, AttachmentName, AttachmentType, CreateAttachment, DeleteAttachment