使用c#中的itextSharp在PDf中显示像Chineese,Japaneese等国际字符 [英] Display internation character like Chineese,Japaneese etc in PDf using itextSharp in c#

查看:109
本文介绍了使用c#中的itextSharp在PDf中显示像Chineese,Japaneese等国际字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,



i有一个包含2个单元格的表格。我想在表格中显示中文字符。



请帮帮我。



使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.Web;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用iTextSharp.text.pdf;

使用iTextSharp.text;

使用System.IO;

public partial class _Default:System.Web。 UI.Page

{

protected void Page_Load(object sender,EventArgs e)

{



文档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 );

标签le.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);



}

}

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");

}
}

推荐答案

中文字符是Unicode而不是ASCII。因此它不适用于iTextSharp库。

试试PDFsharp.NET



PDFsharp是一个可轻松创建的开源.NET库从任何.NET语言即时处理PDF文档。相同的绘图程序可用于创建PDF文档,在屏幕上绘图或将输出发送到任何打印机。



PDFsharp是用于处理PDF文件的.NET库。您可以使用GDI +中已知的绘图例程创建PDF页面。几乎任何可以用GDI +完成的事情都可以与PDFsharp一起使用。 PDFsharp仅支持基本文本布局,并且不会自动创建分页符。相同的绘图程序可用于屏幕,PDF或元文件。
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.


大家好,

这是显示chineese的答案.... 。

Hi All,
This is the answer for displaying chineese.... character.
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();
}


试试这个链接,希望这会有所帮助。



http://stackoverflow.com/a/6111416 [ ^ ]
Try this link, Hope this helps.

http://stackoverflow.com/a/6111416[^]


这篇关于使用c#中的itextSharp在PDf中显示像Chineese,Japaneese等国际字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆