Question
“How do I print my report to the printer and a file device (PDF, Text, etc.) at the same time?”
Solution
Use the TppReport.OnPrintDialogClose event to create the file device and assign its Publisher and PageRequest property to the report’s.
Download: PrintToPrinterAndArchive.zip
PrinterToPrinterAndPDF.zip
PrintToPrinterAndTextFile.zip
Sample Delphi code:
uses
ppPDFDevice;
procedure TForm1.ppReport1PrintDialogClose(Sender: TObject);
begin
//Create the file device and assign its publisher and PageRequest properties.
if (ppReport1.PrintDialog.ModalResult = mrOK) then
AddPDFDevice(ppReport1, TppPageRequest(ppReport1.PrintDialog.PageRequest));
end;
procedure TForm1.AddPDFDevice(aReport: TppReport; aPageRequest: TppPageRequest);
begin
FPDFDevice := TppPDFDevice.Create(nil);
FPDFDevice.Publisher := aReport.Publisher;
FPDFDevice.FileName := TppFileUtils.GetApplicationFilePath + 'Test.pdf';
FPDFDevice.PageRequest := aPageRequest;
end;
procedure TForm1.ppReport1PrintingComplete(Sender: TObject);
begin
FPDFDevice.Free;
FPDFDevice := nil;
end;