Mail Merge

Top  Previous  Next

Since wPDF V2.10 the PDF Engine is able to do "mail-merge", this means it can replace fields found in the input data with text provided by your application.

 

Such fields are defined by a certain start text, for example '@@' followed by any number of characters which are the field name.

 

The start text is defined with the property 'MergeStart' - if it is empty this feature is disabled.

 

Before the engine renders a text which starts with the defined start text it executes the event OnMergeText. In this event you can modify the provided string which is passed as 'var' parameter:

 

This feature can be very useful to enter data into the PDF file which is different on each run of the export for example the current date or time. It is especially useful if you are combing the output of different report engines (RAVE, ReportBuilder) to the same PDF file. In this case each report engine would use its own page counting. If you, instead of using the standard page number fields use a mail-merge field you can enter the page number calculated by the PDF engine:

 

procedure TForm1.WPPDFPrinter1MergeText(Sender: TObject; var Text: String);

begin

  Text := 'Page ' + IntToStr( WPPDFPrinter1.PageNumber );

end;

 

Please note that you can probably use the text alignment flags for the text object to align the text properly.