PDFium Component Docs

Attachment プロパティ

この API エントリでは識別子、シグネチャ、コードブロック、PDF 用語を元の表記のまま保持します。
コンポーネント: TPdf  ·  ユニット: PDFium
指定した 0 基準インデックスの文書レベルの埋め込みファイルにある生バイトの payload を読み取るか置き換えます。各 slot は、PDF 1.7 仕様の 7.11 節で定義される PDF EmbeddedFiles name tree の 1 つの entry に対応します

構文

property Attachment[Index: Integer]: TBytes;

説明

PDF documents can carry arbitrary auxiliary files (source spreadsheets, original Word documents, attached invoices, signed XML payloads, ZIP bundles, even other PDFs) inside a document-level container called the EmbeddedFiles name tree. Each entry is a PDF file specification dictionary whose stream holds the actual bytes of the attached file. PDFiumPas exposes that tree as a flat 0-based index from 0 to AttachmentCount - 1.

Reading Attachment[Index] 添付ファイルのデコード済みバイト内容を次の型で返します TBytes array — exactly the bytes any other PDF reader would extract when the user clicks the paperclip icon and saves the attachment. The returned bytes are already decompressed; you can write them straight to disk, push them to a stream, or feed them back into another TPdf instance if the attachment is itself a PDF.

Writing replaces the file stream of an existing attachment slot in place. The slot must already exist; use CreateAttachment 新しい entry を追加する必要がある場合は先に次を使用してください。書き込みはメモリにバッファされ、文書が次で保存されるまで永続化されません SaveAs.

パラメータ

IndexInteger. Zero-based position in the EmbeddedFiles name tree. Must satisfy 0 <= Index < AttachmentCount. Indexes match those reported by AttachmentName and AttachmentType, so iterating 0..AttachmentCount - 1 visits each attachment exactly once.

備考

var
  I: Integer;
  Data: TBytes;
  OutPath: string;
begin
  Pdf1.LoadFromFile('with-attachments.pdf');
  for I := 0 to Pdf1.AttachmentCount - 1 do
  begin
    Data := Pdf1.Attachment[I];
    OutPath := 'extracted\' + Pdf1.AttachmentName[I];
    TFile.WriteAllBytes(OutPath, Data);
    Memo1.Lines.Add(Format('%s (%s, %d bytes)',
      [Pdf1.AttachmentName[I], Pdf1.AttachmentType[I], Length(Data)]));
  end;
end;

関連項目

AttachmentCount, AttachmentName, AttachmentType, CreateAttachment, DeleteAttachment