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
|
|
|
}
|
}
|
}
|