PDFium Component Docs

AttachmentCount プロパティ

この API エントリでは識別子、シグネチャ、コードブロック、PDF 用語を元の表記のまま保持します。
コンポーネント: TPdf  ·  ユニット: PDFium
文書で宣言されている embedded file attachment の数です

構文

property AttachmentCount: Integer; // read only

説明

AttachmentCount は catalog の /Names /EmbeddedFiles name tree からたどれる embedded file stream を列挙します (PDF 1.7 spec section 7.11)。これらは PDF 内に格納された任意の file (XML, spreadsheet, source CAD, signed XML, ZIP archives など) で、viewer では “Attachments” sidebar として表示されます。PDF/A-3 では、長期再現性のために関連する source artefact をすべてこの方法で embedded にする必要があります

値は ActiveFalse のときと、文書に embedded file がないときに 0 になります。file-attachment annotations (subtype /FileAttachment) はここでは 数えません。それらは page-level annotation であり、代わりに AnnotationCount から見えます。PDFiumPas は Attachment[Index] を通じて embedded stream を TBytes として公開し、人が読める file name と MIME-style type は AttachmentName[Index]AttachmentType[Index] で取得できます

典型的な loop は for I := 0 to Pdf.AttachmentCount - 1 do です。Attachment[I] の各 access は embedded file stream を memory に decompress するので、disk に書き出したり parser に渡したりするなら TBytes を cache してください。attachment の追加・削除は index を無効にします。変更後は AttachmentCount を再取得してください

備考

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;

関連項目

Attachment, AttachmentName, AttachmentType, AnnotationCount