In VB6 with Crystal Reports 8, embedding an image dynamically into a Crystal Reports file was fairly simple. You could merely add a new object to the report on the fly, passing in the path of the image file then drop it into the appropriate section and x/y position on the report.
Dim oleobj As OLEObjectoRpt.Sections(8).AddPictureObject imgfileName, 1920, 1560
In VS.NET 2003 (I haven't looked at how to do this in 2005 yet), it is hardly as easy as this and I needed to do it to solve a serious file bloat problem. I had a 13kb image that I needed to embed as a watermark into the background of the file. You do this by creating a page header section that is the height of the paper and in the formatting options for the section, check "Underlay Following Sections". That way, the section will be a watermark under all of the rest of the sections of the report. However, because of the way Crystal does this underlay, my dlls that contain a report with a watermark were over 2MB when compiled. Without the image, they went back down to 200kb - 350kb depending on other variables.
Embedding the watermark image dynamically was going to help me get rid of this file bloat problem, but it was not as simple as the previous crystal API.
I had some help from tech support and modified the code to suit my needs and will share it here.
The trick is to stream the file into a datatable and then add the datatable as one of the datasource objects of the report. Then the field which represents the image, can be dragged and dropped onto the report surface.
What I did was create a class for extending Crystal call CrystalAddOns. In it I have a shared function that takes in the path of the image file and returns a datatable creating the binary for the image.
Here is the class.
Imports
'Dim ds As New DataSet 'ds.Tables.Add(data) 'ds.WriteXmlSchema(System.IO.Directory.GetCurrentDirectory() & "\Image.xsd")
Now that you have this class, you can use it easily when instantiating your reports:
rpt.Database.Tables(1).SetDataSource(CrystalAddOns.ImageTable(myfilePath)
This assumes that the schema file was the 2nd datasource in your report.
My class also has additional goo to handle specific watermarks, such as a "draft" watermark. This way my call would ask for CrystalAddOns.DraftImageTable() and the CrystalAddOns class already has the path of the file.
Note that the full blown version of Crystal Reports that can be upgraded to from the one that comes with VS2003 (and the next version that you can upgrade to from VS2005) have a Dynamic Image Location feature (which I have never tried) that supposedly makes this much simpler. My guess is that the Dynamic Image Location does the same thing as my class.Don't Forget: www.acehaid.org
See my speaking schedule for more events
User Group Leader
Hosted by:
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008, Julie Lerman
E-mail