Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

How to add a watermark layer to an existing report

edited March 2012 in General
Hi,

I am printing some reports and store them into a database as archive-files.
After a certain time these reports have to be reprinted automatically,
but this time with a watermark.
I tried a ppPageStyle and it looks good.

Now my question. How can I add such a layer (watermark) to an existing
and stored report?
Or the other way round: can I add the layer by default and prevent it
from being printed using archiv-files?

Thanks.

Regards Uli

Comments

  • edited March 2012
    Hi Uli,

    Layers are conceptual only in that they are only a way for ReportBuilder
    to organize the drawcommands rendered.

    An archive file does not save layer information. It is possible however
    to manually add a watermark drawcommand to a page using the following
    technique.

    http://www.digital-metaphors.com/rbWiki/Delphi_Code/Formatting/How_To...Manually_Add_a_Watermark_to_a_Page

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2012
    Nico,


    Ah, cool. Thanks for this hint.
    But I don't see how to use this code with a TppArchiveReader component.
    There is no OnEndPage event.

    Thanks and best regards

    Uli
  • edited March 2012
    Hi Uli,

    You will want to use the OnReadPage event instead when using the
    ArchiveReader. See the RB help for more info.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2012
    Nico,


    Sorry, I use this code now and no watermark is printed:
    What's wrong?

    procedure THauptForm.MyReaderReadPage(Sender, aPage: TObject);
    begin
    CreateWaterMark.Page := aPage as TppPage;
    end;

    function THauptForm.CreateWaterMark: TppDrawCommand;
    var
    lWaterMark: TppDrawText;
    llPageHeight: Longint;
    llPageWidth: Longint;
    liTextWidth: Integer;
    liTextHeight: Integer;
    lPrinter: TppPrinter;
    begin
    lWaterMark := TppDrawText.Create(nil);
    lWaterMark.WrappedText.Add('Wiedervorlage');
    lWaterMark.Transparent := True;
    lWaterMark.IsMemo := False;
    lWaterMark.WordWrap := True;
    lWaterMark.Font.Name := 'Arial';
    lWaterMark.Font.Size := 72;
    lWaterMark.Font.Color := clgray;
    lWaterMark.Autosize := True;
    liTextWidth := 375;
    liTextHeight := 150;
    lPrinter := MyReader.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;

    Best Regards Uli
  • edited March 2012
    In my quick testing with code similar to yours (the code used in the
    AddWatermark example), the text is showing up as expected on every page
    of an archive.

    Try tracing into your code and see if text is actually being added and
    if the measurements are correct. If you still cannot find the issue,
    please construct a simple example and send it to
    support@digital-metaphors.com in .zip format and I'll take a look at it
    for you.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2012
    Nico,


    Meanwhile I found the issue and it works fine.
    Thanks for your help.

    Regards Uli
This discussion has been closed.