ArchiveReader and Streams
Hi,
Just wondering if there is an example on how to use the archive reader with a stream, or if you can please advise what is wrong with the below code?
Adam.
Just wondering if there is an example on how to use the archive reader with a stream, or if you can please advise what is wrong with the below code?
MS1 := TMemoryStream.Create;Thanks & Regards
lArchiveReader := TppArchiveReader.Create(nil);
lArchiveDevice := TppArchiveDevice.Create(nil);
lArchiveDevice.Publisher := lArchiveReader.Publisher;
lArchiveDevice.OutputStream := MS1;
if not Table.isempty then
begin
while not Table.eof do
begin
MS2 := TMemoryStream.create;
TableReportData.SaveToStream(MS2);
MS2.position := 0;
lArchiveDevice.StartPrintJob := Table.Bof;
lArchiveDevice.EndPrintJob := (Table.RecNo = Table.RecordCount);
lArchiveReader.ArchiveStream := MS2;
lArchiveReader.PrintToDevices;
MS2.free;
Table.next;
end;
lArchiveReader.AllowPrintToFile := true;
lArchiveReader.ShowPrintDialog := False;
lArchiveReader.DeviceType := dtPDF;
lArchiveReader.PDFSettings.Author := Appname;
lArchiveReader.PDFSettings.Title := 'Title';
lArchiveReader.PDFSettings.OpenPDFFile := false;
lArchiveReader.TextFileName := 'c:\temp\merged.pdf';
lArchiveReader.Print;
ms1.free;
lArchiveDevice.Free;
lArchiveReader.Free;
Adam.
Comments
The issue is that your merged archive data is held in the MS1 stream, yet you never assign it to the ArchiveReader after the loop.
Your code above merges multiple archives to a single archive, then exports that to PDF. You could skip the first step and merge the multiple archives (from your DB) directly to PDF.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
And thanks for all your help this year too!
Just a quick question. Instead of using
lPDFDevice.FileName := 'c:\temp\merged.pdf';
I was hoping to save the end result to MS1. (TMemoryStream). Just wondering if this is possible, or whether I have to offload it to a file, and then re-import it?
Thanks & Regards
Adam.
Rather than assigning the FileName of the PDFDevice, simply set its OutputStream property to the memory stream you would like to write to (MS1).
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
lDevice.reset
after each itteration of PrintToDevices.
The end result is the following functions/procedures which I leave here in case it may come in handy for anyone else looking to do anything similar in the future. (Or incase I forget and find my own question 10 years from now... it's happened before ;-)