Question
“How can I add a PDF button to the Report Explorer toolbar?”
Solution
The following example shows create and register a custom ReportExplorer form descendant.
Download: ReportExplorerAddPDFButton.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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
uses ppForms, ppExpFrm, ppTBX, ppToolResources, ppTypes; type TmyReportExplorerForm = class(TppReportExplorerForm) private FPDFButton: TppTBXItem; protected procedure ehPDFButton_Click(Sender: TObject); virtual; public procedure Initialize; override; property PDFButton: TppTBXItem read FPDFButton; end; implementation uses ppFileUtils, ppReport, ppRptExp; {------------------------------------------------------------------------------} { TppReportExplorerForm.ehPDFButton_Click } procedure TmyReportExplorerForm.ehPDFButton_Click(Sender: TObject); var lReportExplorer: TppReportExplorer; lReport: TppReport; begin lReportExplorer := TppReportExplorer(ReportExplorer); lReport := lReportExplorer.Designer.Report; if lReportExplorer.IsReport(ListView.ItemName, ListView.FolderId)then begin lReportExplorer.LoadReport(ListView.ItemName, ListView.FolderId); lReport.DeviceType := dtPDF; lReport.AllowPrintToFile := True; lReport.PDFSettings.OpenPDFFile := True; // optional // lReport.ShowPrintDialog := False; // optional lReport.TextFileName := TppFileUtils.GetApplicationFilePath + ListView.ItemName + '.pdf'; // default file name lReport.Print; end; end; {------------------------------------------------------------------------------} { TppReportExplorerForm.Initialize } procedure TmyReportExplorerForm.Initialize; var liIndex: Integer; begin inherited; liIndex := Toolbar.Items.IndexOf(Toolbar.Email); FPDFButton := TppTBXItem.Create(nil); Toolbar.Items.Insert(liIndex, FPDFButton); FPDFButton.Hint := 'PDF'; FPDFButton.OnClick := ehPDFButton_Click; //TODO: create image list and load PDF icon // FPDFButton.Images := FImageList; // FPDFButton.ImageIndex := // temp code - need an icon for the button to appear FPDFButton.ImageIndex := ToolImageList.AddIcon('PPEMAIL'); end; {procedure, Initialize} {****************************************************************************** * ** I N I T I A L I Z A T I O N / F I N A L I Z A T I O N * {******************************************************************************} initialization ppRegisterForm(TppCustomReportExplorer, TmyReportExplorerForm); finalization ppUnRegisterForm(TppCustomReportExplorer); end. |