How To…Add a Drawcommand to a Page

Question

“How do I add items to an archived page before viewing or printing with the Archive Reader?”

Solution

Create a generic TppRasterDevice and implement its OnPageReceive event to add a drawcommand to the page before the report is rendered.

Download: ArchiveReaderAddDrawCommand.zip

Sample Delphi code:

procedure TForm1.ppArchiveReader1BeforePrint(Sender: TObject);
var
  lDevice: TppDevice;
begin

  // get reference to the screen or printer device
  if (ppArchiveReader1.PrinterDevice <> nil) then
    lDevice :=  ppArchiveReader1.PrinterDevice
  else if (ppArchiveReader1.PreviewForm <> nil) then
     lDevice :=  TppViewer(ppArchiveReader1.PreviewForm.Viewer).ScreenDevice
  else
    lDevice := nil;

  // attach handler to device OnPageReceive event
  if (lDevice <> nil) then
    lDevice.OnPageReceive := ehPageReceive;

end;


procedure TForm1.ehPageReceive(Sender, aPage: TObject);
begin
  // add draw command to page (see example for implementation
  AddDrawCommand(TppPage(aPage));

end;