cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Image shown issue

huayuz
Explorer
0 Likes
1,487

Hi,

I set a report with .xsd file as schema of table. and I insert an OLE object with graphic location to load an image.

Here comes the strange thing. Image does not show when I set the data source and export pdf file, every filed shows correctly but image. However, Image shows if I don't set data source and export pdf.

below is how I set the datasource:

 void SetXmlDataSource(ReportDocument report)
        {
            if(!Utils.CheckFileExists(_configuration.Schema))
            {
                throw new Exception($"File {_configuration.Schema} does not exist");
            }
            if(!Utils.CheckFileExists(_commandLine))
            {
                throw new Exception($"File {_commandLine} does not exist");
            }        
            var ds = new DataSet();
            ds.ReadXmlSchema(_configuration.Schema);
            ds.ReadXml(_commandLine);
            report.SetDataSource(ds);
        }<br>

Language: C# (.net4.5)

OS Platform: Windows Server 2016 (x64)

SDK: SP32

Crystal Reports Version: Crystal Report 2020

Accepted Solutions (1)

Accepted Solutions (1)

0 Likes

Wrong, as I said the image is ONLY loaded on Report.load. Refreshing the data DOES NOT reload the image.

To get this to work you must use a formula which points to a database field that redirects to the location of the image, either a hard drive location of another field, you can't load the image directly from a DB field.

huayuz
Explorer
0 Likes

Thanks for your kind reply Williams. I finally work it out with your help.

1. Load report with full file name.

2.using formula Left(Filename,length(filename) - Length(Mid (Filename ,InstrRev (Filename,"\") + 1) )) + "Logo.bmp" to load image.

Thank you.

Answers (4)

Answers (4)

0 Likes

If you export the report using the Viewers Export button does that work?

As I said, the image is only loaded once when the report is opened. Refreshing won't show a new image

huayuz
Explorer
0 Likes

Yes. the image shows if I using the Viewers Export button. Dear Williams, We always use graphic to show the local image in reports and it works well. It only being blank when I set xsd file schema and xml data file as datasource.

If I comment out SetDataSource line as below, the image shows in the exported pdf( but no data because no data source set).

I've set dataset as data source before, of which records are from sql server and everything woks well. the difference here is just read xml as data source I dont know why. Just as you said, the image loaded once when report is opened. it should be opened after data source loaded. And the hardcoded graphic image should be shown, right?

0 Likes

It has always been this way, if you insert an image into a report CR will only load the image when the Report is opened or loaded in an application.

The solution R&D came up with is to use a database field that points to the location of the image. It could be a field in the DB or a file located on the Harddrive.

huayuz
Explorer
0 Likes

Thanks for your kindly reply. Here I want to put some screen shots to make my problem more clear.

1. choose a .xsd file as database ADO.NET(XML)

<?xml version="1.0" standalone="yes"?>
<xs:schema id="data" 
xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="data" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="docid">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="RptDate" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
              <xs:element name="PolNo" type="xs:string" minOccurs="0" msdata:Ordinal="1" />
              <xs:element name="PolicyName" type="xs:string" minOccurs="0" msdata:Ordinal="2" />
              <xs:element name="NextAnni" type="xs:string" minOccurs="0" msdata:Ordinal="3" />
              <xs:element name="Address1" type="xs:string" minOccurs="0" msdata:Ordinal="4" />
              <xs:element name="Address2" type="xs:string" minOccurs="0" msdata:Ordinal="5" />
              <xs:element name="Address3" type="xs:string" minOccurs="0" msdata:Ordinal="6" />
              <xs:element name="Address4" type="xs:string" minOccurs="0" msdata:Ordinal="7" />
              <xs:element name="State" type="xs:string" minOccurs="0" msdata:Ordinal="8" />
              <xs:element name="CONTPERSON" type="xs:string" minOccurs="0" msdata:Ordinal="9" />
              <xs:element name="AgentName" type="xs:string" minOccurs="0" msdata:Ordinal="10" />
              <xs:element name="AGYNAME" type="xs:string" minOccurs="0" msdata:Ordinal="11" />
              <xs:element name="CommDisclsInd" type="xs:string" minOccurs="0" msdata:Ordinal="12" />
              <xs:element name="company_code" type="xs:integer" minOccurs="0" msdata:Ordinal="13" />
              <xs:element name="company_short_name_e" type="xs:string" minOccurs="0" msdata:Ordinal="14" />
              <xs:element name="company_short_name_c" type="xs:string" minOccurs="0" msdata:Ordinal="15" />
              <xs:element name="company_full_name_e" type="xs:string" minOccurs="0" msdata:Ordinal="16" />
              <xs:element name="company_full_name_c" type="xs:string" minOccurs="0" msdata:Ordinal="17" />
              <xs:element name="fax_number" type="xs:string" minOccurs="0" msdata:Ordinal="18" />
              <xs:element name="csc_phone" type="xs:string" minOccurs="0" msdata:Ordinal="19" />
              <xs:element name="print_date" type="xs:string" minOccurs="0" msdata:Ordinal="20" />
			  <xs:element name="logo" type="xs:string" minOccurs="0" msdata:Ordinal="21" />
            </xs:sequence>
            <xs:attribute name="letterdoc">
			  <xs:simpleType>
				<xs:restriction base="xs:string">
				  <xs:pattern value="GRNV005R01|GRNV005R02|GRNV005R03|GRNV005R04"/>
				</xs:restriction>
			  </xs:simpleType>
			</xs:attribute>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

3.I set a report as below

2.preview in designer. As you can see, hard code graphic location image shows correctly

3. call method SetXmlDataSource to load xsd file and xml file.

<data>
<docid letterdoc="GRNV005R01">
<RptDate>08/12/2022 10:24:50</RptDate>
<PolNo>0000012345</PolNo>
<PolicyName>Howard & Ping</PolicyName>
<NextAnni>09/30/2022 00:00:00</NextAnni>
<Address1>SUITE AA</Address1>
<Address2>CMA BUILDING</Address2>
<Address3>20 CONNAUGHT ROAD CENTRAL</Address3>
<Address4></Address4>
<State>HONG KONG</State>
<CONTPERSON>MS. ELIZABETH LAW</CONTPERSON>
<AgentName></AgentName>
<AGYNAME></AGYNAME>
<CommDisclsInd>N</CommDisclsInd>
<company_code>41</company_code>
<company_short_name_e>Apple</company_short_name_e>
<company_short_name_c>Apple</company_short_name_c>
<company_full_name_e>Apple</company_full_name_e>
<company_full_name_c>苹果</company_full_name_c>
<fax_number>1234 9011</fax_number>
<csc_phone>2234 9999</csc_phone>
<print_date>08/11/2022 00:00:00</print_date>
<logo>.\Header_Portrait_Logo.bmp</logo>
</docid>
</data>

4. call ExportToDisk method to export pdf ( you can see both image are blank and logo field has correct value)

5. exe application and report and image are all in debug folder.

Plase help me, thank you

0 Likes

You have to link the image through a database field, If not the image will only load once when the report is opened.

huayuz
Explorer
0 Likes

Than you Williams, I don't know why I have to link the image through a database field. But, the image shows if I set a dataset as data source in some reports. Is it a special way for xml\xsd data source type? In my case, the image path is hard-coded in the graphic location and no need to calculate at all.

DellSC
Active Contributor
0 Likes

You need to make sure that the image is in a location that the web application server software has acces to. For example, if the image is somewhere on the network and you're running your app in Tomcat, Tomcat would have to be running under the credentials of a service account that has access to the network folder where the image is located. The same holds true for IIS. Web application server software, by default, is usually locked down security-wise because of the higher risk of attacks through the web.

-Dell

huayuz
Explorer
0 Likes

Thanks for your reply. Yah, I am sure that the image is available for application. Because image shows if I comment out SetXmlDataSource codes. It might be a issue I think, could you guys take a look at it?

Thanks

DellSC
Active Contributor
0 Likes

I'm not an SAP employee, but don.williams might be able to take a look at it.

-Dell