Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir,

i have a table with 2 cells .I want to display the chinees character in the table.

please help me.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(Request.PhysicalApplicationPath + "test.pdf", FileMode.Create));
doc.Open();

PdfPTable table = new PdfPTable(2);
PdfPCell cell = null;
cell = new PdfPCell(new Phrase("全澳甲流确诊病例已破"));
cell.BackgroundColor = new Color(192, 192, 192);
table.AddCell(cell);
PdfPCell cell1 = null;
cell1 = new PdfPCell(new Phrase("全澳甲流确诊病例已破"));
cell1.BackgroundColor = new Color(192, 192, 192);
table.AddCell(cell1);
doc.Add(table);
doc.Close();
Response.Redirect("~/test.pdf");

}
}
Posted
Comments
connect2manas 23-Jul-13 0:33am    
it is working perfectly for English characters.but not for chinese,japanese...

Chinese characters are Unicode not in ASCII. Thus it won't work with iTextSharp Library.
Try PDFsharp.NET

PDFsharp is the Open Source .NET library that easily creates and processes PDF documents on the fly from any .NET language. The same drawing routines can be used to create PDF documents, draw on the screen, or send output to any printer.

PDFsharp is a .NET library for processing PDF file. You create PDF pages using drawing routines known from GDI+. Almost anything that can be done with GDI+ will also work with PDFsharp. Only basic text layout is supported by PDFsharp, and page breaks are not created automatically. The same drawing routines can be used for screen, PDF, or meta files.
 
Share this answer
 
Comments
Sushil Mate 23-Jul-13 7:27am    
I guess it will work with iTextSharp, Check my solution.
Hi All,
This is the answer for displaying chineese.... character.
C#
Document Doc = new Document(PageSize.LETTER);
using ( FileStream fs = new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf"), FileMode.Create, FileAccess.Write, FileShare.Read))
    {

    PdfWriter writer = PdfWriter.GetInstance(Doc, fs);
    Doc.Open();
    Doc.NewPage();
    string ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "simhei.ttf");
    BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
    Font f = new Font(bf, 12, Font.NORMAL);
    Doc.Add(new Phrase("黄金通货膨胀  ", f));
    Doc.Add(new Phrase(" 电电电电电雲 ", f));
    Doc.Close();
}
 
Share this answer
 
v2
Comments
Naz_Firdouse 23-Jul-13 8:54am    
mark as answer
Naz_Firdouse 23-Jul-13 8:56am    
added pre tags for the code
Try this link, Hope this helps.

http://stackoverflow.com/a/6111416[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900