做过itextsharp的请进(分不够,可以再加)

zlhcc 2003-09-10 03:48:34
小弟用了一下itextsharp,感觉就是挺简单。但是汉字显示不出来。
听说itextsharp支持汉字显示,请给出演示代码,如果成功的话。可以另外开贴在加
100分。
...全文
86 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jackyhzzjcn 2003-09-10
  • 打赏
  • 举报
回复
http://itextsharp.sourceforge.net/tutorial/ch09.html#truetype
jackyhzzjcn 2003-09-10
  • 打赏
  • 举报
回复
iTextSharp.text.Font myFont = new iTextSharp.text.Font();
BaseFont bfSONG = BaseFont.createFont(Server.MapPath("Font/SURSONG.TTF"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
jackyhzzjcn 2003-09-10
  • 打赏
  • 举报
回复
汉字可以自己LOAD汉字文件,就可以直接显示了 :)
panyee 2003-09-10
  • 打赏
  • 举报
回复
页面上虽然出不来汉字, 但
document.addTitle("pdf测试");
document.addAuthor("张立华");
document.addKeywords("world");
上面三行是正确的

默认字体好像是Helvetica
jackyhzzjcn 2003-09-10
  • 打赏
  • 举报
回复
:)
zlhcc 2003-09-10
  • 打赏
  • 举报
回复
using System;
using System.IO;

using iTextSharp.text;
using iTextSharp.text.pdf;

namespace Chap0101
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
// step 1: creation of a document-object

Document document = new Document(PageSize.A4.rotate());
//Document document = new Document(PageSize.B5.rotate());

try
{

// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file

PdfWriter writer = PdfWriter.getInstance(document, new FileStream("d:\\Chap0101.pdf", FileMode.Create));
writer.setEncryption(PdfWriter.STRENGTH128BITS, "111", "6452116",
/*PdfWriter.AllowCopy | */PdfWriter.AllowPrinting);

// we add some metadata and open the document
document.addTitle("pdf测试");
document.addAuthor("张立华");
document.addKeywords("world");

// we Add a Watermark that will show up on PAGE 1
try
{
Watermark watermark = new Watermark(Image.getInstance("watermark.jpg"),200, 300);
document.Add(watermark);
}
catch
{
Console.Error.WriteLine("Are you sure you have the file 'watermark.jpg' in the right path?");
}

// we Add a Header that will show up on PAGE 1
HeaderFooter header = new HeaderFooter(new Phrase("hehe小"), false);
document.Header = header;


// step 3: we open the document
document.Open();



// step 4: we Add a paragraph to the document
// step 4: we Add some paragraphs to the document
for (int i = 0; i < 5; i++)
{
document.Add(new Paragraph("Hello World呵呵"));
}

}
catch(DocumentException de)
{
Console.Error.WriteLine(de.Message);
}
catch(IOException ioe)
{
Console.Error.WriteLine(ioe.Message);
}

// step 5: we close the document
if (document.isOpen())
document.Close();

}
}
}

我的所有的 呵呵 汉字都没有了
zlhcc 2003-09-10
  • 打赏
  • 举报
回复
好,调通了
zlhcc 2003-09-10
  • 打赏
  • 举报
回复
谢谢 lese9(乐色.Net) , 我现在用的不是我自己的电脑。

我晚上会调一调,看样子,你的方法可行。如果你的代码可行,我会另开一贴,你要注意去
收分幺

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧