一步一步 IText.Sharp

注:此文章大部分内容来源于:iText.in.Action.2nd,如果对这个组件有详细的了解,可以直接查阅此书。

Hello  Word

中文支持

Chunk Phrase Paragraph List使用

Anchor Image Chapter Section使用

一步一步ITextSharp 低级操作函数使用

一步一步 ITextSharp Table使用

.Text sharp PdfPTable PdfPCell对齐方式,边框,边框颜色的使用

 

更新日期:2011-5-16

示例基类代码:

   1: public abstract class TestBase : IDisposable
   2:    {
   3:        static TestBase()
   4:        {
   5:            RegisterFont();
   6:  
   7:            BoldUnderlined = FontFactory.GetFont("华文宋体", BaseFont.IDENTITY_H, 12, Font.BOLD | Font.UNDERLINE);
   8:            Normal = FontFactory.GetFont("华文宋体", BaseFont.IDENTITY_H, 12);
   9:            Bolditalic = FontFactory.GetFont("华文宋体", BaseFont.IDENTITY_H, 12, Font.BOLD | Font.ITALIC);
  10:        }
  11:        protected static readonly string BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
  12:        static void RegisterFont()
  13:        {
  14:            BaseFont.AddToResourceSearch("iTextAsian.dll");
  15:            BaseFont.AddToResourceSearch("iTextAsianCmaps.dll");
  16:            FontFactory.Register(Environment.GetFolderPath(Environment.SpecialFolder.System) +
  17:                                 @"\..\Fonts\STSONG.ttf");
  18:            FontFactory.Register(Environment.GetFolderPath(Environment.SpecialFolder.System) +
  19:                                 @"\..\Fonts\simhei.ttf");
  20:            FontFactory.Register(Environment.GetFolderPath(Environment.SpecialFolder.System) +
  21:                                 @"\..\Fonts\simsun.ttc");
  22:        }
  23:  
  24:        protected TestBase(string fileName)
  25:            : this(new FileStream(fileName, FileMode.OpenOrCreate))
  26:        {
  27:        }
  28:  
  29:        protected TestBase()
  30:            : this(string.Format("{0}helloworld.pdf",
  31:                BaseDirectory))
  32:        {
  33:        }
  34:  
  35:        Document document { get; set; }
  36:        PdfWriter writer { get; set; }
  37:        protected TestBase(Stream stream)
  38:        {
  39:            document = new Document();
  40:            writer = PdfWriter.GetInstance(document, stream);
  41:        }
  42:  
  43:        public void Open()
  44:        {
  45:            document.Open();
  46:        }
  47:  
  48:        public static readonly Font BoldUnderlined = FontFactory.GetFont("华文宋体", BaseFont.IDENTITY_H, 12, Font.BOLD | Font.UNDERLINE);
  49:        public static readonly Font Normal = FontFactory.GetFont("华文宋体", BaseFont.IDENTITY_H, 12);
  50:        public static readonly Font Bolditalic = FontFactory.GetFont("华文宋体", BaseFont.IDENTITY_H, 12, Font.BOLD | Font.ITALIC);
  51:  
  52:        public void WriteDocument()
  53:        {
  54:            WriteDocument(document, writer);
  55:        }
  56:        protected abstract void WriteDocument(Document document, PdfWriter writer);
  57:  
  58:        public void Dispose()
  59:        {
  60:            if (document != null)
  61:            {
  62:                document.Close();
  63:            }
  64:        }
  65:    }

你可能感兴趣的:(itext)