How To…Print a Report Backwards

Question

“How do I print my report backwards from last page to first?”

Solution

Start by caching the pages to memory.  Next rearrange the pages as you need by manually starting and ending the print job using the TppDevice.StartJob and TppDevice.EndJob routines.

Download: PrintReportBackwards.zip

Sample Delphi code:

var
  liIndex: Integer;
  lDevice: TppDevice;
  lPrinterDevice: TppPrinterDevice;
  lPage: TppPage;
begin

  lDevice := TppDevice.Create(nil);
  lDevice.PageSetting := psAll;
  lDevice.Publisher := ppReport1.Publisher;

  ppReport1.CachePages := True;
  ppReport1.PrintToDevices;

  lPrinterDevice := TppPrinterDevice.Create(nil);
  lPrinterDevice.Printer.PrinterSetup.Assign(ppReport1.PrinterSetup);

  lPrinterDevice.StartJob;

  for liIndex := ppReport1.Publisher.PageCount - 1 downto 0 do
    begin
      lPage := ppReport1.Publisher.Pages[liIndex];

      lPrinterDevice.ReceivePage(lPage);
    end;

  lPrinterDevice.EndJob;

  lDevice.Free;
  lPrinterDevice.Free;

end;