[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1638
  • Last Modified:

RAVE CustomConnection to print two 4x6 jpeg files and text per page


I need to be able to print sheets of two (approximately) 4x6 inch jpg images on a page through code using a customconnection in RAVE. Under the image, I want to print the filename.

I want to use RAVE because of the ability to generate PDF files.

Does anyone have a working solution to this?  I've seen samples printing a single graphic to a page, and doing jpeg files from Nevrona's site, but I need a quick solution and I have little time to play with this one with my current project load.

I would basically like to feed the jpg file location and a line of text to print under it.

Thanks,

Scott
0
sfb
Asked:
sfb
  • 11
  • 8
1 Solution
 
DragonSlayerCommented:
A few ways to do it:

Use: Parameters (however, the code below only work for BMP, not JPEG, so you would have to first convert your graphic to BMP, or refer to the FAQ you have read in Nev's site to display a JPEG):

In your rave designer:
1. At the treeview on the right, select RaveProject, and from the Object Inspector, select Parameters
2. Add in the following parameters:
Image1Location
Image1Description
Image2Location
Image2Description
3. Put in 2 Bitmap components and 4 DataText components (2 for filenames, 2 for description).
4. Set DataField of the DataText components to Param.Image1Location, Param.Image1Description, Param.Image2Location and Param.Image2Description respectively.
5. Select your first Bitmap, then click on the tab to the Event Editor, and add the following code:
Bitmap1.FileLink := RaveProject.GetParam(Image1Location);
6. Repeat #5 with Bitmap2 and Image2Location.

In your Delphi code:

procedure TForm1.actPrintExecute(Sender: TObject);
begin
  with RvProject1 do
  begin
    SetParam('Image1Location', TheLocationOfYourBitmap1);
    SetParam('Image2Location', TheLocationOfYourBitmap2);
    SetParam('Image1Description', TheDescriptionOfYourBitmap1);
    SetParam('Image2Description', TheDescriptionOfYourBitmap2);
    ExecuteReport('rptMyReport');
  end;
end;



DragonSlayer.
0
 
DragonSlayerCommented:
ignore the "A few ways to do it:" line... initially wanted to show more than one way, but got lazy in the end ;-)
0
 
sfbAuthor Commented:

Thanks DragonSlayer,

I'm just on my way out the door to go to work.  I'll try it when I get there.

Will this not require printing the report one time for each run of several pages?  I did mention sheets because a run will have up to a couple dozen images.  That wouldn't be an issue, except with the abilty to save to PDFs.

Scott
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DragonSlayerCommented:
Well, in that case, are your images in a database? If it is, then the solution is much simpler! (I assume that you are getting it via a TADOQuery?)

1. Type in the query, set TADOQuery to active, go to the Fields Editor of the Query and select Add All Fields
2. Drop in a TRvDatasetConnection, and set the DataSet to your TADOQuery
3. Run your programme
4. In your Rave Designer, create a new Data Object and select Direct Data View. Press Next and select the name of your TRvDatasetConnection
5. Still in Rave, create your report as usual (DataBand, etc), and drop in a Bitmap component into your band. Assign the DataField and DataView properties.

Now you can execute your report ;-)
0
 
sfbAuthor Commented:

Hi DragonSlayer,

Not from a database.  They are jpg files from a digital camera.  The guy taking the pictures renames the files to suit their end use, and my program searches the directory and identifies which files should be printed.  The pictures are organized into subdirectory by the user, and only one directory at a time is printed.

A screenshot of the current version is here:

http://www.predomi.net/MarkB.jpg

Sorry for the delay.  Really busy day at work.

Scott
0
 
DragonSlayerCommented:
Well, in that case, you would have to create a CustomConnection instead of a DatasetConnection. Do you know how to create a custom connection and your own OnGetCol/Row handlers?
0
 
sfbAuthor Commented:


That's what my request was.

Title: RAVE CustomConnection to print two 4x6 jpeg files and text per page

Text:  "I need to be able to print sheets of two (approximately) 4x6 inch jpg images on a page through code using a customconnection in RAVE..."
"Does anyone have a working solution to this?"
"I need a quick solution and I have little time to play"

I'm certain I could figure it out on my own if I had more time.  I had created a customconnection sample in the past (unfortunately I can't find a copy of that project).  I was looking for an easily modifiable sample code ideally.

Scott
0
 
DragonSlayerCommented:
Ooops... didn't read the Title carefully, sorry! ;-)

Well, I've put together a simple demo for you, for this demo you would need to have a FileListBox (with Mask set to '*.jpg') and you would need some jpg files in your programme's folder. Also, I've thrown in as well the routine to read from jpg and output as bmp, because Rave only takes in WMF and BMP natively. So, here goes:

procedure TForm1.RvCustomConnection1Open(Connection: TRvCustomConnection);
begin
  Connection.DataRows := FileListBox1.Items.Count;
end;

procedure TForm1.RvCustomConnection1GetCols(
  Connection: TRvCustomConnection);
begin
  with Connection do
  begin
    WriteField('Graphics', dtGraphic, 0, 'Graphics', 'Graphics');
    WriteField('Filename', dtString, 30, 'Filename', 'Filename');
  end;
end;

procedure TForm1.RvCustomConnection1GetRow(
  Connection: TRvCustomConnection);
var
  jpg: TJPEGImage;
  bmp: TBitmap;
  s: TMemoryStream;
begin
  jpg := TJPEGImage.Create;
  bmp := TBitmap.Create;
  s := TMemoryStream.Create;
  try
    jpg.LoadFromFile(FileListBox1.Items.Strings[Connection.DataIndex]);
    bmp.Assign(jpg);
    bmp.SaveToStream(s);
    s.Position := 0;
    // write bitmap graphics
    Connection.WriteBlobData(s.Memory^, s.Size);
    // write filename
    Connection.WriteStrData('', FileListBox1.Items.Strings[Connection.DataIndex]);
  finally
    jpg.Free;
    bmp.Free;
    s.Free;
  end;
end;

Now, you can have more things, such as description, etc as well (remember to add it to your OnGetCol handler as well!). In your report, similar to my earlier post, create a data object, link it to the custom connection in your form, create a databand, put in the bitmap object in the databand, and set the dataviews/fields for both databand and bitmap object, respectively.

And you are done ;-)



DragonSlayer.
0
 
DragonSlayerCommented:
Does it work?
0
 
sfbAuthor Commented:

I'm rebuilding my home computer and not much is installed yet, so I couldn't run the code there.  I'm on the east coast, so I received the mail notification JUST before I left work.

I'll try it this morning at work.

Thanks,

Scott
0
 
sfbAuthor Commented:

Okay, hopefully I'll have time this afternoon or evening (Delphi should be fully in the new computer tonight).

Scott
0
 
DragonSlayerCommented:
No probs. Take your time, I'm not the one with the deadline in this one ;-)
0
 
sfbAuthor Commented:

I am unable to find my customconnection sample.  With my (so far unsuccessful) attempts to get a new simple sample working, I wonder if I ever did create one - it may have been QuickReports.

So at this point, I see two possibilities.

One, I keep plugging away at the customconnection causing delay for both of us (because this is the side project, not the several with deadlines).

or

Two, you develop a complete sample that includes the report items.  In the interest of being fair, I would be willing to double the points.

Your choice, please let me know.

Scott
0
 
DragonSlayerCommented:
Erm... guess my explanation above is not sufficient huh? I thought it was simple and step-by-step enough ;-)

Erm... I can create a simple demo for you, but how do I pass it over to you? In keeping up with the EE spirit, all solutions are posted in this forum, and not via private emails...
0
 
DragonSlayerCommented:
Forgot that Rave allows your report to be embedded, so well, that means we can have everything as source. So, OK let me try again:

Create a new project, for simplicity's sake, I'm using a FileListBox, so go to Project -> Options -> Packages and include the Delphi 1.0 Compatibility Components.

Now, right click on your form, select View As Text and overwrite the whole content with this:

object Form1: TForm1
  Left = 192
  Top = 106
  Width = 296
  Height = 205
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object FileListBox1: TFileListBox
    Left = 8
    Top = 8
    Width = 169
    Height = 153
    ItemHeight = 13
    TabOrder = 0
  end
  object Button1: TButton
    Left = 184
    Top = 8
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 1
    OnClick = Button1Click
  end
  object RvProject1: TRvProject
    Engine = RvSystem1
    Left = 216
    Top = 40
    RaveBlobNew = {
      C405000098CF7DF287B6E2405241561A459C00000000075265706F7274310013
      545261766550726F6A6563744D616E616765720B5261766550726F6A65637408
      0D436F6D70696C654E6565646564000546616C73650846756C6C4E616D65060B
      5261766550726F6A6563740A43617465676F7269657308000A506172616D6574
      65727308000650495661727308000B556E697473466163746F72050000000000
      000080FF3F000006094461746156696577310D54526176654461746156696577
      0216010000800001A5429184EC6522184E8612B1A4CA7704C26170D878C4100D
      219BCDA70349B0CA4E32994C922000148C61361CCCA08231D4D86C27184DA650
      3446150C871DC620E8C9B8DC65319D0D26F374C6660609948EC433A9CCE91A9E
      CFE8343370C400030004609063291CE461381A0D26323438D86408C4A7115AF5
      82C463398201644329CCC672349C2854403022DB61B19CC136532D9E8D34BF57
      F0170964BA6132C45FEDE730214CD27A32804019B00042B707299D2F06E33E12
      CF699BC5275658F1BB2172BA5DAF17AAA5F75865D74CF07663261F6D1DDC6BE5
      B2FDF4B381B932E572F990F6733D05D0688D3A4D3190196AD50C48997D85D6EF
      79BD9B80C03ED9EB7785DEE43C7E5C6F13D5E4CBF2B3001E6802020407526570
      6F72743102E703000080014A0613399462010040A090600C2A0A310002CA8523
      09D8CA52329C0DE723A01E311A8E0C4100D219BCDA70349B0CA4E32994C92E84
      918C26C3999410463A9B0D84E309B4CA068F4663674188248C69391CCE903828
      001B1FA18C45D4C8302A06729E994E865A4820000628124AC61AE802CC026C00
      ACC80000044A4248A11D8651406098E6280B04C16188100648333CCD2C0691B0
      649346298A62438424461826A1C662810230EA360D8258C1334A501A0D428648
      C201904548DCB520890E71192520991B0C938C010140B8EE3D14C71763998C70
      1400340CC543513D62F81627C78324DA390C1350A91BC6E408701AE4218A530C
      3140E804611380C52C8531A47A1933881504965160CA3A2D938C16C0C280922B
      0C138AEB0B3C258220318522449433C5E0DC013C4B83E8FC1000C12032269772
      0CA50E060238712383402820044000204C2C8E71000E234162141C20C7F03CC0
      194431E4C2270E0358E82607B040291787A1D0341B4F70A0E63E004204120DC9
      B038A634C7508895130A71847A1743C0C00006C8A20C910AC8604811210DC190
      043D8AB1F4DE3F8582086E0C49A034E7080080301339032050CE21C98314F30B
      C99334EA23C071FCE73C4AE00071310D43649819899318A01986A274471300D0
      50063C4CC1A457154F6014CA10DEA0B4131C89C31C3912C1B250D8164D20081E
      084841581A1185137402220A212098440000D8213601914C513406D060470001
      E0C88D01C06168041F85D05C5030080068762944E0181A018B42E03F06C26344
      B6444062E4AE2485B358FD3048529001004E11D8C41A0941B019000600843B23
      446204A418C5E3889825827258152E0A81DC0C1005109834108D731C4935C411
      74971B05406447214A60889E09CA410004044953C4D002001310312848212407
      1000510C86078B607004128D2350BC1044F04A1C1BC5C100100C0051F09F1049
      401C0121861330421C8461181402CA0154A10A075070D5344981E45F11C012A8
      07074240A0211383201C101C0C72B89F3D89A1F41D094E91A41806C971D8CD2D
      453204071408024840204501C81D178851C06511CD20508D0306F218470083E1
      D0C800CFC0FC9A118191A06525C2C0905D1645D388171B86B2282E2E49E0B104
      1182E08813AC4B41BCB81BC5B3787F2A8680E81621C6035C8A0B00528C5E3000
      22405D3A43A1506C294D7014C8028A707C34180070082A0842516EDD0E89E3F4
      AA3A8D1298AF2B06B0D8A62D86A2AC9A3B8BD2001F1E0152A82A028AC2EC2F5B
      0E10D061114EF144C901631477B4A0143047600417816C088170021D86389301
      E01C060E307E10C7C84A1B42540D8890302381B0E0016218718B90800F40207A
      1742985489E1DA358510B602A0048080}
  end
  object RvSystem1: TRvSystem
    TitleSetup = 'Output Options'
    TitleStatus = 'Report Status'
    TitlePreview = 'Report Preview'
    SystemFiler.StatusFormat = 'Generating page %p'
    SystemPreview.ZoomFactor = 100
    SystemPrinter.ScaleX = 100
    SystemPrinter.ScaleY = 100
    SystemPrinter.StatusFormat = 'Printing page %p'
    SystemPrinter.Title = 'ReportPrinter Report'
    SystemPrinter.UnitsFactor = 1
    Left = 248
    Top = 40
  end
  object RvCustomConnection1: TRvCustomConnection
    RuntimeVisibility = rtDeveloper
    OnGetCols = RvCustomConnection1GetCols
    OnGetRow = RvCustomConnection1GetRow
    OnOpen = RvCustomConnection1Open
    Left = 184
    Top = 40
  end
end

And then, right click at the editor again, and choose View As Form, and overwrite the whole content with this:

unit uMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  RpCon, RpBase, RpSystem, RpDefine, RpRave, StdCtrls, FileCtrl, ExtCtrls;

type
  TForm1 = class(TForm)
    RvProject1: TRvProject;
    RvSystem1: TRvSystem;
    RvCustomConnection1: TRvCustomConnection;
    FileListBox1: TFileListBox;
    Button1: TButton;
    procedure RvCustomConnection1Open(Connection: TRvCustomConnection);
    procedure RvCustomConnection1GetCols(Connection: TRvCustomConnection);
    procedure RvCustomConnection1GetRow(Connection: TRvCustomConnection);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses
  jpeg;

procedure TForm1.RvCustomConnection1Open(Connection: TRvCustomConnection);
begin
  Connection.DataRows := FileListBox1.Items.Count;
end;

procedure TForm1.RvCustomConnection1GetCols(
  Connection: TRvCustomConnection);
begin
  with Connection do
  begin
    WriteField('Graphics', dtGraphic, 0, 'Graphics', 'Graphics');
    WriteField('Filename', dtString, 30, 'Filename', 'Filename');
    WriteField('Diz', dtString, 30, 'Diz', 'Diz');
  end;
end;

procedure TForm1.RvCustomConnection1GetRow(
  Connection: TRvCustomConnection);
var
  jpg: TJPEGImage;
  bmp: TBitmap;
  s: TMemoryStream;
begin
  jpg := TJPEGImage.Create;
  bmp := TBitmap.Create;
  s := TMemoryStream.Create;
  try
    jpg.LoadFromFile(FileListBox1.Items.Strings[Connection.DataIndex]);
    bmp.Assign(jpg);
    bmp.SaveToStream(s);
    s.Position := 0;
    // write bitmap graphics
    Connection.WriteBlobData(s.Memory^, s.Size);
    // write filename
    Connection.WriteStrData('', FileListBox1.Items.Strings[Connection.DataIndex]);
    // simulate some description
    Connection.WriteStrData('', 'Here''s some description for ' +
      FileListBox1.Items.Strings[Connection.DataIndex]);
  finally
    jpg.Free;
    bmp.Free;
    s.Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FileListBox1.Mask := '*.jpg';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  RvProject1.Execute;
end;

end.


Save your unit as uMain, and name your project to whatever you like. Now, compile, and run ;-)

Oh, if you would like to see how the report is made, select the RvProject1 component, click at the elipsis (...) at the StoreRAV property and choose Save to save the report into a rave file that you can open and edit in the Rave Editor.

And also, make sure you copy a few JPG files into the folder where your exe is, in order for this demo to work.



DragonSlayer.
0
 
sfbAuthor Commented:

Wow, that is EXCELLENT!!!  Thank you very much.

How do I add the extra points (well desirved)?  I don't visit here often - only when I'm really stuck.

The instructions from question and answer tips are:

"One Expert gave you a ton of extra help, and you feel your 100-point question is now worth 200 points.
In this case, you just increase the points using the box above the comment box, and click the Submit button. You can only do this, however, before you select a comment as an answer. "

Does that mean it's done in the "Split Points" area?

Thanks again for your help!

Scott
0
 
DragonSlayerCommented:
500 is the max allowable points per Q, so you can't go anywhere more than 500, hehe.

Glad it works for you, Scott! ;-)
0
 
sfbAuthor Commented:

That's terribly unfair.

Thank you again for all of your work.

Scott
0
 
DragonSlayerCommented:
It's ok, I'm just glad it helped you!

... Beam me up, scottie! ... sorry, can't resist that ;-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 11
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now