Question
“How do I toggle the page orientation from the preview window?”
Solution
Create a preview plugin that creates a new button to alter the page orientation of the report and regenerate when clicked.
Download: ToggleOrientationPlugin.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 |
type TmyToggleOrientationPlugin = class(TppPreview) private FOrientationButton: TppTBXItem; procedure OrientationButtonClickEvent(Sender: TObject); public procedure CreateToolbarItems; override; end; implementation uses Printers, SysUtils, ppReport, ppDevice, ppUtils, ppPrnDev, ppToolResources; procedure TmyToggleOrientationPlugin.CreateToolbarItems; begin inherited CreateToolbarItems; FOrientationButton := Toolbar.AddButton(); FOrientationButton.ImageIndex := ToolImageList.AddTool('PPZOOMPAGEWIDTH'); //Replace with your own. FOrientationButton.OnClick := OrientationButtonClickEvent; FOrientationButton.Hint := 'Toggle Orientation'; end; procedure TmyToggleOrientationPlugin.OrientationButtonClickEvent(Sender: TObject); var lReport: TppReport; begin lReport := TppReport(Viewer.Report); try case lReport.PrinterSetup.Orientation of poPortrait: lReport.PrinterSetup.Orientation := poLandscape; poLandscape: lReport.PrinterSetup.Orientation := poPortrait; end; finally TppReport( Viewer.Report).Engine.Reset; Viewer.Reset; Viewer.Report.PrintToDevices; end; end; initialization TppPreviewPlugIn.Register(TmyToggleOrientationPlugin); finalization TppPreviewPlugIn.UnRegister(TmyToggleOrientationPlugin); end. |