Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-09-06
15
Medium Priority
?
3,589 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?
0
Comment
Question by:HenryM2
  • 7
  • 6
15 Comments
 
LVL 25

Expert Comment

by:epasquier
ID: 33616148
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
 

Author Comment

by:HenryM2
ID: 33616164
I am using Delphi 2010.  I am sure what works in 2007 will work fine in 2010.
0
 
LVL 25

Expert Comment

by:epasquier
ID: 33616508
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 25

Expert Comment

by:epasquier
ID: 33616566
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
 

Author Comment

by:HenryM2
ID: 33616659
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
 

Author Comment

by:HenryM2
ID: 33616674
epasquier:  I am not sure if you have this attached guide, but this is where I am scraping my information from.
ravedevguide5.pdf
0
 
LVL 25

Expert Comment

by:epasquier
ID: 33616947
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
 

Author Comment

by:HenryM2
ID: 33617107
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
 
LVL 25

Expert Comment

by:epasquier
ID: 33618950
> 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
 

Author Comment

by:HenryM2
ID: 33624941
Epasquier, To keep you posted, I just need to kill some other fires, then I will be back on this.
0
 

Author Comment

by:HenryM2
ID: 33679881
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
 
LVL 25

Accepted Solution

by:
epasquier earned 2000 total points
ID: 33707248
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
 

Author Closing Comment

by:HenryM2
ID: 33715710
All working thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question