PDFium Delphi Component Docs

CreateAttachment method

Component: TPdf  ·  Unit: PDFium
Adds a new embedded file (attachment) at the document level

Syntax

function CreateAttachment(const Name: WString): Boolean; overload;
function CreateAttachment(const Name: WString; const Data: TBytes): Boolean; overload;

Description

Adds a new embedded file (attachment) at the document level

Returns True when the attachment entry is created. The overload with Data stores the file content in the same call; the overload without it creates an empty entry

PDF keeps embedded files in name order, so a new attachment is not necessarily the last one: after adding Apple.txt to a document that holds notes.txt, index AttachmentCount - 1 is still notes.txt. Pass the content to CreateAttachment, or find the new entry through AttachmentName, instead of writing to the last index

All edits to the current page are buffered in PDFium's in-memory representation. Call UpdatePage to refresh the rendering cache and SaveAs to persist the changes

Remarks

Example

begin
  if Pdf1.Active and Pdf1.CreateAttachment('invoice.xml', TFile.ReadAllBytes('C:\invoice.xml')) then
    Pdf1.SaveAs('output.pdf');
end;

See Also

Attachment, AttachmentCount, DeleteAttachment