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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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; |