Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

How to Export Crystal Report in Regional Languages - Marathi, Hindi, Arabic

5.00/5 (7 votes)
25 Mar 2014CPOL4 min read 53.3K   2.3K  
Resolving issue of Font Displaying Box or Junk while exporting Crystal report

Introduction

In this article, I am going to resolve the issue of Font Displaying Box or Junk while exporting Crystal report which is created in regional languages like Marathi, Hindi, Arabic. The biggest issue is because of the font.

This article will help developers who are developing Crystal report in their Regional Language because there aren't many articles on localizing Crystal report.

The font which we use while developing report should be there on server where you are going to deploy your application.

If font is not there, then it will create junk like characters.

Tip: You cannot use any font to develop report, you should use Unicode font for it.

The main step is to install font on the server or any place where you are going to deploy the application.

While exporting Crystal report in languages like English, we do not get an issue because by default, that font is installed on your PC (computer).

But while developing report in regional languages, we face issues:

  • Having fonts, but they are not Unicode - that will be an issue for displaying junk characters.
  • But we will see a report on your developing PC (Personal Computer) - it looks proper but when deployed on the server, it displays junk.

What is Unicode Font? Why to Use Them.

Unicode provides a unique number for every character:

  • no matter what the platform
  • no matter what the program
  • no matter what the language

This line is referenced from this site.

Here in this site, you will see all details about Unicode font.

Here, I am showing you steps to resolve this issue in a few steps:

  1. Create New Application
  2. Step FileNewProject
  3. In Installed Template, select WebASP.NET Web Application
  4. Add Name to it.

    Here is a snapshot with an explanation for creating a new application.

    Image 1

  5. After creating application, just add Webform and Name it.

    Image 2

  6. Add Crystal Report Viewer to Page to display report and also add Button to Export to Crystal report in PDF. Here, I am providing code for .aspx page.

    Tools used:

    • Button
    • Crystal Report Viewer
    HTML
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div style="text-align: center;">
    <asp:Button ID="Button1" runat="server" Width="150px" Height="50px" 
                Text="Export to Pdf" OnClick="Button1_Click" />
    </div>
    <div style="text-align: center;">
    <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
    </body>
    </html>
  7. Add CrystalReport
    • Selecting reporting tools from installed templates
    • After selecting, you can see Crystal report with Visual C#
    • Just select it and name it

    Image 3

    After this, just new window will popup for selection.

    • In popup, you will find three options to develop it.
    • That Select Blank report.

    Image 4

  8. To Crystal-report, I am just binding Stored procedure.
    • I have just created table with Name DOIUsertemp.
    • For storing character of Unicode, I have given datatype of it to Nvarchar.

    In Table, I have Marathi inserted Unicode values to display on Report.

    [One of Regional Languages in India]

    Data. Create Table.

    Image 5

    View of Table. [This is a snapshot of Record in Table DOIUsertemp in Marathi.]

    Image 6

    View of Stored procedure

    [Created Stored Procedure for get values from database and displaying on report.]

    Image 7

    [This is a snapshot of Crystal report with stored procedure Fields.]

    Image 8

  9. In this step, I am Dragging Fields on Report from Stored procedure.
  10. After Dragging Fields on report, I am going to show you how to select font.

    Steps

    1. Select the Drag Field on Crystal-report.
    2. Select Font from above Header which we want to use. (Regional Language Font and MustUnicode).
    3. For Marathi, I am going to select Mangal.
    4. You can select your own Font according to your need.

    [This is a snapshot while selecting in Marathi Font.]

     

    Image 9

    [This is a snapshot of Preview Crystal report in Marathi.]

    Image 10

  11. After that, just save report.
  12. Now, we just need to write code for binding report and exporting report.
  13. Binding Report on load.

    Here, I am providing code for binding Crystal Report on Load event.

    C#
    protected void Button1_Click(object sender, EventArgs e)
    {
    SqlCommand cmd = new SqlCommand("Usp_GetUser", con); // calling for Exporting Records 
                                           // cmd.CommandType = CommandType.StoredProcedure;
    SqlDataAdapter da = new SqlDataAdapter();
    da.SelectCommand = cmd;
    DataTable datatable = new DataTable();
    da.Fill(datatable); // getting value according to imageID and fill dataset
    // creating object of crystal report 
    ReportDocument crystalReport = new ReportDocument(); 
    crystalReport.Load(Server.MapPath("~/CrystalReport1.rpt")); 
    
    // path of report
    crystalReport.SetDataSource(datatable); 
    
    // binding datatable 
    CrystalReportViewer1.ReportSource = crystalReport;
    
    crystalReport.ExportToHttpResponse
    (CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, 
    true, "PersonDetails");

Here is the output for Marathi data after exporting report with no junk character.

 

Image 11

For Hindi Language

The same process is required for developing Crystal in Hindi. Also, just change the font to Hindi while creating Report.

On button click, use the same code used for Marathi to export report.

Done. For demo in table, I have inserted Hindi record.

View of Table. [This is a snapshot of Record in Table DOIUsertemp in Hindi.]

Image 12

Selecting Hindi Font .

[This is snapshot while selecting in Hindi font.]

Image 13

Final output for Hindi Data after exporting.

Image 14

For Arabic Language

Same process is required for developing Crystal in Arabic.

Also just change the Font to Arabic while Creating Report is Done.

Main point you can install any other font of Arabic and develop, but Font must be Unicode. For demo in table, I have inserted Arabic Record.

View of Table. [This is a snapshot of Record in Table DOIUsertemp in Arabic.]

Image 15

Selecting Arabic Font

[This is snapshot while selecting in Arabic Font.]

Image 16

Final output for Arabic data.

Image 17

Image 18

On button click, use the same code used for exporting Marathi Crystal Report.

Completed my solution.

Programmer for sharing knowledge and gaining knowledge.

Making people lives easy.

History

  • 25th March, 2014: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)