Add watermark: Autosize Font?
Hello,
I want to add a watermark to a page when a report is printer with the archive reader. To do that i am using the "OnReadPage" event to get access to the currentlty printed page:
Can you give me a hint how to calculate the font size so that it fits exactly on the page (of any size) for the label printed in an angel of 45 degrees?
Thanks in advance,
Ralf
I want to add a watermark to a page when a report is printer with the archive reader. To do that i am using the "OnReadPage" event to get access to the currentlty printed page:
lDrawText := TppDrawText.Create(nil); lDrawText.Angle := 45; lDrawText.Left := lPage.PageDef.mmMarginLeft; lDrawText.Top := lPage.PageDef.mmMarginTop; lDrawText.Width := lPage.PageDef.mmPrintableWidth; lDrawtext.Height := lPage.PageDef.mmPrintableWidth; lDrawText.Font.Color := clLtGray; lDrawText.Font.Size := 100; // how to autosize the font size to fit to the page? lDrawText.Alignment := taCenter; lDrawText.TextAlignment := taCentered; lDrawText.Transparent := true; lDrawText.IsMemo := false; lDrawText.Autosize := true; lDrawText.Text := 'WATERMARK'; lDrawText.Page := lPage;I found out the "lDrawText.Font.Size" by trial and error (can be used for the page size of my currently used test report). However it would be much better if the font size could be calculated to fit on any page size!
Can you give me a hint how to calculate the font size so that it fits exactly on the page (of any size) for the label printed in an angel of 45 degrees?
Thanks in advance,
Ralf
Comments
lDrawtext.Height := lPage.PageDef.mmPrintableWidth;
should read
lDrawtext.Height := lPage.PageDef.mmPrintableHeight;
(Copy and paste error )
I want this watermark to apear behind all other content of the report. With the code above the watermark appears on top of all other content. I read in other posts that the watermark should be added to a page style but all in examples i found the page style is already created at design time. Can i add such a page style in the OnReadPage (!!) event too?
Thanks again,
Ralf
ReportBuilder does not have auto font scaling so you will need to measure the text manually. I suggest creating a TBitmap and using the Canvas.TextWidth and Canvas.TextHeight to do so.
-- pseudo code -- You can insert the drawcommand at the beginning of the list using the InsertChild command of the TppPage. (Instead of assigning the lDrawCommand.Page property.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
The solution ist working good, thanks.
We currently add the watermark behind all other components. However that leads to a problem when a report contains (for example) label components that are set to be not transparent. These labels are hiding the watermark because of the non transparent background. which does not look good.
A solution would be to add the watermark in front but make this watermark "semi-transparent". Is it possible to "alpha blend" the watermark (it is a TppDrawText) so that the background or and other component behind it shines through? I have not found a way to do that so far. So maybe it is not possible at all?
Thanks in advance,
Ralf
procedure ReportOnEndPage;
var
lDrawText: TppDrawText;
lPage: TppPage;
begin
lPage := Report.engine;
lDrawText := TppDrawText.Create(nil);
lDrawText.Left := 4763;
lDrawText.Top := 7408;
lDrawText.Width := 4630;
lDrawText.Height := 4233;
lDrawText.Angle := 315;
lDrawText.Font.Color := clBlack;
lDrawText.Font.Size := 12;
lDrawText.Transparent := True;
lDrawText.IsMemo := false;
lDrawText.Autosize := True;
lDrawText.Text := 'Copyxx';
lDrawText.Page := lpage;
end;