function CreateAttachment(const Name: WString): Boolean; overload;
function CreateAttachment(const Name: WString; const Data: TBytes): Boolean; overload;
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
Pdf1.Active must be True before creating an attachmentSaveAs after populating the attachment to persist the updated documentData raises EPdfError when the entry is created but its content cannot be stored
begin
if Pdf1.Active and Pdf1.CreateAttachment('invoice.xml', TFile.ReadAllBytes('C:\invoice.xml')) then
Pdf1.SaveAs('output.pdf');
end;