|
|
How to Use cViewIMAGE
Report Designers needing to take a file
name from a database and to display an image from the file name inside a
Crystal Report have found using cViewIMAGE as follows works best...
Design your report using the tables, fields, etc you need in the main
report. You do not need to display the field that has the filename of
your image but it does need to be in the table.
Your database field does not need to store the fully qualified filename.
If you do have it, the Crystal Report will use it as a parameter link to
your image. If you only store the file name, you can create a formula in
Crystal to add the path to the filename. The formula will then be used
as the parameter link instead..
Step by Step instructions:
1. Create a report from your datasource
In this example, we are using the Access d/b StaffReferencedImage.mdb
from the Demo v085 folder available on our website www.chelseatech.net/downreg.asp?id=cvid085
Select the one table in the database: StaffImagePath
Insert a group on FirstName field.
Make the Group header taller and insert the Position field in the Group
header
2. Insert a subreport into the Group Header:
Insert menu / Subreport.
This example is called SubReportOfImages.
Click on the "Report Expert" box.
Click on the "Database" box.
Expand "More Data sources".
Expand "Active Data" Click on "Com Data".
(For Crystal reports version 8.5 users: If you cannot see the Com Data
option, unzip the CR8-5 COM Driver.zip file that has been installed with
cViewIMAGE. This will normally be in the c:\Program Files\cViewIMAGE\Driver
folder.
Copy the P2smon.dll file from the CR8-5 COM Driver.zip file to the
c:\Windows\system32 folder.)
You will be prompted for a ProgId. Enter: cViewIMAGE.SingleImage. (Upper
or lower case is OK).
OK / Add.
You will be prompted to input a parameter value - simply enter any
character, in this case aa, then Close.
Click the Next button in the Report Expert and select both fields (ImagePath
and Image) to be displayed on the right hand side of the screen.
Click OK.
The Subreport will anchor in the Group header section when you move your
cursor to the Group Header and click your left mouse button.
3. Tidy up the Subreport:
Click on the subreport tab, in this case it is called SubReportOfImages.
Hide or suppress the Report header and the Report footer
You may only have one field in the subreport, (ImagePath) even though
you asked the Report Expert to insert both fields. If so, open the field
explorer and expand Databases. You will see the table ImageRecord.
Select the Image field from it and drag it into the Details section.
4. Calculate the full path for your images:
Create a formula to append the file path of where your images are stored
to the name of the image which is held in the database:
In your main report (not the subreport) create a formula, in this case
called BuildFilePath.
"c:\projects\cviewimage\demo v085\" + {StaffImagePath.PhotoFieldName}
In this example, the images are stored in the c drive in the projects\cviewimage\demo
v085 folder. Change this formula to reflect where you have stored the
demo v085 folder.
Use this formula to link to the subreport in the next step.
5. Link the main report to the subreport:
Rick click on the subreport / Change subreport links.
Double click on the formula @BuildFullPath created in the previous step
to move it to the right hand side under "Fields to link to".
Click the drop down list under "Subreport parameter field to use".
You will see "?PM-@BuildFilePath" - this is not the field you want. On
the right side of the field you will see very small scroll bars - click
on the down arrow and click on "?ImageFile" which is the correct field
to use. Click OK.
You can now see your images.
Later versions of Crystal can produce better image resolution.
6. Final report:
Format the report as you wish. In this case, remove subreport borders,
the ImagePath field in the subreport and move the subreport to the right
of the group name. Every 2nd line is given a different colour. Suppress
Details, Group Footer, Report Footer, Page Footer
This is part of the live processing - your users will need a cViewIMAGE
Viewer on their machine if they are accessing live data. They will not
need cViewIMAGE if you export in a different format such as pdf or
Excel.
|