Creating a border around entire page
Hi,
I was just wondering if there was a simpler way to set a page border on
my reports.
At present, the only option I can come up with is to create a shape in
the PageStyle and Set it for the border (as per the code below).
I was just wondering if this is the best way to accomplish this, or if
there is a more streamlined solution?
(I'm looking for a single method I can apply to multiple reports at once
at runtime, and not needing to do it per report in design time)
------------------------------------------------
Uses ppClasUt;
Procedure SetPageBorder(Report : TppReport);
var
myPageStyle : TppPageStyle;
BorderShape : TppShape;
psHeight : double;
begin
if Report.PageStyle = nil then
begin
//Create a page style because none exists
myPageStyle := TppPageStyle(ppComponentCreate(Report,
TppPageStyle));
myPageStyle.Report := Report;
end
else //Use the existing page style
myPageStyle := Report.PageStyle;
//Make sure page style is the correct height we need
psheight := Report.PrinterSetup.PaperHeight -
(Report.PrinterSetup.MarginTop +
Report.PrinterSetup.MarginBottom);
if myPageStyle.height < psheight then
myPageStyle.height := psheight;
myPageStyle.visible := true;
//Create and apply the border shape.
BorderShape := TppShape.create(report.owner);
BorderShape.band := MyPageStyle;
BorderShape.Parentheight := true;
BorderShape.ParentWidth := True;
BorderShape.SendToBack;
end;
------------------------------------------------
Thanks in advance...
Adam.
I was just wondering if there was a simpler way to set a page border on
my reports.
At present, the only option I can come up with is to create a shape in
the PageStyle and Set it for the border (as per the code below).
I was just wondering if this is the best way to accomplish this, or if
there is a more streamlined solution?
(I'm looking for a single method I can apply to multiple reports at once
at runtime, and not needing to do it per report in design time)
------------------------------------------------
Uses ppClasUt;
Procedure SetPageBorder(Report : TppReport);
var
myPageStyle : TppPageStyle;
BorderShape : TppShape;
psHeight : double;
begin
if Report.PageStyle = nil then
begin
//Create a page style because none exists
myPageStyle := TppPageStyle(ppComponentCreate(Report,
TppPageStyle));
myPageStyle.Report := Report;
end
else //Use the existing page style
myPageStyle := Report.PageStyle;
//Make sure page style is the correct height we need
psheight := Report.PrinterSetup.PaperHeight -
(Report.PrinterSetup.MarginTop +
Report.PrinterSetup.MarginBottom);
if myPageStyle.height < psheight then
myPageStyle.height := psheight;
myPageStyle.visible := true;
//Create and apply the border shape.
BorderShape := TppShape.create(report.owner);
BorderShape.band := MyPageStyle;
BorderShape.Parentheight := true;
BorderShape.ParentWidth := True;
BorderShape.SendToBack;
end;
------------------------------------------------
Thanks in advance...
Adam.
This discussion has been closed.
Comments
ReportBuilder does not have a built-in way to create a border around an
entire page.
If you would like to do without the page style, you could manually add a
shape drawcommand before the report is generated. Take a look at the
following article on manually adding watermarks.
http://www.digital-metaphors.com/rbWiki/Delphi_Code/Formatting/How_To...Manually_Add_a_Watermark_to_a_Page
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Thanks for your reply.
I've tried following that example but using tppDrawLine instead, and I'm
unable to get a working result.
The current script I have is as follows (which compiles, but seems to do
nothing).
I was wondering if you could please take a look and advise where I may
have gone wrong?
Thanks & Regards
Adam.
procedure TReportTemplate.setpageborder(Report : TppReport);
begin
Report.OnEndPage := ReportTemplate.ppMyReportEndPage;
end;
Function TReportTemplate.CreatePageBorder(Report : TppReport) :
TppDrawCommand;
//Uses: ppDrwCmd, ppUtils, ppTypes, ppDevice, ppPrintr;
var
lDrawLine: TppDrawLine;
lBorderOuter : TppDrawShape;
llPageHeight : Double;
llPageWidth : Double;
llPageTop : Double;
llPageLeft : Double;
lPrinter : TppPrinter;
begin
lPrinter := Report.Printer;
lBorderOuter := tppDrawShape.create(nil);
llPageHeight := lPrinter.PrinterSetup.PageDef.mmPrintableHeight;
llPageWidth := lPrinter.PrinterSetup.PageDef.mmPrintableWidth;
lBorderOuter.height := ppToMMThousandths(llPageLeft, utScreenPixels,
pprtHorizontal, nil);
lBorderOuter.width := ppToMMThousandths(llPageLeft, utScreenPixels,
pprtHorizontal, nil);
lBorderOuter.Top := 0;
lBorderOuter.Width := 0;
lBorderOuter.Pen.color := clBlack;
lBorderOuter.Pen.width := 5;
lBorderOuter.Brush.Style := bsClear;
result := lBorderOuter;
end;
procedure TReportTemplate.ppMyReportEndPage(Sender: TObject);
begin
CreatePageBorder(tppReport(sender)).page := tppreport(sender).Engine.page;
end;
procedure TReportTemplate.PrintMyReport;
begin
SetPageBorder(ppReport1);
ppreport1.print;
end;
It looks like your measurements are incorrect. You are setting the
Height to PageLeft and the Width to 0 . Try something like the following.
lPrinter := Report.Printer;
lBorderOuter := TppDrawShape.Create(nil);
lBorderOuter.Top := 0;
lBorderOuter.Left := 0;
lBorderOuter.Height := lPrinter.PrinterSetup.PageDef.mmPrintableHeight;
lBorderOuter.Width := lPrinter.PrinterSetup.PageDef.mmPrintableWidth;
lBorderOuter.Pen.Color := clBlack;
lBorderOuter.Pen.Width := 5;
...
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Thanks for your reply. That was a great help.
I modified your example slightly and replaced
with
lBorderOuter.Top := lPrinter.PrinterSetup.PageDef.mmMarginTop;
lBorderOuter.Left := lPrinter.PrinterSetup.PageDef.mmMarginLeft;
To centre the border. Works a treat now! Thanks very much!
Adam.