Question
“How can I add a watermark to a page in code without using the PageStyle band?”
Solution
Use the Report.OnEndPage event to create the drawcommands needed and manually add them to the page.
Note: If you would like the watermark to appear behind the rest of the report components, create a Page Style and use its BeforePrint event instead.
Download:
WaterMark.zip
WaterMarkBehind.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 |
uses ppDrwCmd, ppUtils, ppTypes; procedure TForm1.ppReport1EndPage(Sender: TObject); begin CreateWaterMark.Page := ppReport1.Engine.Page; end; function TForm1.CreateWaterMark: TppDrawCommand; var lWaterMark: TppDrawText; llPageHeight: Longint; llPageWidth: Longint; liTextWidth: Integer; liTextHeight: Integer; lPrinter: TppPrinter; begin lWaterMark := TppDrawText.Create(nil); lWaterMark.WrappedText.Add('ReportBuilder ' + ppEdition + #153 + ' - Demo Copy'); lWaterMark.WrappedText.Add('Version ' + ppVersion); lWaterMark.WrappedText.Add('Digital Metaphors Corporation'); lWaterMark.WrappedText.Add('E-Mail: sales@digital-metaphors.com'); lWaterMark.Transparent := True; lWaterMark.IsMemo := False; lWaterMark.WordWrap := True; lWaterMark.Font.Name := 'Arial'; lWaterMark.Font.Size := 18; lWaterMark.Font.Color := clBlack; lWaterMark.Autosize := True; liTextWidth := 375; liTextHeight := 150; lPrinter := ppReport1.Printer; llPageHeight := lPrinter.PrinterSetup.PageDef.mmPrintableHeight; llPageWidth := lPrinter.PrinterSetup.PageDef.mmPrintableWidth; lWaterMark.Height := ppToMMThousandths(liTextHeight, utScreenPixels, pprtHorizontal, nil); lWaterMark.Width := ppToMMThousandths(liTextWidth, utScreenPixels, pprtHorizontal, nil); lWaterMark.Top := (llPageHeight - lWaterMark.Height) div 2; lWaterMark.Left := (llPageWidth - lWaterMark.Width ) div 2; Result := lWaterMark; end; |