PDFiumVCL Docs

AttachmentType property

Bu API girdisi tanımlayıcıları, imzaları, kod bloklarını ve PDF terimlerini özgün biçiminde korur.
Component: TPdf  ·  Unit: PDFium
Returns the registered MIME / subtype string for the embedded file at the specified zero-based index. The value is taken from the file specification dictionary's /Subtype entry as defined in PDF section 7.11.3.

Syntax

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

Description

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.

Parameters

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

Remarks

Example

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;

See Also

Attachment, AttachmentCount, AttachmentName, CreateAttachment, DeleteAttachment