Docs PDFiumPas

Attachment Propriété

Cette entrée API conserve identifiants, signatures, blocs de code et termes PDF dans leur forme d’origine.
Composant: TPdf  ·  Unité: PDFium
Lit ou remplace la charge utile brute en octets du fichier intégré au niveau du document à l’index indexé à partir de zéro indiqué. Chaque emplacement correspond à une entrée de l’arbre de noms EmbeddedFiles PDF défini à la section 7.11 de la spécification PDF 1.7

Syntaxe

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] renvoie le contenu en octets décodé du fichier attaché sous la forme d’un 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 en premier si vous devez ajouter une nouvelle entrée. Les écritures sont tamponnées en mémoire et ne deviennent persistantes qu’après l’enregistrement du document avec SaveAs.

Paramètres

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.

Remarques

Exemple

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;

Voir aussi

AttachmentCount, AttachmentName, AttachmentType, CreateAttachment, DeleteAttachment