The RTF device gives the capability to easily export any report to RichText format which can be viewed in many text editors such as Microsoft Word and WordPad.
Begin by setting the Report.AllowPrintToFile property to True to enable the Print To File section of the Print Dialog. The print dialog can be bypassed by setting the Report.DeviceType property to “RTF”, assigning the Report.TextFileName property, and setting the Report.ShowPrintDialog property to False.
Sample Delphi code:
procedure TForm1.btnPrintClick(Sender: TObject);
ppReport1.AllowPrintToFile := True;
ppReport1.ShowPrintDialog := False;
ppReport1.DeviceType := dtRTF;
ppReport1.RTFSettings.OpenRTFFile := True;
ppReport1.TextFileName := 'C:\MyRTFFile.RTF';
Below are some important guidelines to follow that will help ensure a more accurate output.
Guideline 1. Font Controls Everything:
The font size of each text object in your report will control the vertical spacing of the report. Try to keep most text objects inside the report of the same font and font size. Also try to keep the vertical space between each text component close to the value of a line of text or a factor of one.
Guideline 2. Use the Default Font:
The RTFSettings.DefaultFont property defines the font of all empty lines inside the report. Adjusting this font to the font most frequently used in the report should give a more accurate ouput. Raising or lowering the size of this font can also help improve accuracy.
Guideline 3. Line It Up:
Try to keep the text components inside the report lined up horizontally and so they do not overlap. Overlapping text is not supported in RichText so all overlapping text will move to the right. Also, if a text object falls half way between two lines, it will either be moved up or down depending on it’s location.
Guideline 4. Keep it Simple:
If you are unable to recreate a report by hand in WordPad very easily, it is likely that the RTFDevice will have trouble as well. Keeping the reports you plan to export to RTF as simple as possible will give the most accurate ouput.
Guideline 5. Use Text Boxes for complex reports:
Complex reports containing a mix of graphics and text that are precisely aligned can be very difficult to export using the above guidelines. In these cases, it may be beneficial to set the TppRTFSettings.UseTextBoxes property to True. This will export all text as a text box in its actual pixel location inside the RTF document. While doing so gives an exact representation of the report in RTF, the editing of text may become more difficult.
RTF Device Options
The following options are controlled using the Report.RTFSettings property. Use these options to help create a RichText document that meets your needs for accuracy and editability.
This is the default font used for all empty lines of text inside the RichText document. For a more accurate output keep this font (and size) equal to the font most frequently used in the report. Doing this also makes editing the exported RichText easier.
By default the RTF Device attempts to produce the most accurate representation of the report as possible. This is very difficult if all empty lines of text are the same size. To work around the issue, small “precision” lines of text are added to the page to increase the vertical accuracy of each component.
Assume for instance there are two text objects 1 inch (72 points) appart vertically. If the default font is Arial 10 and the UsePrecisionLines property is set to True, the RTF Device will insert 7 empty 10 point rows and one 2 point row between them. Otherwise the 2 point line will be ommitted and the lower text object will be moved up and off by approximately 2 points.
Turning the UsePrecisionLines property off can be usefull if the document will be constantly edited in a RTF editor. Though the smaller precision lines increase accuracy, they can be troublesome if trying to add new lines of text manually.
Setting UsePrecisionLines to False will always error on the small side in that all components will be moved up on the page. This can also be useful if the report will not fit on a single page.
Setting this property to True lets the RTF Device attempt to merge any report RTF components into the exported Richtext document. The Richtext component in your report will be treated as wrapped text in the exported document and will contain all custom formatting.
Alternatively, if this property is set to False, a metafile image of the RTF component will be inserted into the Richtext document. This option is handy when the RTF component is too advanced for the device to handle.
Occationally it may be necessary to export only certain report components to a Richtext document. For instance if your text editor does not support graphics or images. Use the ExportComponents property to control which report components are exported.