IText学习手册——调整字体位置

通过设置paragraph的Alignment来设置字体的位置

通过设置paragraph的”SpaceingAfter”、”SpaceingBefore”来设置段落间的距离

通过设置paragraph的”IndentationLeft”、”IndentationRight”、”FirstLineIndent”来设置显示时需要离paragraph左右的距离

/// <summary>
        /// 设置字体位置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button16_Click(object sender, EventArgs e)
        {
            Document doc = new Document(PageSize.A5);
            PdfWriter.GetInstance(doc, File.Open(path, FileMode.Create));
            doc.Open();
            Paragraph paragraph1 = new Paragraph("This is first paragraph");
            //居中显示
            paragraph1.Alignment = Element.ALIGN_CENTER;
            Paragraph paragraph2 = new Paragraph("This is second paragraph");
            paragraph2.Alignment = Element.ALIGN_RIGHT;
            //段落2与段落2的间距加大50个单位
            paragraph2.SpacingAfter = 50;
            //段落2与段落1的间距加大100个单位
            paragraph2.SpacingBefore = 100;
            Paragraph paragraph3 = new Paragraph("This is third paragraph,It's too long and show in new line");
            //段落3距离左边100个单位显示
            paragraph3.IndentationLeft = 100;
            //段落3的第一行距离左边50个单位显示
            paragraph3.FirstLineIndent = 50;
            doc.Add(paragraph1);
            doc.Add(paragraph2);
            doc.Add(paragraph3);
            doc.Close();

        }

显示效果:

image

posted @ 2014-02-26 20:30  争世不悔  阅读(5391)  评论(0编辑  收藏  举报