PDFium Component Docs

Attachment property

Component: TPdf  ·  Unit: PDFium
Membaca atau mengganti payload byte mentah dari file tersemat tingkat dokumen pada indeks berbasis nol yang ditentukan. Setiap slot sesuai dengan satu entri dalam name tree EmbeddedFiles PDF yang didefinisikan pada section 7.11 spesifikasi PDF 1.7

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. PDFiumPas 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