TdxPDFFileAttachment.Data Property
Specifies the file attachment’s content as an array of bytes.
Declaration
property Data: TBytes read; write;
Property Value
Type | Description |
---|---|
TBytes | A dynamic array of bytes. |
Remarks
You can use this property to update the file attachment’s content or copy it to another file or stream. Use the Size property to obtain the Data array size if the document stores it. Otherwise, call the Length system function and pass the Data property value as a parameter to obtain the array size.
Tip
The LoadFromFile LoadFromStream SaveToFile and SaveToStream procedures allow you to manage file attachment content more easily compared to the Data property.
The following code example copies all files attached to a source document to individual files within the same folder:
var
AAttachment: TdxPDFFileAttachment;
ADocument: TdxPDFDocument;
AFileName, APath: string;
AStream: TFileStream;
begin
AFileName := 'SourceDocument.pdf';
// Creates an empty PDF document container
ADocument := TdxPDFDocument.Create;
// A path to the source document's folder
APath := TPath.GetDirectoryName(ADocument.Information.FileName) +'\';
try
// Loads a source PDF file with the specified name (that is, the absolute or relative path)
ADocument.LoadFromFile(AFileName);
// Iterates through all files attached to the loaded document
for AAttachment in ADocument.FileAttachments do
begin
// Creates a new file whose name is identical to the source file attachment's name
AStream := TFileStream.Create(APath + AAttachment.FileName, fmCreate);
try
// Copies the Data property value to the created file
AStream.Write(AAttachment.Data, Length(AAttachment.Data));
finally
AStream.Free; // Releases the file stream
end;
end;
finally
ADocument.Free; // Releases the PDF document container
end;
end;
See Also