property AttachmentType[Index: Integer]: WString; // read only
PDF 文件规范字典可以携带一个可选的 /Subtype 名称,它编码嵌入载荷的 IANA MIME 类型(例如 application#2Fpdf、image#2Fpng、text#2Fcsv)。PDFium Delphi Component 解码 PDF 十六进制转义(将 #2F 还原为 /),并将值暴露为普通 Unicode 字符串,例如 "application/pdf" 或 "image/png"
使用此属性来决定如何分派提取的字节 — 例如,在另一个 TPdf 实例中内联打开 application/pdf 附件,将图像发送到 TImage,或通过保存对话框保存其他所有内容。当作者没有记录子类型时,该属性返回空字符串;在这种情况下,回退到对 AttachmentName 进行扩展名嗅探
该属性是只读的。MIME 条目在附件创建时在 PDFium 内部固定,无法就地更改;如果必须重写子类型,请重新创建槽位
| Index | Integer。基于 0 的附件槽位。必须满足 0 <= Index < AttachmentCount。超出范围的索引会返回空字符串 |
/Subtype。不要将空类型视为错误
var
I: Integer;
Mime, Name: string;
begin
Pdf1.FileName := 'mixed-attachments.pdf';
Pdf1.Active := True;
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;