///<summary>

 

   ///字型

 

   ///</summary>

 

   public class tFont

 

   {

 

       const string fontName = @"標楷體";

 

       static string fontPath = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\..\Fonts\kaiu.ttf";

 

       static BaseFont _bfChinese = BaseFont.CreateFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); //橫式中文BaseFont.IDENTITY_H      

 

       public tFont()

 

       {

 

           FontFactory.Register(fontPath);

 

       }

 

       public Font font12 = new Font(_bfChinese, 12f);

 

       public Font font12U = new Font(_bfChinese, 12f, Font.UNDERLINE);

 

       public Font font12B = new Font(_bfChinese, 12f, Font.BOLD);

 

       public Font font14 = new Font(_bfChinese, 14);

 

       public Font font16 = new Font(_bfChinese, 16);

 

       public Font font24 = new Font(_bfChinese, 24);

 

   }

 

 

#region Chunk

   ///<summary>

   ///產生句子

   ///</summary>

   static Chunk setChunk(string tContent)

   {

       return new Chunk(tContent, (new tFont()).font12);

   }

 

   static Chunk setChunk(string tContent, Font tF)

   {

       return new Chunk(tContent, tF);

   }

   #endregion

 

   #region Phrase

   ///<summary>

   ///產生句子

   ///</summary>

   static Phrase setPhrase(string tContent)

   {

       return new Phrase(setChunk(tContent));

   }

   #endregion

 

   #region Paragraph

   ///<summary>

   ///產生段落

   ///</summary>

   static Paragraph setParagraph(string tContent)

   {

       return setParagraph(tContent, Element.ALIGN_LEFT);

   }

   static Paragraph setParagraph(string tContent, int tAlignment)

   {

       return new Paragraph( csCreatePDF.setChunk(tContent)) { Alignment = tAlignment };// Element.ALIGN_CENTER

   }

   static Paragraph setParagraph(string tContent, Font tF)

   {

       return new Paragraph( csCreatePDF.setChunk(tContent, tF));

   }

   static Paragraph setParagraph(string tContent, int tAlignment, Font tF)

   {

       return new Paragraph( csCreatePDF.setChunk(tContent, tF)) { Alignment = tAlignment };

   }

   static Paragraph setParagraph(Paragraph tPg, int tLeading)

   {

        tPg.SetLeading(0, tLeading);

       return tPg;

   }

 

   ///<summary>

   ///段落前面及左邊空間

   ///</summary>

   static Paragraph setParagraphSpacing(string tContent, int tBefore, int tLeft)

   {

       return setParagraphSpacing(tContent, tBefore, tLeft, 0);

   }

   ///<summary>

   ///段落前面、左邊空間、首行

   ///</summary>

   static Paragraph setParagraphSpacing(string tContent, int tBefore, int tLeft, int tFirst)

   {

       var tPg = setParagraph(tContent);

       tPg.SpacingBefore = tBefore;

       tPg.IndentationLeft = tLeft;

       tPg.FirstLineIndent = tFirst;

       return tPg;

   }

   ///<summary>

   ///段落前面空間

   ///</summary>

   static Paragraph setParagraphBefore(Paragraph tPg, int tLine)

   {      

       tPg.SpacingBefore = tLine;

       return tPg;

   }

   ///<summary>

   ///段落前面空間

   ///</summary>

   static Paragraph setParagraphBefore(string tContent, int tLine)

   {

       var tPg = setParagraph(tContent);

       tPg.SpacingBefore = tLine;

       return tPg;

   }

   ///<summary>

   ///段落後面空間

   ///</summary>

   static Paragraph setParagraphAfter(Paragraph tPg, int tLine)

   {

       tPg.SpacingAfter = tLine;

       return tPg;

   }

   ///<summary>

   ///段落左邊空間

   ///</summary>

   static Paragraph setParagraphLeft(Paragraph tPg, int tLine)

   {

       tPg.IndentationLeft = tLine;

       return tPg;

   }

   ///<summary>

   ///段落左邊空間

   ///</summary>

   static Paragraph setParagraphLeft(Paragraph tPg)

   {

       tPg.IndentationLeft = 25;

       return tPg;

   }

   ///<summary>

   ///段落右邊空間

   ///</summary>

   static Paragraph setParagraphRight(Paragraph tPg, int tLine)

   {

       tPg.IndentationRight = tLine;

       return tPg;

   }

   ///<summary>

   ///設定首行

   ///</summary>

   static Paragraph setParagraphFirstLine(string tContent, int tFirstLine)

   {

       return new Paragraph(csCreatePDF.setChunk(tContent)) { FirstLineIndent = tFirstLine };

   }

   static Paragraph setParagraphFirstLine(string tContent, int tFirstLine,Font tF)

   {

       return new Paragraph(csCreatePDF.setChunk(tContent, tF)) { FirstLineIndent = tFirstLine };

   }

   static Paragraph setParagraphFirstLine(Paragraph tPg, int tFirstLine)

   {

       tPg.FirstLineIndent = tFirstLine;

       return tPg;

   }

   static Paragraph setParagraphFirstLine(string tContent)

   {

       return new Paragraph(csCreatePDF.setChunk(tContent)) { FirstLineIndent = 24 };

   }

   ///<summary>

   ///加入空白行

   ///</summary>

   ///<param name="doc"></param>

   ///<param name="tLine"></param>

   static void setParagraphNull(iTextSharp.text.Document doc, int tLine)

   {

       for (int i = 0; i < tLine; i++)

       {

           doc.Add(setParagraph(" "));

       }

   }

   #endregion

 

, , , ,

倧齊 發表在 痞客邦 PIXNET 留言(0) 人氣()