function ExtractAttachmentsToStreams(const Destinations: array of TStream; const Options: TPdfAttachmentBatchOptions; out Report: TPdfAttachmentBatchReport; const CancellationToken: IPdfCancellationToken = nil): Boolean;
| Destinations | TStream의 open array. 첨부 파일마다 하나의 스트림이며 문서 순서대로 대응합니다. nil 슬롯은 해당 첨부 파일을 아무것도 쓰지 않고 건너뜁니다. 스트림의 소유권은 호출자에게 있습니다 |
| Options | TPdfAttachmentBatchOptions. 일괄 처리 한도와 동작: MaxAttachments, MaxFileBytes, MaxTotalBytes, ChunkBytes, StopOnError. TPdfAttachmentBatchOptions.Default에서 시작하세요 |
| Report | TPdfAttachmentBatchReport. 반환 시 첨부 파일마다 하나의 항목(Metadata, State, BytesWritten, ErrorMessage)과 집계 카운터(AttachmentCount, ExtractedCount, SkippedCount, FailedCount, BytesWritten, PeakBufferBytes, Cancelled, Completed)를 담습니다 |
| CancellationToken | IPdfCancellationToken. 첨부 파일마다 그리고 쓰기 청크 사이에 확인되는 선택적 토큰이며, nil이면 취소 검사 없이 일괄 처리를 실행합니다 |
| Result | Boolean. 일괄 처리가 취소 없이 완료되고 실패한 첨부 파일이 0개일 때만 True입니다. 건너뛴 항목은 실패로 세지 않습니다 |
Attachment를 한 인덱스씩 읽는 것의 일괄 처리 버전입니다. 문서 첨부 파일을 한 번 담아 두고 각 페이로드를 디코딩해 대상 스트림에 밀어 넣으며, 모든 결과는 Report.Items에 첨부 파일별로 기록됩니다
대상 배열은 문서의 첨부 파일마다 정확히 하나의 스트림을 담아야 하며, 그렇지 않으면 바이트를 읽기 전에 EPdfError가 발생합니다. 배열의 nil 항목은 일괄 처리를 중단하는 대신 해당 첨부 파일을 건너뛴(paesSkipped) 것으로 표시합니다
옵션은 미리 검증되어 잘못된 경우 EPdfError를 발생시킵니다. MaxAttachments는 0보다 커야 하고, MaxFileBytes와 MaxTotalBytes는 음수일 수 없으며, ChunkBytes는 0보다 커야 합니다. TPdfAttachmentBatchOptions.Default는 첨부 파일 10000개, 파일당 256 MB, 전체 1 GB 한도, 1 MB 쓰기 청크, StopOnError = True를 제공합니다
각 첨부 파일은 TPdfAttachmentExtractionState 상태 중 하나로 끝납니다. 성공이면 paesExtracted, nil 대상이면 paesSkipped, 페이로드를 열거나 디코딩할 수 없으면 paesUnreadable, 크기 한도를 넘으면 paesFileLimit 또는 paesAggregateLimit, 대상 스트림이 예외를 일으키면 paesWriteFailed, 토큰이 발화하면 paesCancelled입니다. StopOnError가 설정되면 첫 번째 실패가 루프를 멈추고 나머지 항목은 paesNotProcessed로 남습니다
이 함수는 Report.Completed가 설정되고(취소 없음, 처리되지 않은 항목 없음) FailedCount가 0일 때만 True를 반환합니다. 취소 경로는 예외를 일으키는 대신 Report.Cancelled를 설정하고 False를 반환합니다
ChunkBytes는 그 버퍼를 스트림에 얼마나 잘게 밀어 넣을지 제어할 뿐 할당 크기가 아닙니다. Report.PeakBufferBytes가 사용된 최대 버퍼를 기록합니다
var
Options: TPdfAttachmentBatchOptions;
Report: TPdfAttachmentBatchReport;
Streams: array of TStream;
I: Integer;
begin
Pdf1.FileName := 'with-attachments.pdf';
Pdf1.Active := True;
SetLength(Streams, Pdf1.AttachmentCount);
for I := 0 to High(Streams) do
Streams[I] := TFileStream.Create('out\' + Pdf1.AttachmentName[I], fmCreate);
try
Options := TPdfAttachmentBatchOptions.Default;
Options.StopOnError := False;
if not Pdf1.ExtractAttachmentsToStreams(Streams, Options, Report) then
ShowMessage(Format('%d extracted, %d failed, %d skipped',
[Report.ExtractedCount, Report.FailedCount, Report.SkippedCount]));
finally
for I := 0 to High(Streams) do
Streams[I].Free;
end;
end;