We help IT Professionals succeed at work.

Delphi : Ho do you Print a Bitmap in Rave Reprot, scaling it to the selected Rave page

HenryM2
HenryM2 asked
on
4,175 Views
Last Modified: 2013-11-22
I have a Bitmap as the Picture Property of a TImage ( ReportImg).

I used PrintBitmap(1.0,1.0,1,1, Bitmap) whcih works.

I see Rave Reports offer several funtion that seem related to sizing the immage for printing.  CalcGraphicHeight, CalcGraphicWidth, PrintBitmap, StretchDraw PrintBitmapRect etc.  How do I print this immage on a Rave Report scaled to fit the selcted Rave page?
Comment
Watch Question

Emmanuel PASQUIERFreelance Project Manager
CERTIFIED EXPERT
Top Expert 2010

Commented:
To better help you : which Rave Report version are you using ? Delphi version ?
I'll try to find the best way to print bitmap on rave reports, I can use the one that comes with Delphi 2007

Author

Commented:
I am using Delphi 2010.  I am sure what works in 2007 will work fine in 2010.
Emmanuel PASQUIERFreelance Project Manager
CERTIFIED EXPERT
Top Expert 2010

Commented:
Ok, first time I used Rave Report.. Some concepts I needed to grab, and the help is... well maybe my Delphi 2007 is not installed properly with Rave help integrated

Here is the thing : I managed to actually change an image source in a report page (my biggest problem : I had to find out that you HAD to add the page to a list if you wanted it to be generated...)
procedure TForm1.btn1Click(Sender: TObject);
Var
 MyPage: TRavePage;
 MyBitmap: TRaveBitmap;
begin
 RvProject.Open;
 MyPage := RvProject.ProjMan.FindRaveComponent('Report1.Page1', nil) as TRavePage;
 MyBitmap:= MyPage.FindComponent('BMP1') As TRaveBitmap;
 MyBitmap.Image.Assign(Img1.Picture.Bitmap);
 RvProject.Execute;
end;

Open in new window

Emmanuel PASQUIERFreelance Project Manager
CERTIFIED EXPERT
Top Expert 2010

Commented:
and that done, everything else is controlled from the Rave report designer : how the image control fits in the page, how the image source fits in that TRaveBitmap control (with MatchSide which I recommend to set to msInside)

Author

Commented:
Well I started on Rave Friday when aflarin sugested I do.  I think Rave is quite nice, but I am thus also also very new to it.  Just to get on the same page as you.

What I have done so far is to have a TRvSystem visual component, named (MyRvSystem).  

Using the code below works fine, but the scaling on the Rave Report canvas is wrong and the page orientation needs to swing to poLandscape for this report.  I can set it to landcape in myRvSystem properties at design time, but there is a text report also printing through the same MyRvSystem  .  I just need to get the page size and orientation soreted out which is where I think the code you poseted will help.  What do you think?
procedure TReportsFrm.Print1Click(Sender: TObject);
begin
  MyRvSystem.Execute;
end;

procedure TReportsFrm.MyRvSystemPrint(Sender: TObject);
Var Report: TBaseReport;
begin
  PrintGraphicsReport(Sender as TBaseReport)
end;

procedure TReportsFrm.PrintGraphicsReport(Report: TBaseReport);
begin
  with Report do
  begin
    PrintBitmap(0.5,0.5,1,1, ReportImg.Picture.Bitmap); // This is the Bitmap that came from the Merge Procedure of yesterday
  end;
end;

Open in new window

Author

Commented:
epasquier:  I am not sure if you have this attached guide, but this is where I am scraping my information from.
ravedevguide5.pdf
Emmanuel PASQUIERFreelance Project Manager
CERTIFIED EXPERT
Top Expert 2010

Commented:
you can change a page orientation programmatically :

MyPage.Orientation:=poLandscape;

but it is messing all the layout. The best is to change orientation of pages from the Rave Editor. That way I'm sure you can mix page orientations between different reports, even between pages within the same report

Why don't you use the Rave Designer to place a BMP component in a page as I did, instead of playing with PrintBitmap ?

for information, I only have a TRvProject component in my form. And the code to load the bitmap is simple. No events to manage. All controled from the .RAV project file (which can be changed at will without recompiling the application)
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, RpDefine, RpRave,  RvCsDraw, RvCsStd, RvClass,
  RpRender, RpRenderCanvas, RpRenderPreview;

type
  TForm1 = class(TForm)
    RvProject: TRvProject;
    img1: TImage;
    btn1: TButton;
    procedure btn1Click(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
Var
 MyPage: TRavePage;
 MyBitmap: TRaveBitmap;
begin
 RvProject.Open;
 MyPage := RvProject.ProjMan.FindRaveComponent('Report1.Page1', nil) as TRavePage;
 MyPage.Orientation:=poLandscape; // You can do this, but I prefer setting it from Rave Designer
 MyBitmap:= MyPage.FindComponent('BMP1') As TRaveBitmap;
 MyBitmap.Image.Assign(Img1.Picture.Bitmap);
 RvProject.Execute;
 RvProject.Close;
end;

end.

Open in new window

Author

Commented:
Mmm, I should have gone for Rave Designer sooner, but in itself it looked a bit intimidating.  When I looked at it the firts time, it appeared to me that my learning curve would be more than with the code based.  I therefore have now done a lot of work on the Code based Rave for the text reports which live along side the graphic report.

You mention the Rave Editor, where do I find this?

> you can change a page orientation programmatically :
MyPage.Orientation:=poLandscape;

Where is MyPage in the bigger picture of my program?

I tried to change the orientation in theTRvSystem as follows:
  with Report do
  begin
    MyRvSystem.SystemPrinter.Orientation := poLandscape;
  end;
But the compiler replies with:
 [DCC Error] ReportsUNT.pas(535): E2010 Incompatible types: 'TOrientation' and 'TPrinterOrientation'

My appologies if some of these things should be obvious, but I don't have that much Delphi experience, well a lot more than Rave but certainly nowhere near what you guys have in Delphi.
Emmanuel PASQUIERFreelance Project Manager
CERTIFIED EXPERT
Top Expert 2010

Commented:
> You mention the Rave Editor, where do I find this
Double click on the TRvProject componnent

It is the best thing now to rethink your app with RaveEditor. But I think the learning curve will be high soon enough, after a bit playing around at the beginning.

 [DCC Error] ReportsUNT.pas(535): E2010 Incompatible types: 'TOrientation' and 'TPrinterOrientation'
I changed the orientation at the page level. maybe they declared another orientation type for systemprinter

Author

Commented:
Epasquier, To keep you posted, I just need to kill some other fires, then I will be back on this.

Author

Commented:
OK I am back, had to attend to some other issues.  I largely resolved my pronlem as follows:

Using a TRvSystem component (MyRvSystem) I have the attached code which works quite well.

You will notice the line "MyRvSystem.SystemPrinter.Orientation := poLandscape;" is commented out.  With this line, the compiler generates the following error:
[DCC Error] ReportsUNT.pas(666): E2010 Incompatible types: 'TOrientation' and 'TPrinterOrientation'

I can howver chnage the SystemPrinter.Orientation property to poLandscape in the Object Inspector at design time.  I would however like to do this under program control.
procedure TReportsFrm.MyRvSystemPrint(Sender: TObject);
Var Report: TBaseReport;
begin
  if ReportPageControl.ActivePageIndex = 0 Then // TreeView
  PrintTreeViewReport(Sender as TBaseReport)
  else
  if ReportPageControl.ActivePageIndex = 1 Then // GridView
  PrintReportStringGrid(Sender as TBaseReport)
  else
  if ReportPageControl.ActivePageIndex = 2 Then // Graphics View
  PrintGraphicsReport(Sender as TBaseReport)
end;

procedure TReportsFrm.PrintGraphicsReport(Sender: TObject);
var
  Bitmap : TBitmap;
  BitmapHeight, BitMapWidth : Integer;
begin

  with Sender as TBaseReport do
  begin
    //MyRvSystem.SystemPrinter.Orientation := poLandscape;
    SetFont('Arial', 15);
    FontColor := clRed;
    PrintXY(0.5,0.5, ReportName);
    try
      BitmapWidth := ReportImg.Picture.Bitmap.Width;
      BitmapHeight := ReportImg.Picture.Bitmap.Height;
      PrintBitmapRect(0.2,0.2, PageWidth - 0.2, PageHeight - 0.2 , ReportImg.Picture.Bitmap);
    finally

    end;
  end;
end;

Open in new window

Freelance Project Manager
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
All working thanks.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.