function ReadAttachmentMetadata(MaxAttachments: Integer = 10000): TPdfAttachmentMetadataArray;
The method enumerates document-level attachments once and returns caller-owned records containing Index, Name, Description, MimeType, Relationship, decoded Size, and Readable
MaxAttachments is checked before the result array is populated, preventing an untrusted document from causing an unbounded metadata allocation
The size query does not copy payload bytes into PDFium Delphi Component memory, although PDFium may decode a stream internally to determine its decoded length
function ExtractAttachmentsToStreams(const Destinations: array of TStream; const Options: TPdfAttachmentBatchOptions; out Report: TPdfAttachmentBatchReport; const CancellationToken: IPdfCancellationToken = nil): Boolean;
Destinations must contain exactly one slot per document attachment and follows the same zero-based order as Attachment[Index]
A nil destination marks that item as paesSkipped, allowing callers to select attachments without a second enumeration
Each non-empty payload is decoded through PDFium into one temporary PDFium Delphi Component buffer and then written from that buffer in ChunkBytes pieces
The buffer is released before the next attachment, so PDFium Delphi Component never retains the whole batch, but the public PDFium attachment API does not support range reads and may use its own full-payload decode memory internally
Streams remain owned by the caller, writing begins at each current stream position, and the method does not rewind or truncate them
Cancellation or a destination exception can leave bytes already written to that stream, so callers that require transactional output should supply temporary streams and publish them only after a successful report
| Field | Default | Meaning |
|---|---|---|
MaxAttachments | 10000 | Maximum metadata and report entries |
MaxFileBytes | 256 MiB | Maximum decoded size of one attachment |
MaxTotalBytes | 1 GiB | Maximum bytes written across all destinations |
ChunkBytes | 1 MiB | Maximum bytes passed to one stream write |
StopOnError | True | Stop after the first unreadable, over-budget, or write-failed item |
Each TPdfAttachmentMetadata record describes one native attachment and TPdfAttachmentMetadataArray stores the metadata snapshot
Each TPdfAttachmentBatchItem combines metadata, a TPdfAttachmentExtractionState, bytes written, and any error text, while TPdfAttachmentBatchItems stores all per-item results
TPdfAttachmentExtractionState values are paesNotProcessed, paesSkipped, paesExtracted, paesUnreadable, paesFileLimit, paesAggregateLimit, paesCancelled, and paesWriteFailed
The TPdfAttachmentBatchReport counts AttachmentCount, ExtractedCount, SkippedCount, and FailedCount alongside BytesWritten and PeakBufferBytes
Completed means every item reached a terminal state without cancellation, while the function result additionally requires FailedCount = 0
PeakBufferBytes reports the largest PDFium Delphi Component payload buffer and does not include private memory used by PDFium during decode
var Options: TPdfAttachmentBatchOptions;
var Report: TPdfAttachmentBatchReport;
Options := TPdfAttachmentBatchOptions.Default;
Options.MaxFileBytes := 64 * 1024 * 1024;
Options.MaxTotalBytes := 256 * 1024 * 1024;
if not Pdf1.ExtractAttachmentsToStreams(Destinations, Options, Report) then
HandleAttachmentBatchFailure(Report);