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:
- Create New Application
- Step File → New → Project
- In Installed Template, select Web → ASP.NET Web Application
- Add Name to it.
Here is a snapshot with an explanation for creating a new application.
- After creating application, just add Webform and Name it.
- 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 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>
- Add CrystalReport
- Selecting reporting tools from installed templates
- After selecting, you can see Crystal report with Visual C#
- Just select it and name it
After this, just new window will popup for selection.
- In popup, you will find three options to develop it.
- That Select Blank report.
- 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.
View of Table. [This is a snapshot of Record in Table DOIUsertemp
in Marathi.]
View of Stored procedure
[Created Stored Procedure for get values from database and displaying on report.]
[This is a snapshot of Crystal report with stored procedure Fields.]
- In this step, I am Dragging Fields on Report from Stored procedure.
- After Dragging Fields on report, I am going to show you how to select font.
Steps
- Select the Drag Field on Crystal-report.
- Select Font from above Header which we want to use. (Regional Language Font and MustUnicode).
- For Marathi, I am going to select Mangal.
- You can select your own Font according to your need.
[This is a snapshot while selecting in Marathi Font.]
[This is a snapshot of Preview Crystal report in Marathi.]
- After that, just save report.
- Now, we just need to write code for binding report and exporting report.
- Binding Report on load.
Here, I am providing code for binding Crystal Report on Load event.
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("Usp_GetUser", con);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataTable datatable = new DataTable();
da.Fill(datatable);
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("~/CrystalReport1.rpt"));
crystalReport.SetDataSource(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.
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.]
Selecting Hindi Font .
[This is snapshot while selecting in Hindi font.]
Final output for Hindi Data after exporting.
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.]
Selecting Arabic Font
[This is snapshot while selecting in Arabic Font.]
Final output for Arabic data.
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