nothing like a little Vermont snow to welcome him with…
Don’t Forget: www.acehaid.org
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 OLEObject
oRpt.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
CrystalDecisions.CrystalReports.Engine ‘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
I think my head has been under the rock as far as vs2005 WinForms UI design stuff is concerened. I was fiddling wtih Winforms the other day and wanted to put a line on the form and realized I still can’t do it the old VB6 way. I just dropped a panel on instead and put the “below the line” stuff inside the panel. I want the line there at design time, so the GDI+ way wasn’t my cup of tea.
Don’t Forget: www.acehaid.org
Northwestern Vermonters, I received this today:
This is an excellent opportunity offering a base salary commensurate with experience and a comprehensive benefits package. First round interviews will take place in our office on Wednesday, November 30 starting at 10:00 AM.
If you are both interested and qualified in the above-mentioned opportunity, please contact either David A. Coryer or Melissa Moore at ETS, Inc; 518-562-4673 or toll-free 877-303-7737 We can also be reached via email at dcoryer@etsjobs.com or mmoore@etsjobs.com. We look forward to hearing from you!
ETS, Inc., upstate New York’s premier supplier of temporary and direct-hire recruiting for the past twenty-four years, specializes in the placement of high quality individuals in upstate New York, New England and along the Eastern Seaboard.
Don’t Forget: www.acehaid.org