PDFium Component Docs

AttachmentType プロパティ

この API エントリでは識別子、シグネチャ、コードブロック、PDF 用語を元の表記のまま保持します。
コンポーネント: TPdf  ·  ユニット: PDFium
指定した 0 基準インデックスの埋め込みファイルに対する登録済み MIME / subtype string を返します。値は、PDF 7.11.3 節で定義される file specification dictionary の /Subtype entry から取得されます

構文

property AttachmentType[Index: Integer]: WString; // read only

説明

The PDF file specification dictionary can carry an optional /Subtype 埋め込み payload の IANA MIME type を符号化する name です (たとえば application#2Fpdf, image#2Fpng, text#2Fcsv). PDFiumPas decodes the PDF hex escapes (#2F back to /) そして値を次のような plain Unicode string として公開します "application/pdf" or "image/png".

この property を使って、抽出した bytes をどう振り分けるか決めます。たとえば、次を開く application/pdf attachments inline in another TPdf instance, sending images to a TImage、それ以外は save dialog で保存します。作成者が subtype を記録していない場合、この property は空文字列を返します。その場合は次で extension sniffing にフォールバックしてください AttachmentName.

この property は読み取り専用です。MIME entry は PDFium 内で添付作成時に固定され、途中で変更できません。subtype を書き直す必要があるなら slot を作り直してください

パラメータ

IndexInteger. Zero-based attachment slot. Must satisfy 0 <= Index < AttachmentCount. Out-of-range indexes return an empty string.

備考

var
  I: Integer;
  Mime, Name: string;
begin
  Pdf1.LoadFromFile('mixed-attachments.pdf');
  for I := 0 to Pdf1.AttachmentCount - 1 do
  begin
    Name := Pdf1.AttachmentName[I];
    Mime := LowerCase(Pdf1.AttachmentType[I]);
    if Mime = 'application/pdf' then
      Memo1.Lines.Add('PDF: ' + Name)
    else if StartsText('image/', Mime) then
      Memo1.Lines.Add('Image: ' + Name)
    else
      Memo1.Lines.Add(Format('%s [%s]', [Name, Mime]));
  end;
end;

関連項目

Attachment, AttachmentCount, AttachmentName, CreateAttachment, DeleteAttachment