|
Method AddFileAttachment |
Top Previous Next |
|
It is possible to attach a file or a stream to a PDF file. The data will be displayed by acrobat reader in the list of embedded files and can be saved from there or be opened. This feature makes it possible to save the original document with the PDF print out in RTF format or the invoice data with the invoice print in the rather new ZUGFeRD XML structure.
function AddFileAttachment( Name, Desc : WideString; Stream : TStream; const Typ : WideString = 'text/xml'; ModDate: TDateTime = 0):Boolean; overload;
function AddFileAttachment( Name, Desc : WideString; Filename : WideString; const Typ : WideString = 'text/xml'; ModDate: TDateTime = 0):Boolean; overload;
You can provide a date "ModDate" or leave that field to be 0. In this case the current date will be used for streams, the file date for Files.
This example creates PDF from WPTools and also embeds the original document:
var pdf : TWPPDFExport; mem : TMemoryStream; begin pdf := TWPPDFExport.Create(nil); // This code is only used by our demos. // Please remove this line in your code or // set a different path (see property DLLName in PDF manual) pdf.DLLName := '{hkcu}Software\WPCubed\wPDF\4.0\path'; pdf.FontMode := wpEmbedType3; pdf.Source := WPRichText1; pdf.AutoLaunch:= TRUE; pdf.FileName:= 'wp7out.pdf';
pdf.BeginDoc;
mem := TMemoryStream.Create; WPRichText1.SaveToStream(mem, 'RTF'); pdf.AddFileAttachment( 'Document.RTF', 'Embedded Document', mem, 'application/rtf', Now ); mem.Free; try pdf.Print; finally pdf.EndDoc; pdf.Free; end; end;
|