Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get different images on different pages in Crystal Reports VS2010

Using WPF CrystalReportsViewer and the CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument I'm able to dynamically add an image to ALL pages in the rpt by calling ImportPicture on the appropriate section. However, I want to add a different image to each page.

I've figured out how many pages need images (see How do I get the number of rendered pages from a CrystalReportsViewer?), but have not been able to get a different image on each page.

Is there a data model of the "as rendered" report that I can access? Can I add a different image per page?

like image 609
tillerstarr Avatar asked Nov 03 '22 08:11

tillerstarr


2 Answers

I'm not sure about doing this programmatically in VS, but you can do this in the Crystal Report itself.

  1. Put a placeholder image in the desired section, location.
  2. Right click the image -> go to "Format Graphic" -> select the "Picture" tab
  3. You should see a button that will allow you to enter a formula for the "Graphic Location"
  4. Use a formula to resolve to a valid image file path via the "pagenumber" keyword:
select pagenumber
case 1 : "C:\picture1.bmp"
case 2 : "C:\picture2.bmp"
...
default : "C:\warning.bmp"
like image 75
Ryan Avatar answered Nov 08 '22 05:11

Ryan


Add all the images to the desired section, then EnableSuppress and set the formula to hide when its not on the desired page.

CrystalDecisions.ReportAppServer.ReportDefModel.PictureObject pic=ctl.ReportObjectController.ImportPicture(tempImagePath, s, 0, 0);
                        if (pic != null)
                        {
                            var picNew = pic.Clone();
                            picNew.Format.EnableSuppress = true;
                            CrystalDecisions.ReportAppServer.ReportDefModel.ConditionFormula f = roNew.Format.ConditionFormulas[CrObjectFormatConditionFormulaTypeEnum.crObjectFormatConditionFormulaTypeEnableSuppress];
                            if (f != null)
                            {
                                f.Syntax = CrFormulaSyntaxEnum.crFormulaSyntaxCrystal;
                                f.Text = string.Format("PageNumber <> {0}", ri.PageNumber);

                            }
                            ctl.ReportObjectController.Modify(pic, picNew);
                        }
like image 27
tillerstarr Avatar answered Nov 08 '22 06:11

tillerstarr