property AttachmentCount: Integer; // read only
AttachmentCount enumerates embedded file streams reachable through the catalogue
/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. PDFium Delphi Component 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
Only the /EmbeddedFiles name tree is enumerated. A PDF 2.0
associated file (ISO 32000-2 §7.11.4) referenced solely from an
/AF array — on the catalogue, a page, an annotation or any other
object — and not also registered in the name tree is neither counted nor
given an index for Attachment, AttachmentName or
AttachmentRelationship. This includes files written by
SaveAsWithAssociateFiles, which
adds /AF entries only. Most PDF/A-3 producers, including Factur-X and
ZUGFeRD tools, register each associated file in both places, so those files are
listed normally
FeatureSupported(feAttachment) to detect whether the
installed PDFium build supports modifying attachment names
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;