property AttachmentType[Index: Integer]: WString; // read only
The PDF file specification dictionary can carry an optional /Subtype name that encodes the IANA MIME type of the embedded payload (for example application#2Fpdf, image#2Fpng, text#2Fcsv). PDFiumVCL decodes the PDF hex escapes (#2F back to /) and exposes the value as a plain Unicode string such as "application/pdf" or "image/png".
Use this property to decide how to dispatch the extracted bytes — for example, opening application/pdf attachments inline in another TPdf instance, sending images to a TImage, or saving everything else through a save dialog. When the author did not record a subtype the property returns an empty string; in that case fall back to extension sniffing on AttachmentName.
The property is read-only. The MIME entry is fixed at attachment creation time inside PDFium and cannot be changed in place; recreate the slot if you must rewrite the subtype.
| Index | Integer. Zero-based attachment slot. Must satisfy 0 <= Index < AttachmentCount. Out-of-range indexes return an empty string. |
/Subtype entirely. Don't treat an empty type as an error.
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;