Solved

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

Posted on 2010-09-06
15
3,196 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
Comment Utility
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
Comment Utility
I am using Delphi 2010.  I am sure what works in 2007 will work fine in 2010.
0
 
LVL 25

Expert Comment

by:epasquier
Comment Utility
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
 
LVL 25

Expert Comment

by:epasquier
Comment Utility
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
Comment Utility
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
Comment Utility
epasquier:  I am not sure if you have this attached guide, but this is where I am scraping my information from.
ravedevguide5.pdf
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 25

Expert Comment

by:epasquier
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
All working thanks.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Splash screen too shortlived 11 112
delphi custom sort exception 6 109
Delphi selector screen 2 56
Run video youtube webbrowse 10 44
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now