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:
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.