Документация PDFiumVCL

AttachmentCount property

Эта запись API сохраняет идентификаторы, сигнатуры, блоки кода и термины PDF в исходном виде.
Component: TPdf  ·  Unit: PDFium
Number of embedded file attachments declared in the document.

Syntax

property AttachmentCount: Integer; // read only

Description

AttachmentCount enumerates embedded file streams reachable through the catalog /Names /EmbeddedFiles name tree (PDF 1.7 spec section 7.11). These are arbitrary files (XML, spreadsheets, source CAD, signed XML, ZIP archives,…) packaged inside the PDF and exposed by viewers as the “Attachments” sidebar. PDF/A-3 specifically requires every relevant source artefact to be embedded this way for long-term reproducibility.

The value is 0 when Active is False and when the document carries no embedded files. File-attachment annotations (subtype /FileAttachment) are not counted here — those are page-level annotations and surface through AnnotationCount instead. PDFiumVCL exposes embedded streams as TBytes via Attachment[Index]; the human-readable file name and MIME-style type are available through AttachmentName[Index] and AttachmentType[Index].

The typical loop is for I := 0 to Pdf.AttachmentCount - 1 do. Each Attachment[I] access decompresses the embedded file stream into memory, so cache the TBytes if you need to write it to disk and pass it to a parser. Adding or removing an attachment invalidates indices — re-read AttachmentCount after a mutation.

Remarks

Example

var I: Integer;
var Data: TBytes;
for I := 0 to Pdf1.AttachmentCount - 1 do
begin
  Data := Pdf1.Attachment[I];
  TFile.WriteAllBytes(Pdf1.AttachmentName[I], Data);
end;

See Also

Attachment, AttachmentName, AttachmentType, AnnotationCount