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

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?
HenryM2Asked:
Who is Participating?
 
Emmanuel PASQUIERConnect With a Mentor Freelance Project ManagerCommented:
this line works for me when I put it in a button
MyRvSystem.SystemPrinter.Orientation := poLandscape;

These are both TOrientation types, defined in RPDefine

it works also if I put it in a "With Sender as TBaseReport do" section, even if that is not useful. You have a problem with TPrinter unit that declares TPrinterOrientation also, but it is different as there is no poDefault in this enum type.

That is a problem with the order of the units in your uses. I tested, it is the last one that takes priority. So you have 2 solutions :
* move uses Printers,... before uses RPDefine
* specify the unit it must use in your code

That is rather a stupid thing Rave Report designers have done there...
MyRvSystem.SystemPrinter.Orientation := RPDefine.poLandscape;

Open in new window

0
 
Emmanuel PASQUIERFreelance Project ManagerCommented:
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
0
 
HenryM2Author Commented:
I am using Delphi 2010.  I am sure what works in 2007 will work fine in 2010.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Emmanuel PASQUIERFreelance Project ManagerCommented:
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

0
 
Emmanuel PASQUIERFreelance Project ManagerCommented:
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)
0
 
HenryM2Author 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

0
 
HenryM2Author Commented:
epasquier:  I am not sure if you have this attached guide, but this is where I am scraping my information from.
ravedevguide5.pdf
0
 
Emmanuel PASQUIERFreelance Project ManagerCommented:
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

0
 
HenryM2Author 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.
0
 
Emmanuel PASQUIERFreelance Project ManagerCommented:
> 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
0
 
HenryM2Author Commented:
Epasquier, To keep you posted, I just need to kill some other fires, then I will be back on this.
0
 
HenryM2Author 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

0
 
HenryM2Author Commented:
All working thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.