ITEXT学习手册——设置使用底层方法创建PDF

Stream stream = System.IO.File.OpenWrite(@"d:\helloworld.pdf");//创建一个PDF文件
            Document doc = new Document();
            var writer = PdfWriter.GetInstance(doc, stream);
            doc.Open();
            PdfContentByte canvas = writer.DirectContent;//获得PDF文本流,用于在上面画图
            writer.CompressionLevel = 0;
            canvas.SaveState();
            canvas.BeginText();
            canvas.MoveText(36, 788);//从这个位置开始画
            canvas.SetFontAndSize(BaseFont.CreateFont(), 12);//设置字体
            canvas.ShowText("Hello Wrold");//输出内容
            canvas.EndText();
            canvas.RestoreState();
            doc.Close();

image

posted @ 2014-01-15 09:15  争世不悔  阅读(710)  评论(0编辑  收藏  举报