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 を作り直してください
| Index | Integer. Zero-based attachment slot. Must satisfy 0 <= Index < AttachmentCount. Out-of-range indexes return an empty string. |
/Subtype 完全に空です。type が空でもエラーとして扱わないでください
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;