cancel
Showing results for 
Search instead for 
Did you mean: 

Printing images on a CR report through code

Former Member
0 Kudos

Hi everyone,

I have a problem with printing images on my report. I have created a report with 3 images in the header. The path of the images I pass to the report through code in VB.net. I had a report viewer on my form and loaded my report in the report viewer. It showed my report perfectly, with the images. When I clicked the print button on the report viewer, it printed my report with the images.

Now I want to print the report directly through code and therefore I used the function PrintToPrinter. When the report is printed with this function, the images are not printed. I also tried to print the report from the report viewer through code, using the Print function from the report viewer, and also in this case the images are not printed.

I need to print my report through code in VB.net, because the report must be created in the background. The user of the application may not see the report and I need to have the images on my report, because they contain essential information for my report. Can someone help me fix this problem?

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

Hello Gert

What version of CR?

What version of .NET?

Web or Win app?

Is this happening when you run the app on your development computer in the .NET IDE?

- Ludek

Senior Support Engineer AGS Primary Support, Global Support Center Canada

Follow us on Twitter

Got Enhancement ideas? Try the SAP Idea Place

Share Your Knowledge in SCN Topic Spaces

Former Member
0 Kudos

Hello Ludek,

The version of CR is 13.0.3 and i'm using visual studio 2010. It's a windows application. The problem happens every time, when debugging or using the application installed on another computer. All the images are small jpegs between 1 and 10kb in size.

0 Kudos

Hi Gert,

I am trying to display/print an image on the report by using the file path in code.

I read from your first comment that you managed to do this. Could you share the code?

I am using VS2012 with the latest CR for VS.

Thanx,

Japie

Former Member
0 Kudos

Hi,

I passed the file path to a parameter in my CR Report. Then I added a image on my report. After that I clicked right on the image and selected "Format Object". On the second tab (Image) you find the text "Location of". Next to it is a button to create a formula. In the dialog screen of the formula, you put the parameter containing the file path in the formula field. When you run the report with the report viewer, it will display the image.

The only code I used was to pass the path to the parameter. In case you don't know the code, I'll give it here:

Sub EditCrParameter (ByVal report As ReportDocument, _

ByVal parametername As String, ByVal value As Object)

Dim crParameterDiscreteValue As ParameterDiscreteValue

Dim crParameterFieldDefinitions As ParameterFieldDefinitions

Dim crParameterFieldLocation As ParameterFieldDefinition

Dim crParameterValues As ParameterValues

crParameterFieldDefinitions = report.DataDefinition.ParameterFields


crParameterFieldLocation = crParameterFieldDefinitions.Item(parametername)

crParameterValues = crParameterFieldLocation.CurrentValues

crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue

crParameterDiscreteValue.Value = value

crParameterValues.Add(crParameterDiscreteValue)

crParameterFieldLocation.ApplyCurrentValues(crParameterValues)

End Sub

0 Kudos

Hi thank you very much,

I managed to get the image to print by using the "Location of" as you suggested on the report by pointing it to a field in the database.

I am printing to PDF format by code. The image displays in the PDF document correct.

I added a line to print directly to the printer, and that also printed correct. See below the code which I call for each line in a datview grid (gS). I send the row number (lRow) and the PDF file name (lFN) to this function:

private string CreatePDF(int lRow, string lFN)

{

   try

      {

       ReportDocument cryRpt = new ReportDocument();

              if (gS[5,lRow].Value.ToString()=="A")

                   cryRpt.Load(MainForm.jMainDir + "This report.rpt");

               else

                    cryRpt.Load(MainForm.jMainDir + "The other report.rpt");

              cryRpt.DataSourceConnections[0].SetConnection("", MainForm.jMainDB, false);

              MySQL = "Some SQL statement for CR";

              cryRpt.RecordSelectionFormula = MySQL;

              cryRpt.ExportToDisk(ExportFormatType.PortableDocFormat, lFN);

              cryRpt.PrintToPrinter(1, true, 1, 1);

              return "Yes";

      }

   catch (Exception EX)

      {

       return EX.Message;

      }

}

former_member183750
Active Contributor
0 Kudos

OK. Let's make sure you have SP5:

http://scn.sap.com/docs/DOC-7824

A question relating to:

I also tried to print the report from the report viewer through code, using the Print function from the report viewer, and also in this case the images are not printed.

Do the images show up in the viewer?

It would also be interesting to see if an export works. From the viewer and code:

Private Sub ExportToDisk(ByVal fileName As String)

               Dim exportOpts As New ExportOptions()

               Dim diskOpts As DiskFileDestinationOptions

               diskOpts = ExportOptions.CreateDiskFileDestinationOptions()

               exportOpts.ExportFormatType = _

                  ExportFormatType.PDF

               exportOpts.ExportDestinationType = _

                  ExportDestinationType.DiskFile

               diskOpts.DiskFileName = fileName

               exportOpts.ExportDestinationOptions = diskOpts

               Report.Export(exportOpts)

            End Sub

- Ludek

Former Member
0 Kudos

Hi,

I've tried to use the report viewer again, but this time the images didn't show up in the viewer. I edited my report a lot today. One time I typed the correct path hard-coded in the formula editor (Like this: "C:\MyApplication\Images\Imagename.jpg") and when i did that, the image showed up on the report viewer and I was able to print the report with the images.

But that doesn't solve my problem. The images depend on variables in my code and with those variables I create the file path. So I think that the problem is that the "Location of" formula has difficulties reading the path I sent in my parameter. Do you have any idea to solve this?

former_member183750
Active Contributor
0 Kudos

I think we're kinda flying at different elevations here - e.g.; I'm thinking of a solution based on KBA - 1320507 - How to change images dynamically in Crystal Reports based on parameter selection?

I am not sure if when you mention formula you mean a formula at  Format Graphic?

Another way of adding an image is by using the RAS SPIs. See KBA - 1296803 - How to add an image to a report using the Crystal Reports .NET inproc RAS SDK for more details.

- Ludek

Former Member
0 Kudos

Hi,

I managed to solve my problem. I passed all necessary variables from the code to parameters in my report. So behind every image object I edited the formula for "Location of" to a "Select Case" structure. In every "Case" I placed the hard coded path of the image which is needed.

The only disadvantage for my solution is that I needed to have the images on my local drive (C:\). I first tested the application in test mode, with the images on my local drive, and the images showed up. But when I edited the application to the user mode, the images didn't show up. In user mode I use the images from the folder on the network drive (in my case K:\). Do you know a solution for this problem?

Anyway, my initial problem is solved and my application is in use and works perfectly.

Answers (1)

Answers (1)

former_member183750
Active Contributor
0 Kudos

Might be permissions? Process Monitor may be able to tell you if that is the case.

- Ludek

Former Member
0 Kudos

Hi,

I used process monitor and when I used the network file in my report it said that there was a "Sharing Violation". So I shared my folder for everyone, but that didn't helped me. Do you know how to solve a "Sharing violation"?

former_member183750
Active Contributor
0 Kudos

Nope - not sure at all. That looks to be a an environment issue of some sort(?). Maybe your IT guys can help(?).

- Ludek