123
tangxu
2023-04-12 f980bc78ed10c45323a9c5edcf2441124de72241
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.draw;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.Application.Report.Helper
{
    /// <summary>
    /// 页眉页脚帮助类
    /// </summary>
    public class CreatHeaderAndFoot : PdfPageEventHelper, IPdfPageEvent
    {
        private static BaseFont BsFont = BaseFont.CreateFont(@"C:\Windows\Fonts\simsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);//PDF中文使用,0代表宋体
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="document"></param>
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);
 
            #region 一
 
            //string path = "../../Images/LOGO.jpg";//图片路径
            //Image img = Image.GetInstance(path);
            ////页眉
            //img.SetAbsolutePosition(80, 780); //图片位置
            //BaseColor bs = new BaseColor(237, 125, 49);
            //LineSeparator line = new LineSeparator(2f, -300, bs, Element.ALIGN_RIGHT, 30f);//下划线
            //PdfContentByte cbh = writer.DirectContent;
            //cbh.AddImage(img);
            //Phrase header = new Phrase(new Chunk(line));
            //ColumnText.ShowTextAligned(cbh, Element.ALIGN_RIGHT, header,
            //    document.Right, document.Top, 0);
 
            //页脚
            Font fontfooter = new Font(BsFont, 10);
            PdfContentByte cbs = writer.DirectContent;
            cbs.SetCharacterSpacing(1.3f); //设置文字显示时的字间距
            Phrase footer = new Phrase("生成日期:"+DateTime.Now.ToShortDateString(), fontfooter);
            ColumnText.ShowTextAligned(cbs, Element.ALIGN_CENTER, footer,
                document.Right / 2, document.Bottom, 0);
 
 
            #endregion
 
 
        }
    }
}