“Is is possible to export each individual group to a separate Output Stream that I create?”
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…
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…
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.
Sample Delphi code:
procedure TForm2.Button1Click(Sender: TObject);
FPDFDevice := TppPDFDevice.Create(self);
//Assign the OnStartJob event. Manually assign the OutputStream inside this event.
FPDFDevice.OnStartJob := PDFStartJobEvent;
FPDFDevice.PDFSettings := ppReport1.PDFSettings;
FPDFDevice.Publisher := ppReport1.Publisher;
procedure TForm2.PDFStartJobEvent(Sender: TObject);
//Create a separate memory stream for each group.
lMemStream := TMemoryStream.Create;
//Assign the Device OutputStream to the memory stream.
FPDFDevice.OutputStream := lMemStream;
//Add the memory stream to a list for later use.