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 Water that will show up on PAGE 1
try 
{
Water water = new Water(Image.getInstance("water.jpg"),200, 300);
document.Add(water);
}
catch 
{
Console.Error.WriteLine("Are you sure you have the file 'water.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(); }
}
}我的所有的 呵呵 汉字都没有了

解决方案 »

  1.   

    页面上虽然出不来汉字, 但
    document.addTitle("pdf测试");
    document.addAuthor("张立华");
    document.addKeywords("world");
    上面三行是正确的默认字体好像是Helvetica
      

  2.   

    汉字可以自己LOAD汉字文件,就可以直接显示了 :)
      

  3.   

    iTextSharp.text.Font myFont = new iTextSharp.text.Font();
    BaseFont bfSONG = BaseFont.createFont(Server.MapPath("Font/SURSONG.TTF"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
      

  4.   

    http://itextsharp.sourceforge.net/tutorial/ch09.html#truetype
      

  5.   

    谢谢 lese9(乐色.Net) , 我现在用的不是我自己的电脑。我晚上会调一调,看样子,你的方法可行。如果你的代码可行,我会另开一贴,你要注意去
    收分幺