PDFium Component Docs

Attachment Egenskap

Denna API-post behåller identifierare, signaturer, kodblock och PDF-termer i ursprunglig form.
Komponent: TPdf  ·  Enhet: PDFium
Läser eller ersätter det råa byteinnehållet för den dokumentnivåinbäddade filen vid det angivna nollbaserade indexet. Varje plats motsvarar en post i PDF EmbeddedFiles-namnträdet som definieras i avsnitt 7.11 i PDF 1.7-specifikationen.

Syntax

property Attachment[Index: Integer]: TBytes;

Beskrivning

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] returnerar det avkodade byteinnehållet i den bifogade filen som en 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 först om du behöver lägga till en ny post. Skrivningar buffras i minnet och blir beständiga först när dokumentet sparas med SaveAs.

Parametrar

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.

Anmärkningar

Exempel

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;

Se även

AttachmentCount, AttachmentName, AttachmentType, CreateAttachment, DeleteAttachment