How To…Export Each Group to Stream

“Is is possible to export each individual group to a separate Output Stream that I create?”

Solution

All file devices (PDF, Text, etc.) allow the report export output to be directed to a custom stream rather than the default filestream. It is also possible to use this feature with the “New File” feature of Report Groups to export each individual group to a custom stream as well. This can be useful if you would like to keep each exported group in memory or export to a different type of stream such as a TBlobStream.

1. Create a report that contains groups and is set up to export each group to a separate file. See the following article for more information on this…

https://www.digital-metaphors.com/rbWiki/Output/PDF/How_To…Separate_File_for_Each_Group

2. Write code to export the file to a stream, leaving out the assigning of the OutputStream property. This will be done later in the OnStartJob event. See the following article for more information on this…

https://www.digital-metaphors.com/rbWiki/Output/PDF/PDF_Fundamentals

3. Now implement the Device.OnStartJob event. Inside this event, you will want to create the specific stream for the group being exported and assign it to the Device.OutputStream.

The example below shows how this can be done with MemoryStreams. Notice that a new memory stream is created for each exported group and added to a list. Later to show that each memory stream does infact contain the correct data, it is possible to copy each memory stream to a file to view the output.

Download: ExportGroupsToStream.zip

Sample Delphi code: